EfficientAD | VitaVision
Back to atlas

EfficientAD

9 min readAdvancedhybrid8M (EfficientAD-S) / 21M (EfficientAD-M)76 GFLOPs (S) / 235 GFLOPs (M) @ 256×256View in graphIn narrative: Foundation Models for Vision
Based on
EfficientAD: Accurate Visual Anomaly Detection at Millisecond-Level Latencies
Batzner, Heckler, König · WACV 2024 (arXiv 2023) 2023
arXiv ↗

Implementations

Motivation

Detect and localize anomalies in industrial images from normal-only training data, covering both structural defects (scratches, stains, foreign objects) and logical anomalies (wrong count, wrong position, wrong combination of otherwise-normal parts), at millisecond-level per-image latency. Input: an RGB image resized to 256×256256\times256. Output: a per-pixel anomaly map MRW×HM \in \mathbb{R}^{W \times H}, bilinearly resized to the input's original resolution, plus a single image-level score mimage=maxi,jMi,jm_{image} = \max_{i,j} M_{i,j}. The defining property is a two-branch design — a lightweight, loss-induced-asymmetric student-teacher branch for structural anomalies and an autoencoder-distillation branch for logical anomalies — combined into one map and run end to end at 2.2 ms (EfficientAD-S) or 4.5 ms (EfficientAD-M) per image on an RTX A6000.

Architecture

Family & shape. Two parallel fully-convolutional branches over the same 256×256256\times256 input, both built from small CNNs rather than one shared backbone. The local branch is a patch description network (PDN) pair — a frozen teacher and a trainable student sharing one architecture. The global branch is a convolutional autoencoder. Both branches emit dense per-pixel output in the same 384-channel feature space, computed in a single forward pass over the whole image with no cropping or striding.

Blocks.

  • Patch description network (PDN). A compact CNN with a deliberately small receptive field: 33×33 pixels per output location. EfficientAD-S uses 4 conv layers plus 2 strided-average-pool layers; EfficientAD-M uses 6 conv layers, 2 strided-average-pool layers, and two extra 1×1 convs. The teacher is frozen and trained once, by distilling features from a pretrained WideResNet-101 classifier — the same feature space PatchCore uses — and outputs 384 channels. The student shares the teacher's architecture exactly but outputs 768 channels: 384 for the local student-teacher head, 384 for a second head that predicts the autoencoder's output (below). The receptive field is kept small on purpose: it keeps the branch fast and confines it to local, structural deviations, leaving compositional and long-range structure to the autoencoder branch.

  • Loss-induced student-teacher asymmetry. The student and teacher share the identical PDN architecture. The asymmetry that keeps the student from reproducing the teacher on anomalous input at test time comes entirely from the training loss, not from any structural difference between the two networks.

Definition
Hard feature loss

Restricts the student's regression loss to the hardest per-channel, per-pixel discrepancies, analogous to Online Hard Example Mining.

Dc,w,h=(T(I)c,w,hS(I)c,w,h)2,Lhard=mean of Dc,w,hdhard,D_{c,w,h} = (T(I)_{c,w,h} - S(I)_{c,w,h})^2, \qquad L_{hard} = \text{mean of } D_{c,w,h} \ge d_{hard},

where dhardd_{hard} is the phardp_{hard}-quantile of DD. phard=0.999p_{hard} = 0.999, corresponding to using, on average, ten percent of the values.

The hard feature loss in PyTorch:

import torch


def hard_feature_loss(teacher_out: torch.Tensor,
                       student_out: torch.Tensor,
                       p_hard: float = 0.999) -> torch.Tensor:
    """Hard feature loss (Sec. 3.2). Restricts the student's regression
    loss to the p_hard-quantile hardest per-channel, per-pixel elements.
    teacher_out, student_out: [C, H, W] feature maps for one image.
    """
    d = (teacher_out - student_out) ** 2      # D_{c,w,h}
    d_hard = torch.quantile(d, p_hard)        # d_hard
    return d[d >= d_hard].mean()              # L_hard

