PaDiM, short for Patch Distribution Modeling, is a visual anomaly detection method that describes every image position with a multivariate Gaussian distribution of pretrained CNN features learned from normal images only, then flags patches whose features lie far from that distribution. In anomaly detection for industrial inspection, PaDiM provides both an image-level anomaly score and a pixel-level anomaly map that localizes defects.
The method was published by Defard and colleagues in 2020 and quickly became a standard baseline on the MVTec AD benchmark. It requires no neural network training: a frozen backbone extracts features, and only simple statistics are estimated, which makes PaDiM fast to set up on small sets of defect-free samples.
How PaDiM models normal image patches
PaDiM works in three stages: feature extraction, per-position distribution fitting and distance-based scoring. Each training image passes through a convolutional network pretrained on ImageNet, such as ResNet-18 or Wide ResNet-50-2. Feature maps from the first three stages are resized to a common resolution and concatenated into one embedding vector for every spatial position.
For each position across all normal training images, PaDiM estimates a mean vector and a covariance matrix. A small regularization term, typically 0.01 times the identity matrix, is added so the covariance stays invertible. The result is a grid of Gaussians, one per patch location, that captures what normal texture and structure look like at that place in the image.
The table below lists the stages of the pipeline and what each one produces.
| Stage | Operation | Output |
|---|---|---|
| Feature extraction | Frozen CNN, layers 1 to 3 | Multi-scale patch embeddings |
| Dimension reduction | Random selection of channels | Smaller embeddings |
| Distribution fitting | Mean and covariance per position | Grid of Gaussian models |
| Scoring | Mahalanobis distance per patch | Raw anomaly map |
| Post-processing | Upsampling and Gaussian smoothing | Final heat map and image score |
Scoring with the Mahalanobis distance
At test time, PaDiM computes the Mahalanobis distance between each patch embedding and the Gaussian fitted for that position. Unlike Euclidean distance, it accounts for correlations between feature channels, so deviations along rarely varying directions weigh more heavily. The distance map is upsampled to the input resolution and smoothed, typically with a Gaussian filter of sigma about 4 pixels.
The image-level score is usually the maximum value of the anomaly map. A threshold on this score separates normal from defective parts, while a threshold on the map itself produces a segmentation mask of the defect region.
Key parameters and their typical values are summarized below.
| Parameter | Typical value | Effect |
|---|---|---|
| Backbone | ResNet-18 or Wide ResNet-50-2 | Feature quality and speed |
| Reduced dimension | 100 for ResNet-18, 550 for Wide ResNet-50-2 | Accuracy versus memory |
| Input size | 256 pixels resized, 224 center crop | Spatial detail of the map |
| Covariance regularization | 0.01 times identity | Numerical stability |
| Smoothing sigma | About 4 pixels | Noise in the heat map |
The original study found that random channel selection performs almost as well as principal component analysis for dimension reduction, while being cheaper. This result surprised many readers and reflects how redundant pretrained features are for this task.
PaDiM compared with related methods
PaDiM belongs to the family of embedding-based visual anomaly detection methods, which rely on pretrained features instead of reconstruction. Its main distinction is the position-specific parametric model, while neighbors such as PatchCore use a non-parametric memory bank.
| Method | Model of normality | Main strength | Main weakness |
|---|---|---|---|
| PaDiM | One Gaussian per patch position | Simple, fast inference | Needs aligned images |
| PatchCore | Memory bank of patch features | Higher accuracy, position-free | Nearest-neighbor search cost |
| SPADE | k-NN over stored features | No distribution assumption | Slow at large scale |
| Autoencoder detection | Reconstruction of normal images | Learns domain-specific features | Reconstructs some defects too well |
| Deep SVDD | Hypersphere around normal embeddings | Compact model | Training can collapse |
On the MVTec AD benchmark, PaDiM reported about 95 percent image-level AUROC and above 97 percent pixel-level AUROC with a Wide ResNet backbone. Later methods such as PatchCore reached higher scores, but PaDiM remains a strong, interpretable baseline.
When to use PaDiM in practice
PaDiM fits inspection tasks where images are well aligned and only normal samples are easy to collect. Typical settings include fixed-camera production lines that inspect printed circuit boards, bottles, metal parts, textiles or packaging. It is implemented in open-source libraries such as Anomalib, which simplifies deployment.
| Situation | Suitability | Reason |
|---|---|---|
| Fixed camera, aligned parts | Well suited | Position-specific statistics hold |
| Uniform textures such as fabric | Well suited | Patterns repeat across positions |
| Objects in random orientations | Poorly suited | Positions no longer correspond |
| Very limited memory on edge devices | Use with a small backbone | Covariance storage grows quickly |
| Highest possible accuracy required | Consider PatchCore | Usually ranks higher on benchmarks |
A few dozen to a few hundred defect-free training images are usually enough. The decision threshold should be chosen on a validation set that contains at least some real defects, because the anomaly score has no absolute meaning.
Limitations and common pitfalls
PaDiM trades flexibility for simplicity, and several weaknesses follow directly from its per-position Gaussian assumption.
- Memory grows with resolution and embedding size, because each position stores a full covariance matrix.
- Misaligned or rotated objects produce false alarms, since features shift to other positions.
- Multimodal normal appearance, such as product variants, fits poorly into a single Gaussian.
- ImageNet features may miss subtle defects in unusual domains such as X-ray or thermal images.
- Uncalibrated thresholds lead to unstable false positive rates when lighting changes.
Careful image registration, stable lighting and periodic refitting on fresh normal samples address most of these issues in production.
The simple explanation
PaDiM learns what a good product looks like, spot by spot. It studies many photos of flawless parts. For each small area of the picture, it remembers the typical look and how much it normally varies.
When a new part arrives, it checks every small area against that memory. Areas that look far more unusual than normal light up on a heat map. The brighter the spot, the more likely a scratch, dent or stain is there.
How it is used in practice
A factory that produces machined aluminum housings inspects every part with a fixed overhead camera. Defects are rare, so collecting labeled defect images is difficult. The quality team gathers about 300 images of approved parts and fits PaDiM with a Wide ResNet-50-2 backbone.
Fitting takes only minutes on a single GPU, because the network is not trained. On a validation set with real scratches and dents, the team sets a threshold that catches nearly all visible defects while flagging only a small share of good parts for manual review.
In operation, the heat map shows inspectors exactly where each suspected defect lies, which shortens manual checks. When a new housing variant enters production, the team simply refits the model on fresh normal images.