π» Official implementation for "Bayesian Metric Learning for Uncertainty Quantifiation in Image Retrieval" by Frederik Warburg*, Marco Miani*, Silas Brack and SΓΈren Hauberg.
π₯ tl;dr: We use the Laplace Approximation for the Contrastive Loss to optimize a latent space with Metric Learning.
π° paper: https://arxiv.org/abs/2302.01332
π° Abstract: We propose the first Bayesian encoder for metric learning. Rather than relying on neural amortization as done in prior works, we learn a distribution over the network weights with the Laplace Approximation. We actualize this by first proving that the contrastive loss is a valid log-posterior. We then propose three methods that ensure a positive definite Hessian. Lastly, we present a novel decomposition of the Generalized Gauss-Newton approximation. Empirically, we show that our Laplacian Metric Learner (LAM) estimates well-calibrated uncertainties, reliably detects out-of- distribution examples, and yields state-of-the-art predictive performance.
git clone https://github.com/FrederikWarburg/bayesian-metric-learning;
cd bayesian-metric-learning;
git clone https://github.com/IlMioFrizzantinoAmabile/stochman;
cd stochman;
python setup.py develop;
cd ../src;
Your file structure should look like:
bayesian-metric-learning
βββ configs # config files, organised by experiments
βββ img # figures
βββ scripts # scripts for running code
βββ src # source code
β βββ datasets # Code for data
β βββ evaluate # Code for evaluation
β βββ lightning # pytorch lightning models (+ baseliens)
| βββ losses # specialize loss functions
| βββ miners # miners
| βββ models # network architectures
β βββ utils # helpers
βββ requirements.txt # file containing python packages that are required to run code
βββ stochman
cd src;
CUDA_VISIBLE_DEVICES=0 python run.py --config ../configs/fashionmnist/laplace_online_arccos_fix.yaml;
or a baseline model (e.g. the deterministic model)
cd src;
CUDA_VISIBLE_DEVICES=0 python run.py --config ../configs/fashionmnist/deterministic.yaml;
Remember to change the data_dir in the .yaml config file.
If you find this code useful, please consider citing us:
@article{Warburg2023LAM,
title={Bayesian Metric Learning for Uncertainty Quantification in Image Retrieval},
author={Frederik Warburg and Marco Miani and Silas Brack and SΓΈren Hauberg},
journal={CoRR},
year={2023}
}
@article{LAE2022,
title={Laplacian Autoencoders for Learning Stochastic Representations},
author={Marco Miani and Frederik Warburg and Pablo Moreno-MuΓ±oz and Nicki Skafte Detlefsen and SΓΈren Hauberg},
journal=Neurips,
year={2022}
}
@article{software:stochman,
title={StochMan},
author={Nicki S. Detlefsen and Alison Pouplin and Cilie W. Feldager and Cong Geng and Dimitris Kalatzis and Helene Hauschultz and Miguel GonzΓ‘lez Duque and Frederik Warburg and Marco Miani and SΓΈren Hauberg},
journal={GitHub. Note: https://github.com/MachineLearningLifeScience/stochman/},
year={2021}
}