Spaces:
Build error
A newer version of the Gradio SDK is available: 6.12.0
title: Anomaly Detection
emoji: 📈
colorFrom: red
colorTo: gray
sdk: gradio
sdk_version: 5.46.1
app_file: app.py
pinned: false
To use EfficientNet in the same way as ResNet-50 + PatchCore, just swap the backbone and pick an appropriate intermediate feature map. The steps are identical:
Backbone Selection & Freezing
– Choose an EfficientNet variant (e.g. B4 or B5) pretrained on ImageNet.
– Remove (or ignore) the final classification head and freeze all weights.Feature-Map Extraction
– Identify a mid-level block whose spatial resolution is neither too coarse nor too fine (e.g. the output of MBConv block 4 or 5).
– Pass each input image through EfficientNet and take that block’s tensor of shape $$[C,H,W]$$.Flatten into Patch Embeddings
– For each spatial location $$(i,j)$$, flatten the $$C$$-dim vector into a patch embedding.
– Collect all embeddings from your normal training images into a large memory bank.Memory Bank & k-NN Detector
– Fit a k-NN model (PatchCore) on the normal patch embeddings.
– At test time, extract patch embeddings from new images and compute the Euclidean (or cosine) distance to nearest neighbors in the memory bank.
– That distance is your anomaly score per patch.Anomaly Map & Segmentation
– Reshape the patch scores into an $$[H,W]$$ map.
– Upsample to the original image resolution (bilinear) and apply a threshold or morphological filtering to segment abnormal regions.
Because EfficientNet’s inverted-bottleneck blocks are more parameter-efficient, you often get similar or better detection accuracy with lower FLOPs than ResNet-50—while the overall PatchCore workflow remains unchanged.