deployment-and-inference
Export trained anomalib models and run runtime inference with Engine.predict, export helpers, TorchInferencer, and OpenVINOInferencer.
- License 许可
- Apache-2.0
- 最近更新
- 2026-10-08
- Stars
- ★ 11
- Forks
- 3
01 前言 Front Matter
- name
- deployment-and-inference
- license
- Apache 2.0
- metadata
- { "disco-role": "operating" }
- description
- Export trained anomalib models and run runtime inference with Engine.predict, export helpers, TorchInferencer, and OpenVINOInferencer.
- disable-model-invocation
- true
02 资源文件 3
- 参考文档references/api-reference.md2.9 KB
- 参考文档references/deployment-and-inference.md3.6 KB
- 参考文档references/troubleshooting.md2.9 KB
03 SKILL.md 正文
Deployment and Inference
Use this skill when a trained anomalib model must be turned into a runtime artifact or run at inference time. It covers the path from checkpoint or trained model to export, runtime loading, and prediction.
What this skill covers
Engine.predict(...)for dataset, datamodule,data_path, or explicit dataloaders.Engine.export(...)and the underlyingExportMixinhelpers.TorchInferencerfor trusted Torch checkpoints.OpenVINOInferencerfor OpenVINO IR or ONNX artifacts.- Export and runtime troubleshooting for optional dependencies and trust gates.
What this skill excludes
- Training loop internals, fit/test/validate logic, and callback design.
- Benchmark or pipeline orchestration.
- Studio application files and UI implementation details.
Quick chooser
| Need | Use | Notes |
|---|---|---|
| Predict from a trained model inside Lightning | Engine.predict(...) |
Best default when you already have an AnomalibModule. |
| Export to Torch / ONNX / OpenVINO | Engine.export(...) or ExportMixin |
INT8_PTQ and INT8_ACQ need a datamodule. |
| Load a trusted Torch checkpoint directly | TorchInferencer |
Legacy, pickle-based, and gated by TRUST_REMOTE_CODE. |
| Load an OpenVINO or ONNX deployment artifact | OpenVINOInferencer |
Default device is AUTO; config is optional. |
Primary workflow
- Start from a trained
AnomalibModuleor a trusted exported checkpoint. - Decide whether you need:
- Lightning-managed prediction (
Engine.predict) - an export artifact (
Engine.export/ExportMixin) - direct runtime inference (
TorchInferencerorOpenVINOInferencer)
- Lightning-managed prediction (
- Pick the export format:
torchfor a pickled model objectonnxfor interchange or downstream conversionopenvinofor optimized deployment
- For ONNX dynamo export,
onnxscriptmust be installed. For OpenVINO INT8 export,nncfmust be installed. - For OpenVINO quantization:
- use
FP16orINT8when you do not have a datamodule - use
INT8_PTQorINT8_ACQonly with a datamodule - use
INT8_ACQwith a metric when you need custom quality control
- use
- Treat Torch checkpoints as trusted code only. If the source is not trusted, do not bypass the gate; prefer ONNX or OpenVINO instead.
- Use the bundled scripts for tiny deterministic smoke runs.
Bundled references
Bundled scripts
scripts/basic-inference-api.py— minimal PythonEngine.predictexample.scripts/basic-openvino-inference.py— minimal OpenVINO API recipe.scripts/lightning-inference.py— CLI-styleEngine.predicthelper.scripts/openvino-inference.py— OpenVINO image inference helper.scripts/torch-inference.py— legacy Torch inference helper with trust warning.
Notes for future agents
- Prefer
Engine.predictoverTorchInferencerfor new work. TorchInferencerloads pickled checkpoints and requiresTRUST_REMOTE_CODE=1.OpenVINOInferenceraccepts.xml,.bin, or.onnxpaths and may createopenvino_cache/in the current working directory.- The repo's
basic_torch_inference.pyexample is only a header stub in this checkout; do not depend on it. tools/inference/gradio_inference.pyis reference-only because it launches a server and depends on optional UI packages.
Minimal success checks
- Exported Torch artifact ends in
weights/torch/model.pt. - Exported ONNX artifact ends in
weights/onnx/model.onnx. - Exported OpenVINO artifact ends in
weights/openvino/model.xmlwith a sibling.bin. Engine.predictcan be driven bydataset,datamodule, ordata_path.- OpenVINO INT8 export is rejected until a datamodule is provided.
- Torch checkpoint loading is rejected until the trust gate is explicitly opened for a trusted file.
04 同仓库更多 Skills
obsidian-clipper-template-creator
Guide for creating templates for the Obsidian Web Clipper. Use when you want to create a new clipping template, understand available variables, or format clipped content.
obsidian-clipper-template-creator
Guide for creating templates for the Obsidian Web Clipper. Use when you want to create a new clipping template, understand available variables, or format clipped content.
python-api
Programmatic Object-Detection-Metrics API guidance for BoundingBox, BoundingBoxes, Evaluator, enums, coordinate conversion, AP/mAP semantics, and source-style import diagnostics.
file-evaluation
Folder-based PASCAL VOC AP/mAP evaluation from ground-truth and detection text files.
object-detection-metrics
Guides legacy Object-Detection-Metrics PASCAL VOC AP/mAP evaluation from detection text folders and direct Python API classes.
nx-workspace-patterns
Configure and optimize Nx monorepo workspaces. Use when setting up Nx, configuring project boundaries, optimizing build caching, or implementing affected commands.