Uninformed Students | VitaVision
Back to atlas

Uninformed Students

8 min readAdvancedno public implcnnView in graphIn narrative: Foundation Models for Vision
Based on
Uninformed Students: Student-Teacher Anomaly Detection With Discriminative Latent Embeddings
Bergmann, Fauser, Sattlegger, Steger · CVPR 2020 2020
arXiv ↗

Motivation

Uninformed Students performs unsupervised, pixel-precise anomaly segmentation trained only on anomaly-free images. Input: a training set of anomaly-free images; at test time, a single image JRw×h×CJ \in \mathbb{R}^{w \times h \times C}. Output: a dense per-pixel anomaly score map of the same spatial size as the input, thresholded downstream into a binary anomaly segmentation. The defining property is an ensemble of MM student networks trained to regress the dense per-pixel feature descriptors of a fixed teacher network; the per-pixel anomaly score combines two signals — regression error between the ensemble's mixture mean and the teacher's target, and predictive variance, the ensemble's disagreement with itself. The teacher is pretrained entirely off-domain and does not observe the evaluated dataset's images during its own training, to avoid biasing the anomaly signal toward any specific target domain.

Architecture

Family & shape. Fully-convolutional patch-descriptor network, used in three roles: a frozen teacher TT, and an ensemble of MM students SiS_i sharing the teacher's architecture. A single forward pass yields one dd-dimensional descriptor per pixel, each summarizing a p×pp \times p receptive-field patch centered at that pixel — avoiding strided patch-by-patch evaluation. Teacher and students output d=128d = 128-dimensional descriptors. Three receptive-field sizes are trained as separate (T,S1..M)(T, S_{1..M}) pairs — p{17,33,65}p \in \{17, 33, 65\} — and combined at inference for multi-scale anomaly segmentation.

Blocks. The teacher TT is built from a patch-classification network T^:Rp×p×CRd\hat T: \mathbb{R}^{p \times p \times C} \to \mathbb{R}^d by a deterministic dense-evaluation transform that converts patch-by-patch classification into a single fully-convolutional forward pass. T^\hat T is trained with a three-term loss combining knowledge distillation, metric learning, and descriptor decorrelation, then held frozen for the rest of the pipeline. The students SiS_i, i{1,,M}i \in \{1, \dots, M\}, share TT's architecture but are randomly initialized and trained independently, only on the target domain's anomaly-free images.

Definition
Knowledge distillation loss

Distills a pretrained ResNet-18 classification network's 512-dimensional feature output P(p)P(p) for patch pp into the patch descriptor T^(p)\hat T(p), through a decoder DD.

Lk(T^)=D(T^(p))P(p)2.\mathcal{L}_k(\hat T) = \lVert D(\hat T(p)) - P(p) \rVert^2.
Definition
Metric-learning loss

Triplet loss over a patch pp, a same-class patch p+p^+, and a different-class patch pp^-.

Lm(T^)=max{0, δ+δ+δ},\mathcal{L}_m(\hat T) = \max\{0,\ \delta + \delta^+ - \delta^-\},

with δ+=T^(p)T^(p+)2\delta^+ = \lVert \hat T(p) - \hat T(p^+) \rVert_2 and δ=min{T^(p)T^(p)2, T^(p+)T^(p)2}\delta^- = \min\{\lVert \hat T(p) - \hat T(p^-) \rVert^2,\ \lVert \hat T(p^+) - \hat T(p^-) \rVert^2\}.

Definition
Descriptor compactness loss

Sums the off-diagonal entries cijc_{ij} of the correlation matrix computed over all descriptors T^(p)\hat T(p) in the current minibatch, decorrelating descriptor dimensions.

Lc(T^)=ijcij.\mathcal{L}_c(\hat T) = \sum_{i \neq j} c_{ij}.