A separate pretraining penalty adds a term on a random ImageNet image PP at each training step, penalizing the norm of the student's output on that out-of-distribution input: LST=Lhard+(CWH)1cS(P)cF2L_{ST} = L_{hard} + (CWH)^{-1}\sum_c \|S(P)_c\|_F^2. The local anomaly map at inference is the channel-averaged discrepancy, Mw,h=C1cDc,w,hM_{w,h} = C^{-1}\sum_c D_{c,w,h}.

  • Autoencoder branch. A standard convolutional autoencoder — strided convolutions in the encoder, bilinear upsampling in the decoder — not a U-Net; its layer table has no skip connections. A 6-layer strided-conv encoder compresses the image to a 64-dimensional bottleneck; a 6-stage bilinear-upsample-and-conv decoder (dropout 0.2 per stage) reconstructs not the image but the teacher's 384-channel feature output: LAE=(CWH)1cT(I)cA(I)cF2L_{AE} = (CWH)^{-1}\sum_c \|T(I)_c - A(I)_c\|_F^2. Because the 64-dimensional bottleneck cannot carry fine texture, the autoencoder's reconstructions are flawed on normal images too — using the raw autoencoder-versus-teacher residual directly would false-positive on ordinary background texture.

  • Second student head. Instead of scoring the raw autoencoder residual, the student's second output head is trained to predict the autoencoder's output (LSTAEL_{STAE}). The student learns the autoencoder's systematic reconstruction errors on normal images, which cancel out at inference, but does not generalize that prediction to images with unseen logical anomalies. The global anomaly map MAEM^{AE} is the squared difference between the autoencoder's output and this second student head.

Training. Trained per scenario on MVTec AD, VisA, or MVTec LOCO, using only normal images for training and (for map normalization only) validation. Total loss is the unweighted sum Ltotal=LAE+LST+LSTAEL_{total} = L_{AE} + L_{ST} + L_{STAE}. Adam, learning rate 10410^{-4}, weight decay 10510^{-5}, batch size 1, 70000 iterations, learning rate decayed to 10510^{-5} after iteration 66500; the PDN teacher is distilled separately beforehand — 60000 iterations, batch size 16, Adam with the same learning rate and weight decay. Brightness/contrast/saturation augmentation (λU(0.8,1.2)\lambda \sim U(0.8, 1.2)) is applied only to the autoencoder branch's input. Both anomaly maps are normalized before combination:

Definition
Combined anomaly map

Each map is linearly rescaled per scenario using two quantiles of its own score distribution on held-out normal validation images (qa=0.90q_a = 0.9 \to 0, qb=0.9950.1q_b = 0.995 \to 0.1), then the two normalized maps are averaged in equal parts.

M=0.5M^ST+0.5M^AE.M = 0.5\,\hat M^{ST} + 0.5\,\hat M^{AE}.

Under the paper's clean evaluation protocol (early stopping disabled), MVTec AD AU-ROC is 98.8 % for EfficientAD-S and 99.1 % for EfficientAD-M (Table 2). A separately reported early-stopped figure of 99.8 % on MVTec AD uses the same test-time early-stopping protocol the paper disqualifies when scoring its SimpleNet baseline, and is not comparable to the clean-protocol numbers above.

Complexity. EfficientAD-S: 8M parameters, 76 GFLOPs, 100 MB GPU memory, 2.2 ms latency and 614 img/s throughput (batch 16) on an RTX A6000. EfficientAD-M: 21M parameters, 235 GFLOPs, 161 MB GPU memory, 4.5 ms latency and 269 img/s throughput (batch 16), same hardware (Table 1, Table 16).

Implementations

No official open-source implementation accompanies this paper, unlike its baselines, whose repositories are linked from Appendix B.

Assessment

