TTTFlow: Unsupervised Test-Time Training with Normalizing Flow

David Osowiechi, Gustavo Adolfo Vargas Hakim, Mehrdad Noori, Milad Cheraghalikhani, Ismail Ben Ayed, Christian Desrosiers

Abstract

Deep learning models often suffer from performance degradation when encountering "out-of-distribution" data at test time. We present TTTFlow, a novel framework for unsupervised test-time training that utilizes Normalizing Flows (NF) to detect domain shifts and adapt the model on the fly. Unlike traditional methods that rely on human-designed proxy tasks, TTTFlow uses a generative approach to align test-time features with the training distribution. Our evaluations on standard benchmarks like CIFAR-10-C demonstrate that TTTFlow significantly improves robustness and maintains high stability during adaptation.

Introduction

Standard deep learning assumes that training and test data are drawn from the same distribution. However, real-world deployments often face "domain shifts" caused by weather changes, sensor noise, or varying data collection conditions. Existing solutions like Domain Generalization (DG) require massive diverse datasets, while Test-Time Training (TTT) often relies on specialized "proxy tasks" (e.g., predicting image rotation) that may not generalize to all types of data shifts. TTTFlow addresses these limitations by providing an unsupervised adaptation mechanism that does not require source data at test time or manually designed proxy tasks.

Methodology: The Y-Shaped Architecture

The core of TTTFlow is a "Y-shaped" architecture designed to decouple classification from distribution modeling. The system consists of three primary components:

  1. Feature Extractor ($f_\theta$): A backbone network (such as ResNet50) that maps input images into a latent feature space.
  2. Classification Head ($h_\varphi$): The standard component that predicts labels from the extracted features.
  3. Normalizing Flow (NF) Head ($g_\phi$): A generative model trained to map the complex distribution of source features into a simple, tractable Gaussian distribution.
The TTTFlow architecture showing the feature extractor, classifier, and the Normalizing Flow head used for unsupervised adaptation.

The Workflow

The training and adaptation process occurs in two distinct phases:

  • Source Training: The classifier is trained on labeled source data. Subsequently, the NF head is trained in an unsupervised manner to learn the distribution of features produced by the source data while the feature extractor remains frozen.
  • Test-Time Adaptation: When a shifted image is encountered, the NF head calculates the log-likelihood of its features. A low likelihood indicates a domain shift. The model then performs several iterations of gradient descent to update the feature extractor weights, maximizing the log-likelihood from the NF head. This process "nudges" the extractor to produce features that resemble the original training distribution.

Experimental Results

We evaluated TTTFlow on several robustness benchmarks, including CIFAR-10-C (containing 15 types of algorithmic corruptions) and CIFAR-10.1 (natural domain shift).

Performance and Stability

On the most severe corruption level (Level 5) of CIFAR-10-C, TTTFlow improved average accuracy from a baseline of 60.68% to 75.22%. When integrated with stronger base models like TTT++, the system reached an average accuracy of 83.56%, outperforming existing state-of-the-art methods.

A key advantage of TTTFlow is its stability. Many test-time adaptation methods suffer from performance collapse if too many adaptation steps are taken. In contrast, TTTFlow shows consistent improvement or plateaus across many iterations, as shown in the figure below.

Accuracy vs. Iteration for various corruption types on CIFAR-10-C, demonstrating the stability and effectiveness of TTTFlow across different domain shifts.

Key Insights and Limitations

TTTFlow acts as a universal proxy for out-of-distribution detection, measuring the distance from the training distribution in a mathematically rigorous way. It is a "plug-and-play" solution compatible with most pretrained networks.

However, some challenges remain. The method's performance is sensitive to the representation power of the Normalizing Flow; an overly complex NF might lead to "class collapse." Additionally, the current implementation is most effective when adapting to batches of images rather than single instances, and the requirement for gradient descent during inference introduces computational overhead.

Conclusion

TTTFlow provides a robust, unsupervised pathway for adapting deep learning models to unpredictable real-world data shifts. By leveraging the generative power of Normalizing Flows, it moves beyond the limitations of task-specific proxies, offering a more general and stable solution for test-time training.

Summary updated

BibTeX
@inproceedings{osowiechi2023tttflow,
  author = {David Osowiechi and Gustavo Adolfo Vargas Hakim and Mehrdad Noori and Milad Cheraghalikhani and Ismail Ben Ayed and Christian Desrosiers},
  title = {{TTTFlow: Unsupervised Test-Time Training with Normalizing Flow}},
  booktitle = {IEEE/CVF Winter Conference on Applications of Computer Vision},
  year = {2023},
  doi = {10.1109/wacv56688.2023.00216},
}
Figure