ICLR21 Tent: Fully Test-Time Adaptation by Entropy Minimization

Related tags

Deep Learning tent
Overview

⛺️ Tent: Fully Test-Time Adaptation by Entropy Minimization

This is the official project repository for Tent: Fully-Test Time Adaptation by Entropy Minimization by Dequan Wang*, Evan Shelhamer*, Shaoteng Liu, Bruno Olshausen, and Trevor Darrell (ICLR 2021, spotlight).

⛺️ Tent equips a model to adapt itself to new and different data during testing ☀️ 🌧 ❄️ . Tented models adapt online and batch-by-batch to reduce error on dataset shifts like corruptions, simulation-to-real discrepancies, and other differences between training and testing data. This kind of adaptation is effective and efficient: tent makes just one update per batch to not interrupt inference.

We provide example code in PyTorch to illustrate the tent method and fully test-time adaptation setting.

Please check back soon for reference code to exactly reproduce the ImageNet-C results in the paper.

Installation:

pip install -r requirements.txt

tent depends on

and the example depends on

  • RobustBench v0.1 for the dataset and pre-trained model
  • yacs for experiment configuration

but feel free to try your own data and model too!

Usage:

import tent

model = TODO_model()

model = tent.configure_model(model)
params, param_names = tent.collect_params(model)
optimizer = TODO_optimizer(params, lr=1e-3)
tented_model = tent.Tent(model, optimizer)

outputs = tented_model(inputs)  # now it infers and adapts!

Example: Adapting to Image Corruptions on CIFAR-10-C

The example adapts a CIFAR-10 classifier to image corruptions on CIFAR-10-C. The purpose of the example is explanation, not reproduction: exact details of the model architecture, optimization settings, etc. may differ from the paper. That said, the results should be representative, so do give it a try and experiment!

This example compares a baseline without adaptation (source), test-time normalization for updating feature statistics during testing (norm), and our method for entropy minimization during testing (tent). The dataset is CIFAR-10-C, with 15 types and 5 levels of corruption. The model is WRN-28-10, which is the default model for RobustBench.

Usage:

python cifar10c.py --cfg cfgs/source.yaml
python cifar10c.py --cfg cfgs/norm.yaml
python cifar10c.py --cfg cfgs/tent.yaml

Result: tent reduces the error (%) across corruption types at the most severe level of corruption (level 5).

mean gauss_noise shot_noise impulse_noise defocus_blur glass_blur motion_blur zoom_blur snow frost fog brightness contrast elastic_trans pixelate jpeg
source code config 43.5 72.3 65.7 72.9 46.9 54.3 34.8 42.0 25.1 41.3 26.0 9.3 46.7 26.6 58.5 30.3
norm code config 20.4 28.1 26.1 36.3 12.8 35.3 14.2 12.1 17.3 17.4 15.3 8.4 12.6 23.8 19.7 27.3
tent code config 18.6 24.8 23.5 33.0 12.0 31.8 13.7 10.8 15.9 16.2 13.7 7.9 12.1 22.0 17.3 24.2

See the full results for this example in the wandb report.

Correspondence

Please contact Dequan Wang and Evan Shelhamer at dqwang AT cs.berkeley.edu and shelhamer AT google.com.

Citation

If the tent method or fully test-time adaptation setting are helpful in your research, please consider citing our paper:

