anomalib-adding-a-model
Installation
SKILL.md
Adding a New Model
Models live under src/anomalib/models/image/<model_name>/ (or .../video/<model_name>/ for video models).
Every model is a LightningModule subclass of AnomalibModule
(src/anomalib/models/components/base/anomalib_module.py) that wraps a plain torch.nn.Module.
Reference implementation
Read src/anomalib/models/image/padim/ first — it is the smallest complete example:
torch_model.py—PadimModel(nn.Module): pure PyTorch forward pass. In training mode it returns intermediate embeddings; in eval mode it returns anInferenceBatch(pred_score=..., anomaly_map=...).anomaly_map.py—AnomalyMapGenerator(nn.Module): post-processing (score/map computation) kept out oftorch_model.pyfor clarity. Not all models need a separate file for this.lightning_model.py—Padim(MemoryBankMixin, AnomalibModule): the Lightning-facing wrapper. This is the class users construct (Padim()), pass toEngine, and reference from CLI/config asanomalib.models.Padim.__init__.py— exports the Lightning class only:from .lightning_model import Padim.README.md— usage + benchmark notes (seemodel-doc-sync/model-sample-image-exportskills for docs work).