SuperSimpleNet#
Architecture#
SuperSimpleNet.
ICPR 2024 - SuperSimpleNet: Unifying Unsupervised and Supervised Learning for Fast and Reliable Surface Defect Detection.
JIMS 2025 - No Label Left Behind: A Unified Surface Defect Detection Model for all Supervision Regimes
This module implements the SuperSimpleNet model for surface defect / anomaly detection. SuperSimpleNet is a simple yet strong discriminative model consisting of a pretrained feature extractor with upscaling, feature adaptor, train-time feature-level synthetic anomaly generation module, and segmentation-detection module.
Using the adapted features, the model predicts an anomaly map via the segmentation head and an anomaly score using the classification head. It delivers strong performance while maintaining fast inference.
Example
>>> from anomalib.data import MVTecAD
>>> from anomalib.models import Supersimplenet
>>> from anomalib.engine import Engine
>>> datamodule = MVTecAD()
>>> model = Supersimplenet()
>>> engine = Engine()
>>> engine.fit(model, datamodule=datamodule)
>>> predictions = engine.predict(model, datamodule=datamodule)
- Paper:
Original: SuperSimpleNet: Unifying Unsupervised and Supervised Learning for Fast and Reliable Surface Defect Detection. URL: https://arxiv.org/pdf/2408.03143
Extension: No label left behind: a unified surface defect detection model for all supervision regimes URL: https://link.springer.com/article/10.1007/s10845-025-02680-8
Notes
This implementation supports both unsupervised and supervised setting, but Anomalib currently supports only unsupervised learning.
See also
anomalib.models.image.supersimplenet.torch_model.SupersimplenetModel:PyTorch implementation of the SuperSimpleNet model.
- class anomalib.models.image.supersimplenet.lightning_model.Supersimplenet(perlin_threshold=0.2, backbone='wide_resnet50_2.tv_in1k', layers=['layer2', 'layer3'], supervised=False, adapt_cls_features=False, pre_processor=True, post_processor=True, evaluator=True, visualizer=True)#
Bases:
AnomalibModulePL Lightning Module for the SuperSimpleNet model.
- Parameters:
perlin_threshold (
float) – threshold value for Perlin noise thresholding during anomaly generation.backbone (
str) – backbone name. IMPORTANT! use only backbones with torchvision V1 weights ending on “.tv”.supervised (
bool) – whether the model will be trained in supervised mode. False by default (unsupervised).adapt_cls_features (
bool) – whether to adapt classification features (ICPR - True, JIMS - False (default)).pre_processor (
PreProcessor|bool) – Pre-processor instance or flag to use default. Defaults toTrue.post_processor (
PostProcessor|bool) – Post-processor instance or flag to use default. Defaults toTrue.evaluator (
Evaluator|bool) – Evaluator instance or flag to use default. Defaults toTrue.visualizer (
Visualizer|bool) – Visualizer instance or flag to use default. Defaults toTrue.
- configure_optimizers()#
Configure AdamW optimizer and MultiStepLR scheduler.
- classmethod configure_pre_processor(image_size=None)#
Configure the default pre-processor for SuperSimpleNet.
Pre-processor resizes images and normalizes using ImageNet statistics.
- property learning_type: LearningType#
Return the learning type of the model.
This is subject to change in the future when support for supervised training is introduced.
- Returns:
Learning type of the model.
- Return type:
LearningType
- training_step(batch, *args, **kwargs)#
Perform the training step input and return the loss.
- validation_step(batch, *args, **kwargs)#
Perform the validation step and return the anomaly map and anomaly score.
PyTorch model for the SuperSimpleNet model implementation.
See also
anomalib.models.image.supersimplenet.lightning_model.Supersimplenet:SuperSimpleNet Lightning model.
- class anomalib.models.image.supersimplenet.torch_model.AnomalyMapGenerator(sigma)#
Bases:
ModuleFinal anomaly map generator, responsible for upscaling and smoothing.
- Parameters:
sigma (
float)
- class anomalib.models.image.supersimplenet.torch_model.FeatureAdapter(channel_dim)#
Bases:
ModuleFeature adapter used to adapt raw features for the task of anomaly detection.
- Parameters:
channel_dim (
int) – channel dimension of features.
- class anomalib.models.image.supersimplenet.torch_model.SegmentationDetectionModule(channel_dim, stop_grad=False)#
Bases:
ModuleSegmentationDetection module responsible for prediction of anomaly map and score.
- Parameters:
- class anomalib.models.image.supersimplenet.torch_model.SupersimplenetModel(perlin_threshold=0.2, backbone='wide_resnet50_2.tv_in1k', layers=['layer2', 'layer3'], stop_grad=True, adapt_cls_features=False)#
Bases:
ModuleSuperSimpleNet Pytorch model.
It consists of feature extractor, feature adaptor, anomaly generation mechanism and segmentation-detection module.
- Parameters:
perlin_threshold (
float) – threshold value for Perlin noise thresholding during anomaly generation.backbone (
str) – backbone name. IMPORTANT! use only backbones with torchvision V1 weights ending on “.tv”.stop_grad (
bool) – whether to stop gradient from class. to seg. head.adapt_cls_features (
bool) – whether to adapt classification features (ICPR - True, JIMS - False (default)).
- static downsample_mask(masks, feat_h, feat_w)#
Downsample the masks according to the feature dimensions.
Primarily used in supervised setting.
- forward(images, masks=None, labels=None)#
SuperSimpleNet forward pass.
Extract and process features, adapt them, generate anomalies (train only) and predict anomaly map and score.
- class anomalib.models.image.supersimplenet.torch_model.UpscalingFeatureExtractor(backbone, layers, patch_size=3)#
Bases:
ModuleFeature extractor module.
- Parameters:
- forward(input_tensor)#
Extract features from input tensor.
- anomalib.models.image.supersimplenet.torch_model.init_weights(module)#
Init weight of the model.
Anomaly generator for the SuperSimplenet model implementation.
- class anomalib.models.image.supersimplenet.anomaly_generator.AnomalyGenerator(noise_mean, noise_std, threshold)#
Bases:
ModuleAnomaly generator for the SuperSimpleNet model.
- Parameters:
- forward(input_features, adapted_features, masks, labels)#
Generate anomaly on features using thresholded perlin noise and Gaussian noise.
Also update GT masks and labels with new anomaly information.
- Parameters:
- Return type:
- Returns:
perturbed features (if not None), perturbed adapted, updated GT masks and labels.
- generate_perlin(batches, height, width)#
Generate 2d perlin noise masks with dims [b, 1, h, w].