Novelty.

  • Loss-induced, not architectural, student-teacher asymmetry: student and teacher share one PDN architecture, and the hard feature loss plus pretraining penalty alone keep the student from generalizing to anomalies. This directly disagrees with AST (Rudolph et al. 2023), which argues architectural asymmetry — a bijective normalizing-flow teacher paired with a non-bijective CNN student — is required, stating that "a student with similar architecture tends to undesired generalization, such that it extrapolates similar outputs as the teacher for inputs that are out of the training distribution."
  • Two-branch design covering both anomaly classes in one model: extends the plain student-teacher framework of Uninformed Students (Bergmann et al. 2020) with a second, autoencoder-based branch — in the spirit of MVTec LOCO's GCAD baseline — that targets the logical and compositional anomalies the local branch's 33×33 receptive field cannot see.
  • Hard feature loss, analogized to Online Hard Example Mining: restricting the student's loss to the phard=0.999p_{hard}=0.999-quantile hardest elements moves MVTec AD AU-ROC from 94.9 (no mining) to 96.0 — an ablated design choice, not an incidental detail (Table 3).
  • Quantile-based anomaly-map normalization outperforms a Gaussian mean/variance baseline by 0.7 AU-ROC points (95.4 → 94.7 without it), by being distribution-free across scenarios whose raw score distributions differ in shape (Table 5).

Strengths.

  • Millisecond latency: 2.2 ms (EfficientAD-S) and 4.5 ms (EfficientAD-M) per image on an RTX A6000; 614 and 269 img/s throughput at batch 16 (Table 1).
  • Leads its own clean-protocol comparison table across MVTec AD, VisA, and MVTec LOCO, ahead of GCAD, SimpleNet, S-T, FastFlow, DSR, PatchCore, and AST under the same evaluation protocol (Table 1, Table 2).
  • Per the paper's own conclusion, EfficientAD-S reduces latency by a factor of 24 and increases throughput by a factor of 15 relative to AST — "the second-best method" — though AST reports no comparable end-to-end throughput figure of its own to independently verify this against.
  • More robust to the choice of distillation backbone than PatchCore is to its own feature extractor, on MVTec LOCO specifically (Table 9): EfficientAD-M varies 88.3–90.7 AU-ROC across WideResNet-101/ResNeXt-101/DenseNet-201, versus PatchCore's 76.5–80.3 over the same three backbones.
  • Robust to float16 inference precision — detection results are unchanged across all 32 evaluated scenarios (Appendix E); the reported latency figures use float16.

Limitations.

  • Requires training per scenario (about twenty minutes, §5) — in contrast to kNN-based methods, which require no training pass at all.
  • Compared with PatchCore: see When to choose PatchCore over EfficientAD. The PatchCore page hosts the comparison.
  • Logical anomalies remain the method's weakest slice even while leading the field: 85.8 / 86.8 AU-ROC on MVTec LOCO's logical-anomaly split (EfficientAD-S/M), against 98.8 / 99.1 on MVTec AD's largely-structural anomalies (Table 2).
  • Fine-grained logical anomalies below the branches' resolving power — the paper's own example is "a screw that is two millimeters too long" — are out of scope; the paper directs practitioners to metrology methods instead (§5).

References

  1. Batzner, K., Heckler, L., & König, R. EfficientAD: Accurate Visual Anomaly Detection at Millisecond-Level Latencies. arXiv 2303.14535, 2023. arxiv
  2. Bergmann, P., Fauser, M., Sattlegger, D., & Steger, C. Uninformed Students: Student-Teacher Anomaly Detection With Discriminative Latent Embeddings. CVPR, 2020. arxiv
  3. Rudolph, M., Wehrbein, T., Rosenhahn, B., & Wandt, B. Asymmetric Student-Teacher Networks for Industrial Anomaly Detection. WACV, 2023. arxiv
  4. Bergmann, P., Batzner, K., Fauser, M., Sattlegger, D., & Steger, C. Beyond Dents and Scratches: Logical Constraints in Unsupervised Anomaly Detection and Localization. IJCV, 2022. pdf

Extends

  • Uninformed Students

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

Compared with

  • PatchCore

    Peer choice, not supersession — EfficientAD leads on accuracy and latency, but PatchCore requires no per-scenario training.

Fed by

  • medium
    ResNet

    EfficientAD distils its patch description network from a WideResNet-101 teacher; the wide variant is not this page's subject, hence medium confidence.