wikillm

Paper · 2024-05-23 · cs.CV

Dinomaly: The Less Is More Philosophy in Multi-Class Unsupervised Anomaly Detection

One reconstruction-based anomaly detector for many object classes, built only from Transformer blocks. A frozen DINOv2 ViT-B/14 gives features, a dropout-noised MLP bottleneck and a linear-attention decoder rebuild them, and a loosened cosine loss stops the decoder copying defects. Author-reported image AUROC 99.6 on MVTec-AD, 98.7 on VisA and 89.3 on Real-IAD in the multi-class setting.

Anomaly detectionVision Transformer (ViT) backbonesLinear attentionDropoutanomaly-detectionmulti-class-anomaly-detectionfeature-reconstructionlinear-attention

arXivPDFCodeMarkdown20 min read

AI-compiled by claude-haiku-5-5 on 2026-11-13, not yet reviewed by a human. Every claim cites its source; check it when a detail matters.

In plain words

An anomaly detector learns what normal looks like and flags whatever it cannot explain. One common approach trains a small network to rebuild the normal features of an image. Where the picture looks normal, the rebuild is close. Where a defect appears, the rebuild misses it, and the size of the miss marks the spot.

The problem is that a single model trained on many object types learns to rebuild too much. It also rebuilds defects it has never seen, so the miss that should flag them disappears. Earlier fixes added fake defects, extra modules or tuned tricks.

Dinomaly keeps the design plain. It uses only attention and small feed-forward blocks. It adds dropout inside the bottleneck between encoder and decoder, so the rebuild is noisy and cannot copy everything exactly. The decoder uses a form of attention that spreads its focus across the whole image instead of locking onto one spot. And the training loss is not forced to match every layer point by point: it down-weights the parts that are already rebuilt well and concentrates on the rest.

The authors report that one model for all object classes comes close to, or beats, separate models trained for each class on the common benchmarks. The Results section gives the numbers and the test setup.

TL;DR

  • Dinomaly is a reconstruction-based anomaly detector that uses one model for all object classes and only Transformer blocks: a frozen DINOv2 ViT-B/14 encoder, a dropout-noised MLP bottleneck, an 8-block decoder with linear attention and a loosened cosine loss §3.1 §3.2 §3.3 §3.4.
  • The authors call four pieces essential: the pretrained foundation features, the bottleneck dropout, the linear attention, and the loose reconstruction §1 §5.
  • Author-reported image AUROC is 99.6 (MVTec-AD), 98.7 (VisA) and 89.3 (Real-IAD) in the multi-class setting, and the authors say these beat earlier multi-class methods tab. 1 §4.2.
  • The released code matches the paper's main recipe. It differs in dropout placement, the linear-attention normalizer, the optimizer epsilon and the hard-mining ramp length of the class-separated runs; see Paper vs code.

Problem

Unsupervised anomaly detection trains on normal images only and localises anomalous regions at test time §1. Class-separated methods train one model per object category. That costs storage when there are many categories §1.

A single unified model for all categories (multi-class UAD) is the practical alternative, but the authors report that it lags far behind class-separated models. They attribute this to an "identity mapping" in which the network copies anomalous inputs as well as normal ones, which they describe as over-generalisation across the diverse multi-class normal patterns §1 §3.2.

Earlier methods handled this with pseudo anomalies, hand-made feature noise, or specialised modules, which the authors say limit how general and easy to use those methods are §1 §3.2. The paper assumes that normal and anomalous images share the same objects apart from the defect, which it calls sensory anomaly detection, and it does not address semantic anomaly detection app. A app. G.

Method

Dinomaly is an encoder, a bottleneck and a decoder. The decoder is trained to reproduce the encoder's middle-level features on normal images. At test time it reproduces normal regions well and fails on anomalous ones, and the per-location cosine distance between the two marks the anomaly §3.1.

Encoder

  1. A ViT-Base with patch size 14 and 12 Transformer layers, pretrained by DINOv2 with registers, is the encoder by default §3.1 app. B vit_encoder.py. The paper chose it for the balance of detection and compute §3.1.
  2. The encoder runs only up to block index 9 (0-based), and its eight middle layers, indices 2 to 9, are used. The paper calls these the middle 8 layers §3.1 app. B dinomaly_mvtec_uni.py uad.py.
  3. The encoder receives no gradient in the code. The paper does not state freezing in those words uad.py.

