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.pyPadimModel(nn.Module): pure PyTorch forward pass. In training mode it returns intermediate embeddings; in eval mode it returns an InferenceBatch(pred_score=..., anomaly_map=...).
  • anomaly_map.pyAnomalyMapGenerator(nn.Module): post-processing (score/map computation) kept out of torch_model.py for clarity. Not all models need a separate file for this.
  • lightning_model.pyPadim(MemoryBankMixin, AnomalibModule): the Lightning-facing wrapper. This is the class users construct (Padim()), pass to Engine, and reference from CLI/config as anomalib.models.Padim.
  • __init__.py — exports the Lightning class only: from .lightning_model import Padim.
  • README.md — usage + benchmark notes (see model-doc-sync/model-sample-image-export skills for docs work).
Installs
1
GitHub Stars
2
First Seen
5 days ago
anomalib-adding-a-model — open-edge-platform/skills