Back to Projects
Industrial Inspection

Fabric Surface Anomaly Detection

Unsupervised anomaly detection for textile inspection using PatchCore embedding with FAISS indexing, achieving 98.9% AUROC.

June 20, 2023 GitHub
Anomaly Detection Unsupervised PyTorch FAISS

Overview

Fabric inspection requires detecting subtle defects โ€” snags, holes, density variations โ€” with no defective samples available during training. This project adapts the PatchCore algorithm for high-resolution textile images.

Method

Patch features are extracted from WideResNet-50 at layers โ„“2\ell_2 and โ„“3\ell_3, then aggregated into a memory bank M\mathcal{M}:

sโˆ—(p)=minโกmโˆˆMโˆฅฯ•(p)โˆ’mโˆฅ2s^*(p) = \min_{m \in \mathcal{M}} \| \phi(p) - m \|_2

The anomaly score for a full image is the maximum patch score:

S=maxโกpโˆˆPsโˆ—(p)S = \max_{p \in P} s^*(p)

Coreset Subsampling

The memory bank is compressed via greedy coreset selection to maintain โˆฃMโˆฃโ‰ค1%|\mathcal{M}| \leq 1\% of the original feature set with < 1% AUROC degradation. This reduces search time with FAISS from 120 ms to < 5 ms.

Results

| Metric | Value | |---|---| | AUROC | 98.9% | | Inference Time | 12 ms/frame | | Training Samples Needed | 200 (normal only) |

Tech Stack

PythonPyTorchFAISSWideResNetOpenCV