Feature grouping (loose reconstruction)

  1. The eight encoder layers are split into two groups, [2, 3, 4, 5] and [6, 7, 8, 9]. Each group is averaged. The paper describes this as adding the layers of a group together as one target §3.4 app. B dinomaly_mvtec_uni.py uad.py.
  2. The bottleneck input is the average over all eight layers. The paper does not give this operator §3.1 uad.py.

Noisy bottleneck

  1. The bottleneck is one MLP. It has a 4x hidden width (768 to 3072 to 768), a GELU activation, and dropout with rate 0.2 §3.2 app. B dinomaly_mvtec_uni.py. The hidden width is not in the paper text and comes from the code.
  2. Dropout is applied at three points in the MLP: on its input, on the hidden layer and on its output vision_transformer.py vision_transformer.py vision_transformer.py.
Pseudocode
# Noisy bottleneck MLP  [§3.2]  [code: models/vision_transformer.py#L79-L87]
# Input:  fused tokens (B, N, 768); dropout rate 0.2  [app. B]
# Output: tokens (B, N, 768)

def noisy_bottleneck(tokens):
    # 1. Dropout on the input tokens  [code: models/vision_transformer.py#L80]
    tokens = dropout(tokens, rate=0.2)
    # 2. Expand to 4x width with GELU  [code: dinomaly_mvtec_uni.py#L137]
    tokens = gelu(linear(tokens, in_dim=768, out_dim=3072))
    # 3. Dropout on the hidden layer  [code: models/vision_transformer.py#L83]
    tokens = dropout(tokens, rate=0.2)
    # 4. Project back to 768 and apply dropout again
    #    [code: models/vision_transformer.py#L84-L85]
    tokens = dropout(linear(tokens, in_dim=3072, out_dim=768), rate=0.2)
    return tokens

Decoder with linear attention

  1. The decoder has 8 Transformer blocks of width 768, with 12 heads, an MLP ratio of 4 and GELU, qkv bias, and LayerNorm with epsilon 1e-8. Its attention is linear attention, and the decoder has no dropout §3.1 §3.3 app. B dinomaly_mvtec_uni.py dinomaly_mvtec_uni.py.
  2. Linear attention replaces softmax with a positive feature map phi(x) = elu(x) + 1 and multiplies keys with values first, which costs O(N d^2) rather than O(N^2 d). The paper observes that its attention spreads across the whole image instead of concentrating on the query's region, and argues that this reduces the passing of identical information to the next layer §3.3 eq. 3 fig. 3.
  3. The decoder outputs are reversed before grouping, so the first decoder group is made of the last four decoder blocks uad.py uad.py.
Pseudocode
# Unfocused linear attention in one decoder block  [§3.3]  [eq. 3]
# Input:  tokens (B, N, 768); 12 heads of width 64
#         [code: dinomaly_mvtec_uni.py#L127]
# Output: tokens (B, N, 768)

def linear_attention(tokens):
    # 1. Project to queries, keys and values  [§3.3]  [eq. 1]
    queries, keys, values = split_heads(qkv(tokens))    # (B, H, N, D)
    # 2. Positive feature map phi(x) = elu(x) + 1  [§3.3]
    queries = elu(queries) + 1
    keys = elu(keys) + 1
    # 3. Summarise keys and values first  [§3.3]  [eq. 3]
    key_value = transpose(keys) @ values                # (B, H, D, D)
    # 4. Per-query normaliser, absent from Eq. 3
    #    [code: models/vision_transformer.py#L270]
    normaliser = 1 / (queries @ sum_over_tokens(keys))  # (B, H, N)
    out = (queries @ key_value) * normaliser[..., None]
    return output_projection(merge_heads(out))

Loss with loose reconstruction and hard mining

  1. For each encoder-decoder pair, the loss is the cosine distance between the flattened maps, averaged over the pairs §3.4 eq. 4 utils.py utils.py.
  2. Inside each pair, per-location cosine distances are computed without gradient. The decoder's gradient is multiplied by 0.1 at locations whose distance falls below the threshold that keeps the top (1 - p) share of the batch. The fraction p rises linearly from 0 to 0.9 over the first 1000 iterations §3.4 eq. 5 eq. 6 app. B utils.py dinomaly_mvtec_uni.py.
  3. Gradient norms are clipped to 0.1 in the training scripts. The paper does not mention clipping dinomaly_mvtec_uni.py.