The three terms combine as L(T^)=λkLk+λmLm+λcLc\mathcal{L}(\hat T) = \lambda_k \mathcal{L}_k + \lambda_m \mathcal{L}_m + \lambda_c \mathcal{L}_c. The configuration used for MVTec AD sets λk=λc=1\lambda_k = \lambda_c = 1, λm=0\lambda_m = 0 — the metric-learning term is disabled. Each student SiS_i is then trained with a squared-2\ell_2 regression loss against the teacher's per-pixel descriptor, normalized by the training-set descriptor mean μRd\mu \in \mathbb{R}^d and standard deviation σRd\sigma \in \mathbb{R}^d computed once over all training descriptors. Each student's output at a pixel is treated as the mean of a Gaussian component with constant scalar covariance ss; averaging the MM students' means gives a Gaussian-mixture prediction.

Definition
Regression error

Squared distance between the ensemble's mixture mean and the normalized teacher target at pixel (r,c)(r,c). High when all students agree but agree wrongly.

e(r,c)=1Mi=1Mμ(r,c)Si(y(r,c)Tμ)diag(σ)12.e_{(r,c)} = \left\lVert \frac{1}{M}\sum_{i=1}^{M} \mu^{S_i}_{(r,c)} - \left(y^T_{(r,c)} - \mu\right)\mathrm{diag}(\sigma)^{-1} \right\rVert^2.
Definition
Predictive variance

The ensemble's disagreement with itself, written with the mixture mean μ(r,c)=1Mi=1Mμ(r,c)Si\mu_{(r,c)} = \frac{1}{M}\sum_{i=1}^{M} \mu^{S_i}_{(r,c)}. High when students diverge from each other, independent of whether their mean is close to the teacher's target.

v(r,c)=1Mi=1Mμ(r,c)Si22μ(r,c)22.v_{(r,c)} = \frac{1}{M}\sum_{i=1}^{M} \left\lVert \mu^{S_i}_{(r,c)} \right\rVert_2^2 - \left\lVert \mu_{(r,c)} \right\rVert_2^2.

The constant per-component covariance ss introduced with the training criterion does not appear here. Being uniform across pixels, students, and the ensemble, it contributes only a fixed offset and cancels under the normalisation below.

Both terms are z-normalized over a held-out anomaly-free validation set — statistics eμ,vμ,eσ,vσe_\mu, v_\mu, e_\sigma, v_\sigma — and summed into a per-pixel combined score. Combined scores from the three receptive-field scales are then averaged, unweighted, into the final multi-scale anomaly map.

Combined anomaly score for one receptive-field scale, in NumPy:

import numpy as np


def anomaly_score(student_means: np.ndarray,
                   teacher_target: np.ndarray,
                   val_stats: dict) -> np.ndarray:
    """Per-pixel anomaly score, one receptive-field scale.
    student_means: (M, H, W, d) — each student's per-pixel mean prediction.
    teacher_target: (H, W, d) — normalized teacher descriptor,
        (y_T - mu) @ diag(sigma)^-1, precomputed from training stats.
    val_stats: e_mu, e_sigma, v_mu, v_sigma from a held-out
        anomaly-free validation set (Eq. 11 of Bergmann et al. 2020).
    """
    mixture_mean = student_means.mean(axis=0)                  # (H, W, d)

    # Regression error: mixture mean vs. normalized teacher target.
    e = np.sum((mixture_mean - teacher_target) ** 2, axis=-1)   # (H, W)

    # Predictive variance: ensemble disagreement with itself.
    v = (np.sum(student_means ** 2, axis=(0, -1)) / student_means.shape[0]
         - np.sum(mixture_mean ** 2, axis=-1))                  # (H, W)

    e_z = (e - val_stats["e_mu"]) / val_stats["e_sigma"]
    v_z = (v - val_stats["v_mu"]) / val_stats["v_sigma"]
    return e_z + v_z

Training. Teacher pretraining uses ImageNet patch crops, unrelated to any evaluation domain — the teacher does not observe the evaluated datasets' images during pretraining. Optimizer: Adam, initial learning rate 2×1042 \times 10^{-4}, weight decay 10510^{-5}, batch size 64, 5×1045\times10^4 iterations. Student-ensemble training on MVTec AD: input zoomed to 256×256256\times256, 100 epochs, batch size 1, Adam initial learning rate 10410^{-4}, weight decay 10510^{-5}; M=3M=3 students per scale (M=5M=5 for the MNIST/CIFAR-10 experiments). Activation is leaky ReLU with slope 5×1035\times10^{-3} throughout. On MVTec AD, mean normalized area under the PRO-curve — integrated up to an average per-pixel false-positive rate of 30% — is 0.857 at p=65p=65 and 0.914 combining all three scales (Table 1, Table 3).

