anomalib-training
Skill8 starsChanged 8 days agoApache-2.0View on GitHub
Trains an anomalib model on a dataset via the Python API or CLI, including training on a custom folder-structured dataset with the Folder datamodule. Use when writing or debugging an anomalib training script/command, choosing Engine/Trainer arguments, or wiring a model + datamodule together. Do not use for adding a new model or datamodule from scratch (see anomalib-adding-a-model / anomalib-adding-a-datamodule), or for the tiled-ensemble or benchmarking pipelines (see anomalib-tiled-ensemble / anomalib-benchmarking).
1 other project uses a version of this.
Adopted by
Most recently taken up by
- open-edge-platform/anomalibword for word, first seen Oct 8, 2026
Other versions1 project uses a version of this.
Word for word · 1
- open-edge-platform/anomalib★ 6.4k100% same
Edited · 0
None found.
Wrote their own version · 0
None found.
How matches are found. Word for word: the exact same text. Edited: shares passages with this file (“99% same” means 99% of its five-word phrases also appear here; 10% or more counts). Their own version: similar meaning, or, weakest, the same name. We can’t tell which project had it first. Projects are counted among the 200 most-starred candidates, and mentions are links to the repository we found, up to 50 per site, so both counts are a floor.
In this repository38 other files it gives its agents.
- anomalib-adding-a-datamoduleSkill
- anomalib-adding-a-modelSkill
- anomalib-benchmarkingSkill
- anomalib-tiled-ensembleSkill
- chatqna-docker-deploySkill
- chatqna-helm-deploySkill
- dlsps-userSkill
- dlstreamer-coding-agentSkill
- getitune-discovering-modelsSkill
- getitune-exporting-a-modelSkill
- getitune-optimizing-a-modelSkill
- getitune-preparing-datasetsSkill
- getitune-running-inferenceSkill
- getitune-training-a-modelSkill
- geti-using-the-pipelineSkill
- manufacturing-ai-app-builderSkill
- manufacturing-app-recipeSkill
- metro-ai-app-builderSkill
- metro-ai-app-recipeSkill
- model-download-userSkill
- multimodal-dataprep-userSkill
- multimodal-embedding-serving-userSkill
- openedge-cliSkill
- pai-benchmark-policySkill
- pai-configure-inferenceSkill
- pai-export-policySkill
- pai-load-policySkill
- pai-run-policySkill
- pai-train-policySkill
- pai-work-with-datasetsSkill
- scenescape-setupSkill
- time-series-analytics-userSkill
- uav-mission-compute-sdkSkill
- vss-deploy-helmSkill
- vss-deploySkill
- vss-search-indexSkill
- vss-summarize-videoSkill
- skill-nameSkill
The file
We split this skill into the rules it gives an agent
4 rules. About 0 are common, 0 are distinctive, and 4 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈0
Distinctive · estimate
This author's own choices. Worth a look.
4
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Very specific: line 36
If model/datamodule are omitted from test/predict, the engine reuses the ones passed to fit.
- Very specific: line 40
Use Folder whenever your data is laid out as root/normal_dir/*, root/abnormal_dir/*, and optionally root/mask_dir/* (segmentation masks) — …
- Very specific: line 63
If you only have normal training images and unlabeled/normal-only test images, omit abnormal_dir and mask_dir — Folder will still produce a …
- Very specific: line 105
Not every model trains via gradient descent — training-free models (e.g.
≈ “Common” is an estimate: at least 1 in 5 of the 350,495 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
Training a Model on a Dataset
Training in anomalib always goes through anomalib.engine.Engine, which wraps a Lightning Trainer.
Python API — standard benchmark dataset (MVTecAD)
from anomalib.data import MVTecAD
from anomalib.models import Patchcore
from anomalib.engine import Engine
datamodule = MVTecAD(root="./datasets/MVTecAD", category="bottle", train_batch_size=32)
model = Patchcore()
engine = Engine() # any Lightning Trainer kwarg can go here
engine.fit(model=model, datamodule=datamodule)
results = engine.test(model=model, datamodule=datamodule)Engine(**kwargs) forwards unknown kwargs straight to the underlying Lightning Trainer
(accelerator, devices, strategy, max_epochs, logger, callbacks, enable_checkpointing,
val_check_interval, barebones, ...) — there is no separate "Trainer config object" to build.
Key Engine methods: fit(model, datamodule=...), train(...) (fit + test in one call),
test(model=None, datamodule=...), predict(model=None, datamodule=..., dataset=..., data_path=...).
If model/datamodule are omitted from test/predict, the engine reuses the ones passed to fit.
Python API — custom data with the Folder datamodule
Use Folder whenever your data is laid out as root/normal_dir/*, root/abnormal_dir/*, and
optionally root/mask_dir/* (segmentation masks) — no new dataset code needed:
from anomalib.data import Folder
from anomalib.models import Padim
from anomalib.engine import Engine
datamodule = Folder(
name="custom", # required — used as the datamodule's display name
root="./datasets/custom",
normal_dir="good", # required
abnormal_dir="defect", # optional: enables anomalous test/eval samples
mask_dir="mask", # optional: enables pixel-level (segmentation) evaluation
train_batch_size=32,
eval_batch_size=32,
num_workers=8,
)
model = Padim()
engine = Engine()
engine.fit(model=model, datamodule=datamodule)If you only have normal training images and unlabeled/normal-only test images, omit abnormal_dir
and mask_dir — Folder will still produce a valid train/test split via test_split_ratio (fraction
of normal training images held out for testing). Use normal_test_dir if you have a separate directory
of normal images specifically for the test set.
CLI
# Standard dataset, defaults
anomalib train --model Patchcore --data anomalib.data.MVTecAD
# Override a datamodule field
anomalib train --model Patchcore --data anomalib.data.MVTecAD --data.category transistor
# Override a trainer field (use a gradient-trained model like Stfpm where max_epochs is meaningful)
anomalib train --model anomalib.models.Stfpm --data anomalib.data.MVTecAD --trainer.max_epochs 3
# Custom Folder dataset from the CLI
anomalib train --model Padim --data anomalib.data.Folder \
--data.name custom --data.root ./datasets/custom \
--data.normal_dir good --data.abnormal_dir defect
# From a config file (jsonargparse; combine with any of the above overrides)
anomalib train --config path/to/config.yamlCLI wiring lives in src/anomalib/cli/cli.py (AnomalibCLI); model/data classes are exposed as
jsonargparse subclass arguments, so --model/--data accept either a short name (Padim) or a full
class path (anomalib.models.Padim, anomalib.data.Folder).
Choosing accelerator / devices
Pass standard Lightning kwargs to Engine(...): accelerator="gpu"|"cpu"|"xpu", devices=1. For
Intel XPU specifically, use SingleXPUStrategy/XPUAccelerator from anomalib.engine:
from anomalib.engine import Engine, SingleXPUStrategy, XPUAccelerator
engine = Engine(strategy=SingleXPUStrategy(), accelerator=XPUAccelerator())Gotchas
- Not every model trains via gradient descent — training-free models (e.g. Padim, Patchcore) still go through
engine.fit(...);Engine/Trainerhandles the single "epoch" needed to build their memory bank. You don't need special-case code for this. Note that these models overridemax_epochsvia theirtrainer_argumentsproperty (e.g.max_epochs=1), so anymax_epochsyou pass toEnginewill be overwritten for such models. Folder'smask_diris what switches evaluation from image-level (classification) to pixel-level (segmentation) metrics — only pass it if you actually have per-pixel ground-truth masks.- Results (checkpoints, logs, images) are written under
Engine'sdefault_root_dir("results"by default), nested by model/datamodule/category — check there first when debugging a run.
Reviewer / self-check
Engine(...)receives Trainer overrides as plain kwargs, not a hand-builtTrainerobject.- Folder-dataset training specifies
normal_dirand, if applicable,abnormal_dir/mask_dirmatching the actual on-disk layout. - CLI invocations use
anomalib.data.<Class>/anomalib.models.<Class>paths that are actually exported (seeanomalib-adding-a-model/anomalib-adding-a-datamodulefor how exports work).
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

