Code for paper "A Bit More Bayesian: Domain-Invariant Learning with Uncertainty" submitted to ICML 2021.
- Python 3.6.9
- Pytorch 1.1.0
../kfold/
: Directory of images../files/
: Directory of the train/validation/test split txt filespacs_main.py
: script to run classification experiments on PACSpacs_model.py
: the model used inpacs_main.py
pacs_datas.py
: script to load data from PACS for the experimentspacs_test.py
: script to evaluate the trained model./logs/
: folder to store the trained modelaugs.py
: data augmentation functions for the experimentsutils.py
: assorted functions to support the repository
The code is for the PACS dataset. Download the datasets from the following link (or the link in the main paper), extract the compressed file, and place the images in ../kfold/
directory and the train/validation/test split txt files in the ../files/
directory.
For training the model run the following:
python pacs_main.py --test_domain cartoon --log_dir model_name
Change the cartoon
after --test_domain
to art_painting
, photo
or sketch
to change the target domain.
Use --classifier SGP/NO
to choose Bayesian invariant classifier or deterministic classifier. The default value is --classifier SGP
.
Use --feature bayes/no
to choose Bayesian invariant feature extractor or deterministic one. The default value is --feature bayes
.
Use --classifier NO --feature no
to train the baseline method.
The trained model and logs will be stored in ./logs/model_name/
For evaluation of the trained model run the following:
python pacs_test.py --test_domain cartoon --log_dir cartoon_model
Change the target domain as the training phase.
Change the cartoon_model
to other names to evaluate other trained models