Pseudocode
# Global cosine loss with hard mining  [§3.4]  [eq. 4]  [eq. 5]  [eq. 6]
# Input:  encoder_groups, decoder_groups: lists of (B, C, 28, 28) maps
#         p: share of points that keep full gradient, ramped 0 -> 0.9
# Output: scalar loss

def hard_mining_cosine_loss(encoder_groups, decoder_groups, p):
    loss = 0
    for enc, dec in zip(encoder_groups, decoder_groups):
        # 1. Per-location cosine distance, no gradient  [eq. 6]
        point_dist = 1 - cosine(enc.detach(), dec.detach(), dim=1)
        # 2. Threshold: the k-th largest distance in the batch  [app. B]
        k = int(point_dist.numel() * (1 - p))
        thresh = topk(flatten(point_dist), k)[-1]
        # 3. Global cosine distance on the flattened maps  [eq. 4]
        loss += mean(1 - cosine(flatten(enc.detach()), flatten(dec)))
        # 4. Scale the gradient by 0.1 where distance is below thresh
        #    [eq. 5]
        dec.register_hook(scale_gradient_where(point_dist < thresh, 0.1))
    # 5. Average over the encoder-decoder pairs  [eq. 4]
    return loss / len(encoder_groups)

Scoring at test time

  1. For each pair, the per-location cosine distance on the 28 x 28 grid is upsampled to the input size. The pair maps are averaged. The paper states the anomaly map this way, averaged over pairs and groups app. B utils.py.
  2. The code resizes the map to 256 x 256 and smooths it with a 5 x 5 Gaussian kernel with sigma 4. The paper does not describe this step utils.py utils.py.
  3. The image score is the mean of the top 1% of the map's pixels, not the single maximum app. B utils.py.
Pseudocode
# Pixel map and image score at test time  [§4.1]  [app. B]
# Input:  images (B, 3, 392, 392)
# Output: amap (B, 256, 256); image_score (B,)

def anomaly_scores(images, model):
    # 1. Run encoder and decoder, grouped as in training  [§3.4]
    encoder_groups, decoder_groups = model(images)
    maps = []
    for enc, dec in zip(encoder_groups, decoder_groups):
        # 2. Cosine distance per location, upsampled to input size  [§4.1]
        d = 1 - cosine(enc, dec, dim=1)                 # (B, 28, 28)
        maps.append(upsample_bilinear(d, size=392))
    # 3. Average the pairs into one map  [app. B]  [code: utils.py#L222]
    amap = mean(maps)                                   # (B, 392, 392)
    # 4. Resize to 256, then 5x5 Gaussian blur, sigma 4  [code: utils.py#L370]
    amap = gaussian_blur(resize(amap, 256), size=5, sigma=4)
    # 5. Image score: mean of the top 1% of pixels  [app. B]
    image_score = mean(topk(flatten(amap), k=655))      # (B,)
    return amap, image_score

Training recipe

  1. Inputs are resized to 448 x 448 and center-cropped to 392 x 392, which gives a 28 x 28 feature grid. The paper uses the center crop to reduce the influence of background, and notes that it can make anomalies at the image edge unreachable. The code uses no other augmentation §4.1 app. B app. C dataset.py dinomaly_mvtec_uni.py.
  2. Training uses StableAdamW with AMSGrad, learning rate 2e-3, betas (0.9, 0.999) and weight decay 1e-4, with a 100-iteration linear warm-up and cosine decay to 2e-4 §4.1 app. B dinomaly_mvtec_uni.py utils.py.
  3. Iterations: 10 000 for MVTec-AD and VisA, 50 000 for Real-IAD in the multi-class setting, and 5 000 per class in the class-separated setting §4.1 app. B dinomaly_mvtec_uni.py dinomaly_realiad_uni.py dinomaly_mvtec_sep.py.
  4. Seed 1, with deterministic cuDNN app. B dinomaly_mvtec_uni.py.

Hyperparameters

