Evan Shelhamer�UBC / Vector Institute
Class #2
2025-09-09
CPSC 532X:
Test-Time Adaptation
Today: The Second Step!
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
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 ⚙️
Course Format:..
There Will Be Reading!_
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.
Course Grading: Project-Focused with Participation
20% attendance and participation
30% paper presentations and written reactions
50% course project
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
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
But Shift Happens
Luckily, Deep Learning for Vision Works!
train test
ImageNet-C Hendrycks & Dietterich ICLR’19
blur
weather
compression
noise
train
"goldfinch"
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
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
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
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?
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, ???
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, ???
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
soup
=
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
soup
=
⛺️
⛺️
⛺️
How to adapt�to shifts?
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)
More Corruption, More Loss & Entropy
Plot of loss (L) and entropy (H)��for a source (= unadapted) model on different test sets
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
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
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
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
figure: Wu & He ECCV'18
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
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)
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
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:�
* except last layers
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)
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
Real-to-Real: Wildfire without Adaptation
unadapted model:�HRNet trained on Cityscapes�for semantic segmentation / pixel-wise prediction
Real-to-Real: Wildfire with Adaptation by Normalization
adapted model� + statistics update
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
Analysis: Tent Reduces Entropy
sorted test entropies on CIFAR-100(-C)
Analysis: Less Entropy, Less Loss (Mostly, but Not Always)
changes in loss (L) and entropy (H)�after adaptation by tent on CIFAR-100-C�
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)
Analysis: Error vs. Entropy Pre/Post Adaptation
measuring error rate and entropy for a source model + normalization update and + entropy update
source
norm
tent
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
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
Alternatives for Adaptation with and without Source Data
fully test-time,
only target
domain adaptation,�source and target
test-time training,�after pre-training
Alternatives for Adaptation with and without Source Data
fully test-time,
only target
domain adaptation,�source and target
test-time training,�after pre-training
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
Test-Time Training by Self-Supervision: The Train-Time Update
Test-Time Training by Self-Supervision: The Test-Time Update
🔒
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
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
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
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
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
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
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
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
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