1 of 50

Evan Shelhamer�UBC / Vector Institute

Class #2

2025-09-09

CPSC 532X:

Test-Time Adaptation

2 of 50

Today: The Second Step!

  1. Topics�adaptation + adaptive computation�
  2. Course Details�site and syllabus (soon)�
  3. Test-Time Adaptation + Test-Time Training�let's pick up where we left off with Tent�and check out one more method before�touring adaptive computation next class

3 of 50

Course Topics: Adaptation and Adaptive Computation

Depth or Layer-wise Computation,�Routing Computation, Iterative Computation,

…

Adaptive Computation: How to update execution on each input, or the how

Adaptation: How to adapt to new and different data� by updating the model function, or the what

​

Update the Inputs�Diffusion-Driven Adaptation�Gao*, Zhang*, Liu, Darrell,�Wang†, Shelhamer†, CVPR'23

​

Adaptive Randomized Smoothing�Lyu*, Shaikh*, Frederick Shpilevskiy*�Shelhamer, Lécuyer. NeurIPS'24

Update the Parameters�Tent: Test Entropy Minimization�Wang*, Shelhamer*, et al. ICLR'21�

Mix Parameters�Seasoning Model Soups�Croce, Rebuffi, Shelhamer, Gowal. CVPR'23

0

1

2

soup

=

Spatial Computation�LookWhere: Self-Supervised Efficiency�Fuller*, Yassin*, Wen, Kyrollos, Ibrahim,�Green†, Shelhamer†. arXiv'25�

Temporal Computation�Clockwork Networks for Video�E. Shelhamer*, K. Rakelly*, J. Hoffman*,

T. Darrell. ECCVW 2016�

We will learn about these topics through papers and projects�with emphasis on experiments 🔬 and engineering ⚙️

4 of 50

Course Format:..

There Will Be Reading!_

5 of 50

Course Site + Syllabus

🚧 ⚠️ still under construction for this Thu. Sep. 11 or sooner

​

​

🖇️📚 all materials will be shared on the site: papers, slides, books, …

​

👀📯 watch for a notification through workday with the URL� and I will share it in class on Thu.

​

6 of 50

Course Grading: Project-Focused with Participation

20% attendance and participation

30% paper presentations and written reactions

50% course project

7 of 50

Questions?

email shelhamer@cs.ubc.ca about this and anything else to help you decide to take the class or not by the end of this week for add/drop

you should ask about enrollment if you are still on the waitlist

you should ask about prequisites and bonus materials if too much is unfamiliar about deep learning, the types of data we are talking about,�or anything else

8 of 50

Visual Data is Vast and Varied (+ Text, Audio, …, is Too!)

The visual world is too vast and varied to fully describe by hand

Learning is essential to handle the variety of visual data

Adaptation keeps learning to cope with changing data

…because we live in a changing world

9 of 50

But Shift Happens

Luckily, Deep Learning for Vision Works!

train test

ImageNet-C Hendrycks & Dietterich ICLR’19

blur

weather

compression

noise

train

"goldfinch"

10 of 50

But Shift Happens, and Shift Hurts

R-50

59.5% error vs.

23.9% error

how can we (1) make a model learn + adapt on different data and (2) equip a model to adapt itself on new shifts?

...there was an unexpected shift with the wildfires

because shift is actually the rule, and the data can keep changing

ViTB

44.5% error vs.

20.0% error

train test

11 of 50

The Need: Fully Test-Time Adaptation

why during testing? for generalization to new & different data that degrades accuracy without adaptation

ImageNet-C Hendrycks & Dietterich ICLR’19

why fully test-time?

1. Availability: a model might be distributed without training data for bandwidth, privacy, or profit

​

2. Efficiency: it might not be computationally practical to (re-)process training data during testing

R-50

59.5% error vs.

23.9% error

ViTB

44.5% error vs.

20.0% error

12 of 50

Review of Adaptation Settings

Of the source s and target t data x and labels y, our fully test-time setting only needs the target data xt�no need for the source data given the source model

Test-Time Training adapts during testing, but needs source data during training

Fully Test-Time adapts during testing by online updates—no source data or offline computation

​

settings differ by their data and therefore losses for training and testing�

today

today�+ last time

13 of 50

Natural Shifts and Adversarial Shifts

natural shifts like weather change the input but�systematically—snow is similar across images

adversarial shifts like attacks change the input�to cause errors like an opponent would

1. can adaption learn to cope with change?

2. can adaption learn to defend against attacks?

14 of 50