NameValueWhereNotes
EncoderViT-Base/14, 4 register tokens, DINOv2-R weights§3.1 app. B vit_encoder.pyCheckpoint loaded with strict=False vit_encoder.py
Encoder layers usedindices 2 to 9 (0-based), 8 of 12§3.1 app. B dinomaly_mvtec_uni.pyBlocks above index 9 are not run uad.py
Encoder gradientsnoneuad.pyPaper does not state this explicitly
Layer groups[2-5] and [6-9], averaged§3.4 app. B dinomaly_mvtec_uni.pyPaper: "adding up" the layers; code averages
Bottleneck inputmean of all 8 layersuad.py uad.pyPaper gives no operator
Bottleneck MLP768 to 3072 to 768, GELUdinomaly_mvtec_uni.pyHidden width not stated in paper
Bottleneck dropoutrate 0.2; applied 3 times§3.2 app. B vision_transformer.pyPaper describes one MLP dropout
Dropout, Real-IAD (unified)rate 0.4§4.1 app. B dinomaly_realiad_uni.pyClass-separated Real-IAD script uses 0.2
Decoder8 blocks, width 768, 12 heads, MLP ratio 4§3.1 app. B dinomaly_mvtec_uni.pyHeads and MLP ratio are code-only
Decoder attentionlinear attention, elu + 1§3.3 eq. 3 vision_transformer.pyCode normalises each query; Eq. 3 does not
Decoder dropoutnonedinomaly_mvtec_uni.pyAttention drop 0; MLP drop 0 in decoder blocks
Lossglobal cosine on flattened maps, averaged over 2 pairs§3.4 eq. 4 utils.py
Hard-mining fraction plinear from 0 to 0.9 over first 1000 iterations§3.4 app. B dinomaly_mvtec_uni.pyPaper: 500 iterations for class-separated; code: 1000
Gradient factor on easy points0.1§3.4 eq. 5 dinomaly_mvtec_uni.py
Gradient clippingmax norm 0.1dinomaly_mvtec_uni.pyNot in paper
OptimizerStableAdamW, AMSGrad, lr 2e-3, betas (0.9, 0.999), weight decay 1e-4§4.1 app. B dinomaly_mvtec_uni.py
Optimizer epsilon1e-10 (unified); 1e-8 in MVTec, VisA and MPDD class-separatedapp. B dinomaly_mvtec_uni.py dinomaly_mvtec_sep.pyPaper gives 1e-10 only
LR schedulelinear warm-up 100 iterations, cosine to 2e-4app. B dinomaly_mvtec_uni.py
Iterations10k MVTec-AD and VisA; 50k Real-IAD; 5k per class§4.1 app. B dinomaly_mvtec_uni.py
Batch size16dinomaly_mvtec_uni.pyNot stated in paper
Inputresize 448, center crop 392; 28 x 28 grid§4.1 app. B dinomaly_mvtec_uni.py
Augmentationnonedinomaly_mvtec_uni.pyNot stated in paper
Evaluation size256 x 256 for localisation and scoringapp. C dinomaly_mvtec_uni.pyGaussian blur in code only
Image scoremean of top 1% pixelsapp. B utils.py
Seed1app. B dinomaly_mvtec_uni.py
Hardware and softwareRTX 3090 24 GB; PyTorch 1.12.0 with CUDA 11.3app. B requirements.txt

Results

Author-reported. Setup: MVTec-AD has 15 classes, VisA 12 and Real-IAD 30. Training uses 3,629, 8,659 and 36,465 normal images, and testing uses 1,725, 2,162 and 114,585 images respectively §4.1. Metrics are image and pixel AUROC, AP and F1-max, and pixel AUPRO §4.1. Baselines marked with a dagger were designed for multi-class anomaly detection tab. 1. Numbers below are copied from the paper, which takes most baseline values from the ADer benchmark app. B.

Headline image AUROC, with the paper's own rounding §1:

DatasetDinomaly (ViT-B)Dinomaly (ViT-L)Source
MVTec-AD99.699.8tab. 1 tab. 4
VisA98.798.9tab. 1 tab. A3
Real-IAD89.390.1tab. 1 tab. A3

Table 1: multi-class setting, all classes in one model tab. 1 §4.2. Values in percent. Bold and underline marks in the source are dropped.