Complexity. Neither total parameter count nor FLOPs are reported. Inference cost scales with ensemble size and scale count: one teacher plus MM student forward passes per receptive-field scale, evaluated at all three scales and averaged — M×3=9M \times 3 = 9 student network evaluations per image in the MVTec AD configuration (M=3M=3).

Implementations

No implementation is cited: MVTec released no official code, the most-used third-party reimplementation carries no LICENSE file, and the only permissively licensed reimplementation is unmaintained and low-traction.

Assessment

Novelty

  • Combines two complementary per-pixel anomaly signals computed from a single ensemble — regression error (mixture-mean vs. teacher mismatch) and predictive variance (ensemble self-disagreement) — rather than either signal alone.
  • Trains the teacher entirely off-domain, on ImageNet patch crops, and never exposes it to the evaluated dataset's images, to avoid an unfair bias.
  • Trains multiple (T,S1..M)(T, S_{1..M}) pairs at different receptive-field sizes and averages their combined scores, addressing the scale-dependence of anomaly size rather than committing to one fixed scale.

Strengths

  • Mean normalized area under the PRO-curve on MVTec AD reaches 0.857 at p=65p=65, ahead of every evaluated baseline's mean, including the deterministic 2\ell_2-autoencoder (0.790) and the VAE (0.639) (Table 1).
  • Combining all three receptive-field scales (mean 0.914) beats every single scale evaluated alone (0.866, 0.900, 0.857 for p=17,33,65p=17,33,65) (Table 3).
  • On MNIST/CIFAR-10 one-class ROC-AUC, the best teacher-loss configuration (distillation + compactness, no metric-learning term) reaches 0.9935 / 0.8196 mean, ahead of a 1-NN baseline (0.9753 / 0.8189) and a deterministic autoencoder baseline (0.9832 / 0.7898) (Table 2).

Limitations

  • A single receptive-field scale under- or over-segments anomalies whose size differs from pp; per-category sensitivity to pp is inconsistent in direction — Wood's score drops from 0.943 (p=17p=17) to 0.725 (p=65p=65), while Cable's rises from 0.671 to 0.865 over the same range (Table 3).
  • The PRO-based metric is capped at 30% average per-pixel false-positive rate, since beyond that point even a perfect score becomes uninformative — the reported numbers do not characterize behavior in the high-false-positive regime.
  • On small, low-diversity one-class datasets (MNIST, CIFAR-10), a 1-NN baseline that stores every training vector outperforms the ensemble-regression approach; the method's generalization advantage matters only once training-set variability exceeds what nearest-neighbor lookup can store.
  • Training cost scales with ensemble size and scale count: a full CNN ensemble is trained separately at each receptive-field scale.
  • EfficientAD later extends this student-teacher framework, replacing the pretrained-backbone ensemble with a single distilled patch description network and loss-induced, rather than architectural, asymmetry.

References

  1. Bergmann, P., Fauser, M., Sattlegger, D., & Steger, C. Uninformed Students: Student-Teacher Anomaly Detection With Discriminative Latent Embeddings. CVPR, 2020. arxiv
  2. Bergmann, P., Fauser, M., Sattlegger, D., & Steger, C. MVTec AD — A Comprehensive Real-World Dataset for Unsupervised Anomaly Detection. CVPR, 2019. cvf
  3. Batzner, K., Heckler, L., & König, R. EfficientAD: Accurate Visual Anomaly Detection at Millisecond-Level Latencies. arXiv 2303.14535, 2023. arxiv

Extended by

  • EfficientAD

    EfficientAD keeps the student-teacher principle but replaces the pretrained-backbone ensemble with a single distilled patch description network and loss-induced asymmetry.