Natural Shifts and Adversarial Shifts

natural shifts like weather change the input but�systematically—snow is similar across images

adversarial shifts like attacks change the input�to cause errors like an opponent would

1. can adaption learn to cope with change? yes!

2. can adaption learn to defend against attacks? yes, no, ???

15 of 50

Natural Shifts and Adversarial Shifts

natural shifts like weather change the input but�systematically—snow is similar across images

adversarial shifts like attacks change the input�to cause errors like an opponent would

1. can adaption learn to cope with change? yes!

2. can adaption learn to defend against attacks? yes, no, ???

16 of 50

Test-Time Adaptation of Models and Inputs for Robustness

How to adapt�to shifts?

How to adapt to changing conditions ☀️🌧❄️ �by updating on new and different data during testing�

Update the Inputs�Diffusion-Driven Adaptation�Gao*, Zhang*, Liu, Darrell,�Wang†, Shelhamer†, CVPR'23

​

Adaptive Randomized Smoothing�Lyu*, Shaikh*, Frederick Shpilevskiy*�Shelhamer, Lécuyer. NeurIPS'24

Mix Parameters�Seasoning Model Soups�Croce, Rebuffi, Shelhamer, Gowal. CVPR'23

0

1

2

soup

=

Update the Parameters�Tent: Test Entropy Minimization�Wang*, Shelhamer*, et al. ICLR'21�

17 of 50

Test-Time Adaptation of Models and Inputs for Robustness

How to adapt to changing conditions ☀️🌧❄️ �by updating on new and different data during testing�without needing more supervision or even altering training!

Update the Inputs�Diffusion-Driven Adaptation�Gao*, Zhang*, Liu, Darrell,�Wang†, Shelhamer†, CVPR'23

​

Adaptive Randomized Smoothing�Lyu*, Shaikh*, Frederick Shpilevskiy*�Shelhamer, Lécuyer. NeurIPS'24

Update the Parameters�Tent: Test Entropy Minimization�Wang*, Shelhamer*, et al. ICLR'21�

Mix Parameters�Seasoning Model Soups�Croce, Rebuffi, Shelhamer, Gowal. CVPR'23

0

1

2

soup

=

⛺️

⛺️

⛺️

How to adapt�to shifts?

18 of 50

Predictions with lower entropy tend to have�lower error rates on corrupted CIFAR-100-C

���

​

​

​

​

high entropy / uniform

low entropy / peaked

Certainty could supervise on test data�if we figure out how to update at test time�

see Grandvalet & Bengio 2005�for the semi-supervised setting�at train time

uncertain

certain

"cat"

Entropy as a Loss for Fully Test-Time Adaptation ICLR'21 (Spotlight)

19 of 50

More Corruption, More Loss & Entropy

Plot of loss (L) and entropy (H)��for a source (= unadapted) model on different test sets

  • Corruption types are grouped by color�
  • Corruption level {1, 2, 3, 4, 5} is less/more opaque�
  • Increasing corruption increases both loss and entropy with rank correlation 0.61

original

Note: the loss and entropy on the original test set are low,� and both are approximately zero on the train set too

Entropy can serve as a measure of shift

20 of 50

The Method: Update while Predicting during Testing

briefly: minimize entropy of model predictions by updating statistics and just a few parameters in normalization layers�tent for test entropy minimization

  • training optimizes parameter 𝞱 to minimize supervised loss

​

  • tent optimizes modulation 𝚫 to minimize prediction entropy

​

  • tent does not alter training

​

  • tent adapts online during testing & batch-by-batch

21 of 50