DatasetMethodI-AUROCI-API-F1P-AUROCP-APP-F1P-AUPRO
MVTec-ADRD4AD94.696.595.296.148.653.891.1
MVTec-ADSimpleNet95.398.495.896.945.949.786.5
MVTec-ADDeSTSeg89.295.591.693.154.350.964.8
MVTec-ADUniAD (†)96.598.896.296.843.449.590.7
MVTec-ADReContrast (†)98.399.497.697.160.261.593.2
MVTec-ADDiAD (†)97.299.096.596.852.655.590.7
MVTec-ADViTAD (†)98.399.497.397.755.358.791.4
MVTec-ADMambaAD (†)98.699.697.897.756.359.293.1
MVTec-ADDinomaly99.699.899.098.469.369.294.8
MVTec-ADDinomaly, longer schedule (20k)99.799.899.298.469.369.294.7
VisARD4AD92.492.489.698.138.042.691.8
VisASimpleNet87.287.081.896.834.737.881.4
VisADeSTSeg88.989.085.296.139.643.467.4
VisAUniAD (†)88.890.885.898.333.739.085.5
VisAReContrast (†)95.596.492.098.547.950.691.9
VisADiAD (†)86.888.385.196.026.133.075.2
VisAViTAD (†)90.591.786.398.236.641.185.1
VisAMambaAD (†)94.394.589.498.539.444.091.0
VisADinomaly98.798.996.298.753.255.794.5
VisADinomaly, longer schedule (20k)98.999.096.498.853.855.894.5
Real-IADRD4AD82.479.073.997.325.032.789.6
Real-IADSimpleNet57.253.461.575.72.86.539.0
Real-IADDeSTSeg82.379.273.294.637.941.740.6
Real-IADUniAD (†)83.080.974.397.321.129.286.7
Real-IADReContrast (†)86.484.277.497.831.638.291.8
Real-IADDiAD (†)75.666.469.988.02.97.158.1
Real-IADViTAD (†)82.780.273.797.224.332.384.8
Real-IADMambaAD (†)86.384.677.098.533.038.790.5
Real-IADDinomaly89.386.880.298.842.847.193.9
Real-IADDinomaly, longer schedule (50k to 100k)89.586.980.498.943.347.494.2

The paper's gray rows use 20 000, 20 000 and 100 000 iterations for the three datasets. The repository contains no script for them tab. 1 dinomaly_mvtec_uni.py.

Table 2: class-separated setting, one model per class tab. 2 §4.3. Values in percent.

MethodMVTec I-AUROCMVTec P-AUROCMVTec P-AUPROVisA I-AUROCVisA P-AUROCVisA P-AUPROReal-IAD I-AUROCReal-IAD P-AUROCReal-IAD P-AUPRO
Dinomaly (multi-class)99.698.494.898.798.794.589.398.893.9
Dinomaly (class-separated)99.799.995.098.998.995.192.099.195.1
RD4AD98.597.893.996.090.170.987.1n/a93.8
PatchCore99.198.193.594.798.591.889.4n/a91.5
SimpleNet99.698.190.097.198.290.788.5n/a84.6

Table 3: ablation on MVTec-AD tab. 3 §4.4. Column flags: NB switches on the dropout bottleneck, LA the linear decoder attention, LC the two-group feature grouping, and LL the hard-mining loss. Values in percent.

NBLALCLLI-AUROCI-API-F1P-AUROCP-APP-F1P-AUPRO
offoffoffoff98.4199.0997.4197.1862.9663.8292.95
onoffoffoff99.0699.5498.3197.6266.2266.7093.71
offonoffoff98.5499.2197.6297.2062.9463.7393.09
offoffonoff98.3599.0497.4397.1061.0562.7392.60
offoffoffon99.0399.4598.1997.6264.1064.9693.34
ononoffoff99.2799.6298.6397.8567.3667.3394.16
onoffonoff99.5099.7298.8798.1468.1668.2494.23
onoffonon99.5299.7398.9298.2068.2568.3494.17
onononoff99.5799.7899.0098.2067.9368.2194.50
onononon99.6099.7899.0498.3569.2969.1794.79

The paper says the loose constraint is not beneficial on its own, because it makes reconstruction too easy without injected noise §4.4. The VisA version of this ablation is Table A4 app. C.

