Entropy is not Enough for Test-Time Adaptation: From the Perspective of Disentangled Factors

May 21, 2024 ยท View on GitHub

PWC MIT License

This is the official implementation of Entropy is not Enough for Test-Time Adaptation: From the Perspective of Disentangled Factors ๐Ÿ”— by Jonghyun Lee, Dahuin Jung, Saehyung Lee, Junsung Park, Juhyeon Shin, Uiwon Hwang and Sungroh Yoon (ICLR 2024 Spotlight, Top-5% of the submissions).
This implementation is based on SAR implementation ๐Ÿ”—.

Environments

You should modify [username] and [env_name] in environment.yaml, then

$ conda env create --file environment.yaml

Baselines

TENT ๐Ÿ”— (ICLR 2021)
EATA ๐Ÿ”— (ICML 2022)
SAR ๐Ÿ”— (ICLR 2023)

Dataset

You can download ImageNet-C from a link ImageNet-C ๐Ÿ”—.

After downloading the dataset, move to the root directory ([data_root]) of datasets.

If you run on ColoredMNIST ๐Ÿ”— or Waterbirds ๐Ÿ”—, run

$ python pretrain_[dataset_name].py --root_dir [data_root] --dset [dataset_name]

Then datasets are automatically downloaded in your [data_root] directory.
(ColoredMNIST from torchvision ๐Ÿ”— and ./dataset/ColoredMNIST_dataset.py, Waterbirds from wilds ๐Ÿ”— package)

Your [data_root] will be as follows:

data_root
โ”œโ”€โ”€ ImageNet-C
โ”‚   โ”œโ”€โ”€ brightness
โ”‚   โ”œโ”€โ”€ contrast
โ”‚   โ””โ”€โ”€ ...
โ”œโ”€โ”€ ColoredMNIST
โ”‚   โ”œโ”€โ”€ ColoredMNIST_model.pickle
โ”‚   โ”œโ”€โ”€ MNIST
โ”‚   โ”œโ”€โ”€ train1.pt
โ”‚   โ”œโ”€โ”€ train2.pt
โ”‚   โ””โ”€โ”€ test.pt
โ”œโ”€โ”€ Waterbirds
โ”‚   โ”œโ”€โ”€ metadata.csv
โ”‚   โ”œโ”€โ”€ waterbirds_dataset.h5py
โ”‚   โ”œโ”€โ”€ waterbirds_pretrained_model.pickle
โ”‚   โ”œโ”€โ”€ 001. Black_footed_Albatross
โ”‚   โ”œโ”€โ”€ 002. Laysan_Albatross
โ””โ”€โ”€ โ””โ”€โ”€ ...

If you don't want to pre-train, you can just copy and paste the [dataset_name]_model.pickle from './pretrained/' directory.

Experiment

You can run most of the experiments in our paper by

chmod+xexpdeyo.shchmod +x exp_deyo.sh ./exp_deyo.sh

If you want to run on the ImageNet-R or VISDA-2021, you should use main_da.py

You should modify ROOT variable as [data_root] in exp_deyo.sh.

Citation

If our DeYO method or biased test-time adaptation settings are helpful in your research, please consider citing our paper:

@inproceedings{
    lee2024entropy,
    title={Entropy is not Enough for Test-Time Adaptation: From the Perspective of Disentangled Factors},
    author={Jonghyun Lee and Dahuin Jung and Saehyung Lee and Junsung Park and Juhyeon Shin and Uiwon Hwang and Sungroh Yoon},
    booktitle={The Twelfth International Conference on Learning Representations},
    year={2024},
    url={https://openreview.net/forum?id=9w3iw8wDuE}
}

Acknowledgment

The code is inspired by the Tent ๐Ÿ”—, EATA ๐Ÿ”—, and SAR ๐Ÿ”—.