@inproceedings{wang2021tent,
  title={Tent: Fully Test-Time Adaptation by Entropy Minimization},
  author={Wang, Dequan and Shelhamer, Evan and Liu, Shaoteng and Olshausen, Bruno and Darrell, Trevor},
  booktitle={International Conference on Learning Representations},
  year={2021},
  url={https://openreview.net/forum?id=uXl3bZLkr3c}
}
Comments
  • Performance on CIFAR-10-C deteriorates with more epochs

    Performance on CIFAR-10-C deteriorates with more epochs

    Hello! First of all, thank you for sharing your great work :) I've tested your code on CIFAR-10-C (severity 5) using CIFAR-10 pretrained ResNet 18/34/50, following the configuration in /master/cfgs/tent.yaml. While the tent indeed increases the classification performance at the very first epoch, it deteriorates with more epochs (even below the baseline model). This is my result:

    Models | Baseline (%) | Tent (%) (epoch 1/2/3) ------------|------------|------------ ResNet18 | 62.23 | 78.85 / 77.02 / 74.33 ResNet34 | 62.43 | 74.31 / 64.24 / 53.74 ResNet50 | 61.84 | 67.58 / 47.56 / 34.82

    I expected the performance to gradually increase, but it didn't. Is this result reasonable, or did I do something wrong? Thank you :)

    opened by 1ho0jin1 5
  • The Number of Forward Pass

    The Number of Forward Pass

    As the paper said, TNET needs 2× the inference time plus 1× the gradient time per test point, but I found there is only one forward and one gradient update in the code https://github.com/DequanWang/tent/blob/03ac55c4fef0fda3eacb2f6414b099031e96d003/tent.py#L49

    Is the right order: forward, backward, and forward?

    opened by kinredon 4
  • training loss value is always 0

    training loss value is always 0

    Hi @DequanWang ,

    Thanks for you open source the code firstly, I try to use the model as my paper baseline, but the training loss value is always 0.

    My training script code following,

    self.model.train()
    self.model = tent.configure_model(self.model)
    params, _ = tent.collect_params(self.model)
    self.optimizer = optim.Adam(params, lr=3e-4)
    tent_model = tent.Tent(self.model, self.optimizer)
    
    for idx, data in enumerate(self.train_loader):
            image = data['img'].type(torch.FloatTensor).cuda(non_blocking=True)
    
            output, loss = tent_model(image)
    

    It's worth mentioning that this happens whether I load the model or not.

    Looking Forward to Hearing from You.

    opened by JohnMasoner 1
  • Question about Tent Offline Results

    Question about Tent Offline Results

    I have a simple question related to the offline tent experiment. What should I change if I want to get results of the offline tent (ex, Table 2)?
    Should I change _C.MODEL.EPISODIC = True https://github.com/DequanWang/tent/blob/e9e926a668d85244c66a6d5c006efbd2b82e83e8/conf.py#L37-L39

    Termination For online adaptation, no termination is necessary, and iteration continues as long as there is test data. For offline adaptation, the model is first updated and then inference is repeated. Adaptation may of course continue by updating for multiple epochs.

    opened by taeyeop-lee 0
  • how does minimizing the shannon entropy increase the accuracy of classification?

    how does minimizing the shannon entropy increase the accuracy of classification?

    all i know is minimizing the shannon entropy can lower the uncertainty of the model, but how can i assure the model is becoming more accurate instead of becoming less accurate after minimizing the entropy?looking forward to an answer

    opened by XYHhhhhhhhh 1
  • "url_base"can't be accessed

    Hello! First of all, thank you for sharing your great work

    When I run example--WRN-28-10, I find that: url_base ,which is = "https://docs.google.com/uc?export=download", can't be accessed. Is the link invalid?

    image

    image

    If it is because the url is invalid, could you upload it again?

    thank you very much!

    opened by CYDping 2
  • Cifar-10c, Cifar-100c and Imagenet-c Results (Not as reported in the paper)

    Cifar-10c, Cifar-100c and Imagenet-c Results (Not as reported in the paper)

    Hi,

    Thank you for a very nice paper. I have tried to reproduce (or get close) to the results mentioned in the paper. I cannot reproduce the results for Cifar 10c and Cifar 100c by using the resnet-26 as also used by TTT (Sun et. al) paper. I am pretty sure, that I am doing everything right because my trained (resnet-26) gives me an error of 8.2 percent on the clean test set.

    When I try to use it with tent, the performance degrades. I am attaching the log file for Resnet 26 here with this issue just so you know what is happening. I must also mention that the results mentioned in the paper (for Cifar10c and 100c) were reproduced by using a Wide resnet 28. But there is NO mention of using a wide resnet 28 in the paper.

    Did you update the final version of the paper or I am doing something wrong? I am also attaching the log file with this issue for the results obtained by using wide resnet 28.

    Also, can you please tell me what architecture did you use for the imagenet results? Basically when I take an off the shelf resnet 50 (pretrained on imagenet) and try to reproduce the results. It doesn't. In fact the system totally blows up! Is it some other model used for imagenet results as well, instead of resnet 50? Also, adding the log file for Imagenet results.

    I look forward to your answer.

    Thanks and BR,

    Mirza.

    tent_resnet_26.txt tent_wide_resnet_28.txt tent_imagenet.txt

    opened by jmiemirza 5
  • About the performance on DA datasets like Digits, Office, VisDA-C and etc

    About the performance on DA datasets like Digits, Office, VisDA-C and etc

    Hi, thanks for your great work. I re-implement Tent based on Transfer-Learning-Library to evaluate its performance on DA datasets. And I only update BN layers as recommented in the paper. However, I find the accuracy is really low. Could you please release the code to help reproducing the results on Digits and VisDA. Thanks a lot.

    opened by fumyou13 0
Owner
Dequan Wang
CS Ph.D. Student at UC Berkeley
Dequan Wang
Code base for "On-the-Fly Test-time Adaptation for Medical Image Segmentation"

On-the-Fly Adaptation Official Pytorch Code base for On-the-Fly Test-time Adaptation for Medical Image Segmentation Paper Introduction One major probl

Jeya Maria Jose 17 Nov 10, 2022
[CVPR 2022] CoTTA Code for our CVPR 2022 paper Continual Test-Time Domain Adaptation

CoTTA Code for our CVPR 2022 paper Continual Test-Time Domain Adaptation Prerequisite Please create and activate the following conda envrionment. To r

Qin Wang 87 Jan 8, 2023
Adversarial Adaptation with Distillation for BERT Unsupervised Domain Adaptation