Table 4: encoder size on MVTec-AD tab. 4 §4.4. Im/s is throughput on an RTX 3090 at batch 16, as the paper reports it tab. 4. Values in percent.

EncoderParamsMACsIm/sI-AUROCI-API-F1P-AUROCP-APP-F1P-AUPRO
ViT-Small37.4M26.3G153.699.2699.6798.7298.0768.2967.7894.36
ViT-Base (default)148.0M104.7G58.199.6099.7899.0498.3569.2969.1794.79
ViT-Large275.3M413.5G24.299.7799.9299.4598.5470.5370.0495.09

Table 5: input size on MVTec-AD tab. 5 §4.4. Image-level columns are AUROC / AP / F1-max; pixel-level columns are AUROC / AP / F1-max / AUPRO. Values in percent.

MethodInput sizeImage-levelPixel-level
RD4AD256² (default)94.6 / 96.5 / 96.196.1 / 48.6 / 53.8 / 91.1
RD4AD320²93.2 / 96.9 / 95.695.7 / 55.1 / 57.5 / 91.1
RD4AD384²91.9 / 96.2 / 95.094.9 / 52.1 / 55.3 / 90.8
ReContrast256² (default)98.3 / 99.4 / 97.697.1 / 60.2 / 61.5 / 93.2
ReContrast320²98.2 / 99.2 / 97.596.8 / 61.8 / 62.6 / 93.3
ReContrast384²95.2 / 98.0 / 96.496.5 / 57.7 / 59.5 / 92.6
Dinomaly280²99.6 / 99.8 / 99.398.2 / 65.2 / 66.3 / 93.6
Dinomaly336²99.6 / 99.8 / 99.298.3 / 67.2 / 67.8 / 94.2
Dinomaly392² (default)99.6 / 99.8 / 99.098.4 / 69.3 / 69.2 / 94.8

The paper says that compared methods lose accuracy at larger inputs, while Dinomaly gains on localisation as the input grows §4.4 tab. 5.

Table A3: encoder size on VisA and Real-IAD tab. A3 app. B. Values in percent.

DatasetEncoderI-AUROCI-API-F1P-AUROCP-APP-F1P-AUPRO
VisAViT-Small97.9498.0995.3398.5751.1955.1093.71
VisAViT-Base (default)98.7398.8796.1898.7453.2355.6994.50
VisAViT-Large98.8599.0996.1299.1055.6857.3394.76
Real-IADViT-Small89.1086.9179.8798.6941.8846.7494.08
Real-IADViT-Base (default)89.3386.7780.1798.8442.7947.1093.86
Real-IADViT-Large90.0787.5780.9099.0244.2948.3694.37

Table A5: dropout rate in the noisy bottleneck, MVTec-AD tab. A5 app. C. Default 0.2. Values in percent.

RateI-AUROCI-API-F1P-AUROCP-APP-F1P-AUPRO
0 (none)99.1999.5598.5197.5563.1164.3993.33
0.199.5499.7598.9098.3569.4669.1994.53
0.2 (default)99.6099.7899.0498.3569.2969.1794.79
0.399.6599.8399.1698.3468.4668.8194.63
0.499.6499.8099.2398.2267.9568.3394.57
0.599.5699.8199.1498.1567.4367.8294.64

Table A6: reconstruction constraint, MVTec-AD tab. A6 app. C. Values in percent.

ConstraintI-AUROCI-API-F1P-AUROCP-APP-F1P-AUPRO
Layer to layer, dense (every layer)99.3999.6898.7398.1268.5568.6394.28
Layer to layer, sparse (every 2)99.5299.7398.9598.1668.8968.5794.40
Layer to layer, sparse (every 4)99.5499.7799.0598.0466.6967.1794.07
Layer to concatenated layer (every 2)99.4899.7199.2697.8362.2962.9193.16
Group to group, 1 group99.6499.8099.3698.1864.7965.4093.96
Group to group, 2 groups (default)99.6099.7899.0498.3569.2969.1794.79

Table A7: spatial mixer in the decoder, MVTec-AD tab. A7 app. C. Values in percent.