The Update: Estimate Statistics + Minimize Entropy (That's All!)

briefly: minimize entropy of model predictions by updating statistics and just a few parameters in normalization layers�tent for test entropy minimization

Perez et al. AAAI'18

prior work�learn the change during training�our work�adapt the change during testing

we can do this during testing because�we update <1% of all parameters, so�you can too!

which statistics and parameters?�change the normalization + transformation

⨉ k

R-50

59.5% error vs.

23.9%

vs.

44.0%

w/ Tent

ViTB

44.5% error vs.

20.0%

vs.

37.3%

w/ SAR

it can help!

how to update?�

- estimate normalization statistics�- optimize transformation parameters��where estimation and optimization update online on batches of the test data�

1. predict and update normalization 2. measure entropy and update transformation 3. keep updates for the next batch / step

22 of 50

The Update: Test-Time Normalization

The statistics update alone is a method and Tent baseline:

simply (re-)estimate the mean and variance of the features

if the shift only changes the mean and variance, then normalizing by

the shifted mean and shifted variance cancels it out

Fixup and GN trained models perform better

than non-adapted BN models but worse than adapted BN models

​

23 of 50

Fully Test-Time Adaptation to Natural Shifts: Corruptions

Error on ImageNet-C with R-50

�Tent improves on its error�without altering training

​

Tent also improves on

test-time normalization

​

ANT was the prior best�with adversarial noise training

by Rusak et al.

Tent is state-of-the-art on ImageNet-C

24 of 50

Train-Time Adaptation to Natural Shifts: Adversarial Noise Training

Error on ImageNet-C with R-50

�ANT improves its error on�new data by training more on known data with its own corruptions

​

​

However, after training ANT never updates so it cannot adapt to the�test data

Adversarial Noise Training (ANT) was the prior state-of-the-art on ImageNet-C (Rusak et al. ECCV 2020)

25 of 50

Fully Test-Time Adaptation to Natural Shifts: Corruptions

Tent is was state-of-the-art on ImageNet-C… well done latest test-time adaptation methods! (like SAR, which extends Tent)

Error on ImageNet-C with R-50

�Tent improves on its error�without altering training

​

Tent also improves on

test-time normalization

​

ANT was the prior best�with adversarial noise training

by Rusak et al.

test-time adaptation�can be more robust than�train-time anticipation

26 of 50

Simulation-to-Real: from Rendering to Reality on VisDA-C

task: image classification�data: simulated training (3D rendering),� real testing (COCO)�metric: error % (lower is better)��

parameterization matters! harder shifts need more parameters and what to update is now a key topic

results:�

  • source 56.1%
  • tent (few) 45.6%
  • tent (all*) 39.6%�

* except last layers

27 of 50

Sim-to-Real: from GTAV (= Game) to Cityscapes (= Germany)

test-time adaptation on a single image can recover missing objects and reduce errors

Image

Truth

Before (Source)

After (Tent)

28 of 50

Sim-to-Real: from GTAV (= Game) to Cityscapes (= Germany)

test-time adaptation on a single image by pixel-wise entropy minimization

source

norm

tent: 1

tent: 2

29 of 50

Real-to-Real: Wildfire without Adaptation

unadapted model:�HRNet trained on Cityscapes�for semantic segmentation / pixel-wise prediction

30 of 50

Real-to-Real: Wildfire with Adaptation by Normalization

adapted model� + statistics update

31 of 50

Real-to-Real: Wildfire with Adaptation by Tent

adapted model� + statistics update� + entropy minimization update

sidewalk

street

tree

car

building

sign

it's better, but our work is not done here

32 of 50

Analysis: Tent Reduces Entropy

sorted test entropies on CIFAR-100(-C)

  • modulation is enough�to alter predictions�
  • tent reduces entropy�for all levels of severity�including original data�
  • rank order is preserved,�and most uncertain stays�the most uncertain

33 of 50

Analysis: Less Entropy, Less Loss (Mostly, but Not Always)

changes in loss (L) and entropy (H)�after adaptation by tent on CIFAR-100-C�

  • Loss for analysis is the cross entropy�with the true class�
  • Entropy is the Shannon entropy�of the prediction�
  • Both are normalized by log(C) for C classes�

Reducing entropy does in general reduce the loss,�note the dark diagonal and rank correlation of 0.22��However, there are changes in all directions, and sometimes tent decreases the entropy but increases the loss (top-left)

34 of 50

Analysis: Error vs. Entropy Pre/Post Adaptation

measuring error rate and entropy for a source model + normalization update and + entropy update

  • each dot is a corrupted test set plotted by its error and entropy over its data points�
  • the baseline is not perfect, but entropy and error rate are almost linearly related�
  • entropy minimization by Tent reduces entropy, but not dramatically, and the ordering is mostly preserved

source

norm

tent

35 of 50

Analysis: Tent Feature Modulation is Not Simply Normalization

Adapted features (front) on corrupted inputs and and reference features (back) without corruption

Corruption shifts features away from the reference, but BN reduces the shifts

Tent is less like the reference, and more like an oracle that optimizes on target labels

  • data: CIFAR-100-C with Gaussian noise
  • model: ResNet-26 at L = 11

36 of 50

Review of Adaptation Settings

Of the source s and target t data x and labels y, our fully test-time setting only needs the target data xt�no need for the source data given the source model

Test-Time Training adapts during testing, but needs source data during training

Fully Test-Time adapts during testing by online updates—no source data or offline computation

​

settings differ by their data and therefore losses for training and testing�

today

today�+ last time

37 of 50

Alternatives for Adaptation with and without Source Data

fully test-time,

only target

  • source-only/unadapted model�
  • adversarial domain adaptation by reversed gradients (RG)�
  • self-supervised domain adaptation (UDA-SS)�
  • self-supervised test-time training (TTT)�
  • test-time normalization (BN):�only update normalization statistics�
  • pseudo-labeling/bootstrapping (PL):�take the most likely class as the ground truth

domain adaptation,�source and target

test-time training,�after pre-training

38 of 50

Alternatives for Adaptation with and without Source Data

fully test-time,

only target

  • source-only/unadapted model�
  • adversarial domain adaptation by reversed gradients (RG)�
  • self-supervised domain adaptation (UDA-SS)�
  • self-supervised test-time training (TTT)�
  • test-time normalization (BN):�only update normalization statistics�
  • pseudo-labeling/bootstrapping (PL):�take the most likely class as the ground truth

domain adaptation,�source and target

test-time training,�after pre-training

39 of 50

Test-Time Training by Self-Supervision: The Auxiliary Task

s: self-supervision

self-supervision:

design a learning task where the label is a function of the input for automatic labeling��example: recognize rotations of an image� (also called an auxiliary task)

e: embedding/�representation

40 of 50

Test-Time Training by Self-Supervision: The Train-Time Update

41 of 50

Test-Time Training by Self-Supervision: The Test-Time Update

🔒

42 of 50

Test-Time Training by Self-Supervision: Results

Test-Time Training (TTT)�improves accuracy over

the source baseline and

joint training and online cumulative updates are best

TTT updates on each sample to improve accuray on average but sometimes helps and sometimes hurts

note: TTT only helps on the shifted data and not on the original data

43 of 50

Tent Adapts to Corruption on CIFAR-10-C/100-C

reference source error��- CIFAR-10 5.0%�- CIFAR-100 21.0

34.2 when adapted on target train,

so modulation generalizes across points

44 of 50

Tent Adapts across Digits without Source

Adaptation from SVHN source to MNIST and other targets

Tent improves on domain adaptation in ⅔ cases, without joint use of source and target data

​

Note efficiency with 0.01x of the data and 0.1x of the optimization

45 of 50

Tent Adapts across Digits without Source

Tent Adapts across Digits without Source

these results are for offline adaptation for fair comparison with offline baselines��tent online reaches 12.5% error in 1 epoch and 8.4% error in 10 epochs on MNIST��still better than baselines and more efficient with less latency for predictions

​

/ 12.5

/ 8.4

Adaptation from SVHN source to MNIST and other targets

46 of 50

Test-Time Adaptation + Test-Time Training:�When a System Must Adapt Itself

Truth

Before (Source)

After (Tent)

⛺️ Tent helps a model adapt itself in changing conditions ☀️ 🌧 ❄️�by updating on new and different data during testing�without altering training or requiring more supervision

from static with the same�parameters 𝜃 for all x

to adaptive by gradient updates� and statistics updates� for a new model on new data

47 of 50

Extension: MEMO for adaptation to one input�Zhang et al. NeurIPS'22 https://arxiv.org/abs/2110.09506

​

Tent adapts to a batch, while MEMO adapts to just one input at a time

episodic adaptation

= adapting to each input independently or adapting on each input then resetting

48 of 50

Extension: EATA for efficient adaptation without forgetting�Niu et al. CML'22 https://arxiv.org/abs/2204.02610

Tent adapts to the current data but might forget past data, while EATA remembers past data�and keeps adapting to new and multiple shifts by 1. regularizing the parameters to be near the source model�and 2. only updating on certain batches according to a threshold on entropy

continual adaptation

= adapting to each shift in turn

49 of 50

Extension: NOTE for adaptation to related inputs�Gong et al. NeurIPS'22 https://openreview.net/forum?id=E9HNxrCFZPV

​

Tent adapts to a batch of independent data (of multiple classes/times/places),�while NOTE adapts to dependent data, for instance on a video:

(2) keep memory of past data balanced by predictions,� and update on data in the memory

(1) accept or reject statistics and correct

50 of 50

Done with the 2nd Update:�Test-Time Adaptation + Test-Time Training

Now: we have taken our second step on how to update� by test-time adaptation and test-time training

​

Next: in the next class we will take our first steps on how to update� by adaptive computation

​

Questions, Comments, Suggestions?

Share now or send to shelhamer@cs.ubc.ca