GithubHelp home page GithubHelp logo

dequanwang / tent Goto Github PK

View Code? Open in Web Editor NEW
339.0 339.0 43.0 24 KB

ICLR21 Tent: Fully Test-Time Adaptation by Entropy Minimization

Home Page: https://arxiv.org/abs/2006.10726

License: MIT License

Python 100.00%

tent's People

Contributors

dequanwang avatar shelhamer avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

tent's Issues

The results on ImageNet-C sensitive to some hyperparameters

Hi, thanks for sharing your great work. And the current repository only contains example code to illustrate how tent works. I am wondering if you will share the code to exactly reproduce results on ImageNet-C or some implementation details if the code is not available. Because it seems that tent is very sensitive to choices of some hyperparameters.

How do the outputs change?

According to the code (and assuming that STEPS = 1, i dont understand how the outputs change after the adaptation:

def forward(self, x):
    if self.episodic:
        self.reset()

    for _ in range(self.steps):
        outputs = forward_and_adapt(x, self.model, self.optimizer)
    return outputs

@torch.enable_grad()  # ensure grads in possible no grad context for testing
def forward_and_adapt(x, model, optimizer):
    """Forward and adapt model on batch of data.

    Measure entropy of the model prediction, take gradients, and update params.
    """
    # forward
    outputs = model(x)
    # adapt
    loss = softmax_entropy(outputs).mean(0)
    loss.backward()
    optimizer.step()
    optimizer.zero_grad()
    return outputs

judging by the code, you return the original outputs however they do change somehow, how?

The code for source-free UDA experiments

Hi, thanks for sharing your great work. Recently, I try to reproduce your experiments on digit 5 with a simple network. However, it doesn't work. Could you please also share the code used for the source-free UDA experiments?

The backbone network for the experiments on cifar10 and cifar100

In the paper, the backbone network for the experiments on cifar10 and cifar100 is R-26, but the implementation is WRN-28-10, could the authors provide the R-26 experiment code? I hope the authors provide more details about how to implement the R-26 and the training setup. Thanks very much!

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.

Problem of scenario: episodic and step=1

Hello!
I have a problem understanding the code when it is online (episodic) and step=1.
The output of the old model(before adaptation) is used for both backprop and accuracy calculation.
So the online scenario doesn't actually output the results after the test adaptation, instead it outputs the results before the test adaptation.

Thank you in advance!

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 :)

GTA to Cityscapes

I tested semantic segmentation from the cityscape dataset to the Zurich dataset. The miou for the former is 73%, and Zurich is 32% without tent, but becomes 16% with tent. I was hoping you could give me your semantic segmentation code for GTA to cityscapes so I can see what went wrong, please

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.

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

tent/tent.py

Line 49 in 03ac55c

def forward_and_adapt(x, model, optimizer):

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

Having issues reproducing test error statistics when configuring model.

I've trained my model and have some tests statistics X. Afterward, I an untented, but configured version of the model and I am unable to reach the accuracy X. I've changed the batch size to match the training batch size, but still the issue persist. It probably has to do with using the "model.train()" function. Note, I am using Efficientnet_v2_s as my model.

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

Why is entire model set to train, instead of only BatchNorm modules

Model is set to train mode in TENT so that BatchNorm modules use batch statistics at test time. However, this also sets other modules to train mode, for instance Dropout.

tent/tent.py

Lines 96 to 110 in e9e926a

def configure_model(model):
"""Configure model for use with tent."""
# train mode, because tent optimizes the model to minimize entropy
model.train()
# disable grad, to (re-)enable only what tent updates
model.requires_grad_(False)
# configure norm for tent updates: enable grad + force batch statisics
for m in model.modules():
if isinstance(m, nn.BatchNorm2d):
m.requires_grad_(True)
# force use of batch stats in train and eval modes
m.track_running_stats = False
m.running_mean = None
m.running_var = None
return model

It is also possible to set submodules to train mode only, and I believe this would achieve the desired behaviour for BatchNorm without affecting other modules. Is my understanding correct?

About Threat Model

Hi!Thanks for sharing your code here!
Here's a question,what is threat model for?I couldn't find it in the paper.looking forward to your reply!

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

tent/conf.py

Lines 37 to 39 in e9e926a

# By default tent is online, with updates persisting across batches.
# To make adaptation episodic, and reset the model for each batch, choose True.
_C.MODEL.EPISODIC = False

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.

code release

Thanks for sharing this example code. Any plan to release code on ImageNet or segmentation datasets ?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.