Spatial mixerI-AUROCI-API-F1P-AUROCP-APP-F1P-AUPRO
Conv block 3x399.4599.6398.6498.0565.3568.0794.17
Conv block 5x599.4199.6298.8697.9966.6467.4794.24
Conv block 7x799.4299.6598.8698.0167.5767.9494.45
Softmax attention99.5299.7398.9298.2068.2568.3494.17
Softmax attention, neighbour mask n=199.5199.7198.9098.1767.8667.9294.27
Softmax attention, neighbour mask n=399.5699.7699.0598.2869.2668.1794.50
Linear attention (default)99.6099.7899.0498.3569.2969.1794.79
Linear attention, neighbour mask n=199.6099.7899.0498.3268.7768.7294.75
Linear attention, neighbour mask n=399.6099.8099.1498.3869.6569.3894.70

Table A12: five random seeds, MVTec-AD tab. A12 app. C. Values in percent.

SeedI-AUROCI-API-F1P-AUROCP-APP-F1P-AUPRO
199.6099.7899.0498.3569.2969.1794.79
299.6399.7999.1298.3368.7368.9194.63
399.6399.7999.1698.3168.7068.9394.60
499.5699.7499.0298.3369.0469.0994.70
599.5999.7799.0298.3268.6468.4794.51
mean ± std99.60 ± 0.0399.77 ± 0.0299.07 ± 0.0698.33 ± 0.0168.88 ± 0.2568.91 ± 0.2494.65 ± 0.09

Other tables are not copied here: the pre-trained backbone comparison (Table A1), the input-size grid (A2), the VisA ablation (A4), the compute comparison (A11), the per-class tables (A14 to A19), and the extra-dataset table (A13). The text reports Dinomaly's I-AUROC on MPDD, BTAD and Uni-Medical as 97.2, 95.4 and 84.9 §4.2 app. D tab. A13. Pre-trained backbones: almost all tested ViT foundations reach image AUROC above 98%, and MAE is the weakest §4.4 tab. A1.

Paper vs code

Official repository: guojiajeremy/Dinomaly, checked at commit 1f252be03a918789b19848f0ca37166e7c28dada. The README links the arXiv paper README.md, and the owner's handle matches the first author's contact address on the paper's title page. The code is Apache-2.0 LICENSE.

  • Hard-mining ramp in class-separated runs. The paper gives 500 iterations for the class-separated setting app. B. All class-separated scripts use 1000: MVTec-AD dinomaly_mvtec_sep.py, VisA dinomaly_visa_sep.py, MPDD dinomaly_mpdd_sep.py and Real-IAD dinomaly_realiad_sep.py. The unified scripts also use 1000 dinomaly_mvtec_uni.py, which matches the paper's unified setting.
  • Optimizer epsilon. The paper gives 1e-10 app. B. The class-separated MVTec-AD, VisA and MPDD scripts use 1e-8 dinomaly_mvtec_sep.py dinomaly_visa_sep.py dinomaly_mpdd_sep.py. The Real-IAD class-separated script uses 1e-10 dinomaly_realiad_sep.py.
  • Dropout placement. The paper describes one dropout inside the MLP §3.2. The code applies it at the input, the hidden layer and the output vision_transformer.py vision_transformer.py vision_transformer.py.
  • Linear attention normalizer. Eq. 3 has no normaliser §3.3 eq. 3. The code divides each query's output by its dot product with the summed keys vision_transformer.py. The paper's note on the omitted constant does not cover this.
  • Grouping operator. The paper says the layers in a group are added §3.4. The code averages them uad.py. Cosine distance is scale-invariant, so the loss and anomaly map are not affected, but the bottleneck input is scaled by one over the group size.
  • Gradient clipping. The code clips the gradient norm to 0.1 dinomaly_mvtec_uni.py. The paper does not mention clipping.
  • Map smoothing. The code blurs the map with a 5 x 5 Gaussian, sigma 4, after resizing to 256 utils.py utils.py. The paper does not mention smoothing.
  • Real-IAD dropout in class-separated runs. The paper raises the rate for Real-IAD, the most varied of its datasets, to 0.4 app. B. The class-separated Real-IAD script uses 0.2 dinomaly_realiad_sep.py.
  • Longer schedules. The gray rows in Table 1 use longer schedules tab. 1. The repository has only the 10k and 50k scripts dinomaly_mvtec_uni.py dinomaly_realiad_uni.py.
  • Checkpoints and evaluation. The scripts evaluate on the test set every 5000 iterations, and checkpoint saving is commented out dinomaly_mvtec_uni.py dinomaly_mvtec_uni.py. The reported numbers therefore cannot be reloaded from the repository, and the final-iteration evaluation is inferred from the loop.
  • Encoder loading. The pretrained weights are loaded with strict=False, so missing or unexpected keys do not raise an error vit_encoder.py.