Knowledge Distillation for BERT Unsupervised Domain Adaptation Official PyTorch implementation | Paper Abstract A pre-trained language model, BERT, ha

Minho Ryu 29 Nov 30, 2022
AntroPy: entropy and complexity of (EEG) time-series in Python

AntroPy is a Python 3 package providing several time-efficient algorithms for computing the complexity of time-series. It can be used for example to e

Raphael Vallat 153 Dec 27, 2022
A PyTorch implementation of Sharpness-Aware Minimization for Efficiently Improving Generalization

sam.pytorch A PyTorch implementation of Sharpness-Aware Minimization for Efficiently Improving Generalization ( Foret+2020) Paper, Official implementa

Ryuichiro Hataya 102 Dec 28, 2022
Tilted Empirical Risk Minimization (ICLR '21)

Tilted Empirical Risk Minimization This repository contains the implementation for the paper Tilted Empirical Risk Minimization ICLR 2021 Empirical ri

Tian Li 40 Nov 28, 2022
Sharpness-Aware Minimization for Efficiently Improving Generalization

Sharpness-Aware-Minimization-TensorFlow This repository provides a minimal implementation of sharpness-aware minimization (SAM) (Sharpness-Aware Minim

Sayak Paul 54 Dec 8, 2022
Codes accompanying the paper "Learning Nearly Decomposable Value Functions with Communication Minimization" (ICLR 2020)

NDQ: Learning Nearly Decomposable Value Functions with Communication Minimization Note This codebase accompanies paper Learning Nearly Decomposable Va

Tonghan Wang 69 Nov 26, 2022
A PyTorch implementation of the paper Mixup: Beyond Empirical Risk Minimization in PyTorch

Mixup: Beyond Empirical Risk Minimization in PyTorch This is an unofficial PyTorch implementation of mixup: Beyond Empirical Risk Minimization. The co

Harry Yang 121 Dec 17, 2022
Pytorch implementation of the AAAI 2022 paper "Cross-Domain Empirical Risk Minimization for Unbiased Long-tailed Classification"

[AAAI22] Cross-Domain Empirical Risk Minimization for Unbiased Long-tailed Classification We point out the overlooked unbiasedness in long-tailed clas

PatatiPatata 28 Oct 18, 2022
Implement of "Training deep neural networks via direct loss minimization" in PyTorch for 0-1 loss

This is the implementation of "Training deep neural networks via direct loss minimization" published at ICML 2016 in PyTorch. The implementation targe

Cuong Nguyen 1 Jan 18, 2022
PyTorch code for SENTRY: Selective Entropy Optimization via Committee Consistency for Unsupervised DA

PyTorch Code for SENTRY: Selective Entropy Optimization via Committee Consistency for Unsupervised Domain Adaptation Viraj Prabhu, Shivam Khare, Deeks

Viraj Prabhu 46 Dec 24, 2022
noisy labels; missing labels; semi-supervised learning; entropy; uncertainty; robustness and generalisation.

ProSelfLC: CVPR 2021 ProSelfLC: Progressive Self Label Correction for Training Robust Deep Neural Networks For any specific discussion or potential fu

amos_xwang 57 Dec 4, 2022
RE3: State Entropy Maximization with Random Encoders for Efficient Exploration

State Entropy Maximization with Random Encoders for Efficient Exploration (RE3) (ICML 2021) Code for State Entropy Maximization with Random Encoders f

Younggyo Seo 47 Nov 29, 2022
Implementation of accepted AAAI 2021 paper: Deep Unsupervised Image Hashing by Maximizing Bit Entropy

Deep Unsupervised Image Hashing by Maximizing Bit Entropy This is the PyTorch implementation of accepted AAAI 2021 paper: Deep Unsupervised Image Hash

null 62 Dec 30, 2022
PyTorch code accompanying our paper on Maximum Entropy Generators for Energy-Based Models

Maximum Entropy Generators for Energy-Based Models All experiments have tensorboard visualizations for samples / density / train curves etc. To run th

Rithesh Kumar 135 Oct 27, 2022
Predicting path with preference based on user demonstration using Maximum Entropy Deep Inverse Reinforcement Learning in a continuous environment

Preference-Planning-Deep-IRL Introduction Check my portfolio post Dependencies Gym stable-baselines3 PyTorch Usage Take Demonstration python3 record.

Tianyu Li 9 Oct 26, 2022
Softlearning is a reinforcement learning framework for training maximum entropy policies in continuous domains. Includes the official implementation of the Soft Actor-Critic algorithm.

Softlearning Softlearning is a deep reinforcement learning toolbox for training maximum entropy policies in continuous domains. The implementation is

Robotic AI & Learning Lab Berkeley 997 Dec 30, 2022
Weakly Supervised Posture Mining with Reverse Cross-entropy for Fine-grained Classification

Fine-grainedImageClassification Weakly Supervised Posture Mining with Reverse Cross-entropy for Fine-grained Classification We trained model here: lin

ZhenchaoTang 14 Oct 21, 2022