No other discrepancies found in the architecture, the layer indices, the groups, the loss constants, the learning rate, the warm-up or the iteration counts for the unified runs.

Pitfalls

  • Unstated details filled by code. Bottleneck width (4x), decoder head count (12), batch size (16), Gaussian smoothing, gradient clipping and the StableAdamW clip threshold are not in the paper. The StableAdamW class defaults to a clip threshold of 1.0 and the scripts do not override it StableAdamW.py. An implementer who follows only the paper will get different results.
  • Hard-mining threshold is batch-wide. The threshold is taken over all points of the batch, not per image utils.py. With batch size 16 the threshold depends on which images share a batch.
  • Decoder group indices run backwards. Decoder outputs are reversed before grouping uad.py. Group 0 uses the last four decoder blocks, which pair with the shallow encoder layers. Indexing by decoder position without the reversal swaps the pairs.
  • Paper-internal inconsistencies. Table 5 gives image F1 96.1 for RD4AD at 256², while Table 1 gives 95.2 for the same setting tab. 1 tab. 5. Table 5's 280² row mixes two rows of the appendix input-size grid tab. A2: its image AUROC and AP and its pixel metrics match the 320²-to-280² row, but its image F1 (99.3) matches the 280² row (99.27) instead. Check any number against its own table before using it.
  • Edge anomalies. The paper says the center crop reduces background influence, but it can also make anomalies at the image edge unreachable app. C. Localisation near the border is limited by the crop.
  • Score choice. The image score is the mean of the top 1% of the map, not its maximum, so one bright pixel does not decide the score app. B utils.py. The paper does not say why it chose this.
  • Cost. At 392 x 392 the default ViT-Base needs 104.7 GMACs and runs at 58.1 images per second on an RTX 3090 tab. 4. The paper notes that Vision Transformers are costly and can be a barrier in low-compute settings app. G.
  • Scope. The method targets sensory anomalies, where normal and anomalous images show the same objects with a defect. It is not meant for semantic anomaly detection, where whole classes differ app. A app. G.
  • Variance across seeds. Image AUROC varies by about 0.03 and pixel AP by about 0.25 across five seeds on MVTec-AD tab. A12. Differences smaller than that need several seeds to be meaningful.

Lineage

  • Builds on: feature-reconstruction and distillation anomaly detectors, such as RD4AD (Deng and Li, 2022) and UniAD (arXiv:2206.03687) §2. The paper replaces pseudo-anomaly-based restoration with dropout-based denoising §3.2.
  • Builds on, feature source: DINOv2 with registers, from the paper's own citation (arXiv:2309.16588) §3.1.
  • Builds on, decoder attention: linear attention in the form of Katharopoulos et al. (2020), as the paper cites it §3.3.
  • Builds on, loss: the hard-mining global cosine loss from ReContrast (Guo et al., 2023), which the paper borrows §3.4.
  • Compared against: UniAD (arXiv:2206.03687), ViTAD (arXiv:2312.07495), MambaAD (arXiv:2404.06564), DiAD, SimpleNet, DeSTSeg, ReContrast and RD4AD, with baseline values from the ADer benchmark (arXiv:2406.03262) §4.2 app. B.
  • Superseded by: not stated.

Source and license

Adapted from “Dinomaly: The Less Is More Philosophy in Multi-Class Unsupervised Anomaly Detection” by Jia Guo, Shuai Lu, Weihang Zhang, Fang Chen, Huiqi Li, Hongen Liao (arXiv:2405.14325), used under CC BY 4.0. Changes: condensed and restructured for implementation, with tables, equations and algorithms taken from the paper and its code, each cited to its source. Not affiliated with or endorsed by the authors. Code citations refer to https://github.com/guojiajeremy/Dinomaly at commit 1f252be03a91 (Apache-2.0). Any quoted code is shown under that license.