Skip to main content

Templates for anomaly detection with computer vision using anomalib library.

Project description



Sinapsis Anomalib

Module to provide anomaly detection training, inference and export with Anomalib.

🐍 Installation 🚀 Features 📚 Usage Example📙 Documentation 🔍 License

🐍 Installation

Install using your package manager of choice. We encourage the use of uv

Example with uv:

  uv pip install sinapsis-anomalib --extra-index-url https://pypi.sinapsis.tech

or with raw pip:

  pip install sinapsis-anomalib --extra-index-url https://pypi.sinapsis.tech

[!IMPORTANT] Templates in each package may require extra dependencies. For development, we recommend installing the package with all the optional dependencies:

with uv:

  uv pip install sinapsis-anomalib[all] --extra-index-url https://pypi.sinapsis.tech

or with raw pip:

  pip install sinapsis-anomalib[all] --extra-index-url https://pypi.sinapsis.tech

🚀 Features

Templates Supported

The Sinapsis Anomalib provides a powerful and flexible implementation for anomaly detection with Anomalib library.

AnomalibTorchInference

The following attributes configure PyTorch model inference:

  • model_path (str, required): Path to the trained PyTorch model file (.pt).
  • transforms (list[str], optional): List of torchvision transforms to apply (e.g., ["Resize", "Normalize"]).
  • device (Literal["cuda", "cpu"], required): Hardware acceleration target ("cuda" for GPU, "cpu" for CPU).
AnomalibOpenVINOInference

The following attributes configure OpenVINO-optimized inference:

  • model_path (str, required): Path to OpenVINO model directory (containing .xml and .bin).
  • transforms (dict, optional): Preprocessing steps matching the model's requirements.
  • device (Literal["CPU", "GPU"], optional): OpenVINO device plugin to use (default: "CPU").
  • model_height (int, required): The image height expected by OV model.
  • model_width (int, required): The image width expected by OV model.
AnomalibTrain

The following attributes apply to AnomalibTrain template:

  • folder_attributes_config_path (str | Path, required): Path to datamodule configuration YAML file. This must follow Anomalib's Folder data format specification. An example configuration is provided at packages/sinapsis_anomalib/src/sinapsis_anomalib/configs/datamodule_config.yml.
  • generic_key (str, required): Unique identifier for training artifacts.
  • callbacks (list[Callback], optional): PyTorch Lightning callbacks.
  • normalization (dict, optional): Input normalization configuration.
  • threshold (dict, optional): Anomaly threshold settings.
  • task (TaskType, optional): Task type (classification/detection/segmentation).
  • image_metrics (list, optional): Image-level evaluation metrics.
  • pixel_metrics (list, optional): Pixel-level evaluation metrics.
  • logger (Logger, optional): Training logger configuration.
  • default_root_dir (Path, required): Output directory for training artifacts.
  • callback_configs (dict, optional): Callback initialization parameters.
  • logger_configs (dict, optional): Logger initialization parameters.
  • max_epochs (int, optional): Maximum training epochs.
  • ckpt_path (str | Path, optional): Checkpoint path for resuming training.
  • accelerator (Literal["cpu", "gpu", "tpu", "hpu", "auto"]): Define the device to be used during training. Defaults to "cpu".
  • trainer_args (dict[str, Any]): General trainer asrguments. For more details see: https://lightning.ai/docs/pytorch/stable/common/trainer.html#trainer-flags

Additional model-specific attributes can be dynamically assigned through the class initialization dictionary (*_init attributes). These attributes correspond directly to the arguments used in Anomalib Models. Typically used for hyperparameters directly assigned to the corresponding model or to modify the model's architecture.

AnomalibExport

The following attributes apply to AnomalibExport template:

  • folder_attributes_config_path (str | Path, required for INT8_ACQ/INT8_PTQ compression): Path to datamodule configuration YAML (only required when using INT8 quantization). Must follow Anomalib's Folder data format.
  • callbacks (list[Callback], optional): PyTorch Lightning callbacks.
  • normalization (dict, optional): Input normalization configuration.
  • threshold (dict, optional): Anomaly threshold settings.
  • image_metrics (list, optional): Image-level evaluation metrics.
  • pixel_metrics (list, optional): Pixel-level evaluation metrics.
  • logger (Logger, optional): Training logger configuration.
  • default_root_dir (Path, required): Output directory for training artifacts.
  • callback_configs (dict, optional): Callback initialization parameters.
  • logger_configs (dict, optional): Logger initialization parameters.
  • export_type (ExportType | str, required): Export format (TORCH/ONNX/OPENVINO).
  • export_root (str | Path, optional): Output directory for exported models.
  • input_size (tuple[int, int], optional): Model input dimensions.
  • compression_type (CompressionType, optional): Model compression method.
  • metric (Metric | str, optional): Calibration metric.
  • ov_args (dict, optional): OpenVINO-specific arguments.
  • ckpt_path (str, optional): Explicit checkpoint path override.
  • generic_key_chkpt (str, optional): Alternate key for checkpoint loading.

Additional model-specific attributes can be dynamically assigned through the class initialization dictionary (*_init attributes). These attributes correspond directly to the arguments used in Anomalib Models. Typically used for hyperparameters directly assigned to the corresponding model or to modify the model's architecture.

[!TIP] Use CLI command sinapsis info --all-template-names to show a list with all the available Template names installed with Sinapsis Anomalib.

[!TIP] Use CLI command sinapsis info --example-template-config TEMPLATE_NAME to produce an example Agent config for the Template specified in TEMPLATE_NAME.

For example, for CfaTrain use sinapsis info --example-template-config CfaTrain to produce the following example config:

agent:
  name: my_test_agent
templates:
- template_name: InputTemplate
  class_name: InputTemplate
  attributes: {}
- template_name: CfaTrain
  class_name: CfaTrain
  template_input: InputTemplate
  attributes:
    folder_attributes_config_path: null
    generic_key: 'my_generic_key'
    callbacks: null
    normalization: null
    threshold: null
    image_metrics: null
    pixel_metrics: null
    logger: null
    default_root_dir: null
    callback_configs: null
    logger_configs: null
    max_epochs: null
    ckpt_path: null
    cfa_init:
      backbone: wide_resnet50_2
      gamma_c: 1
      gamma_d: 1
      num_nearest_neighbors: 3
      num_hard_negative_features: 3
      radius: 1.0e-05
🚫 Excluded Models

Some models that required additional configuration have been excluded and support for this will be included in future releases.

  • EfficientAd
  • VlmAd
  • Cfa
  • Dfkde
  • Fastflow
  • Supersimplenet
  • AiVad

For all other supported models, refer to the Anomalib documentation linked above.

📚 Usage Example

Below is an example configuration for **Sinapsis Anomalib** using a CFLOW model. This setup trains an anomaly detection model with configurable hyperparameters, including learning rate and epochs, and exports it in OpenVINO format for optimized inference. The pipeline includes training, model export, and predefined paths for outputs.
Example config
agent:
  name: anomalib_train_export

templates:
- template_name: InputTemplate
  class_name: InputTemplate
  attributes: {}

- template_name: CflowTrain
  class_name: CflowTrain
  attributes:
    folder_attributes_config_path: "configs/datamodule_config.yml"
    default_root_dir: "results/model"
    max_epochs: 1
    cflow_init:
      lr: 0.0001

- template_name: CflowExport
  class_name: CflowExport
  attributes:
    generic_key_chkpt: "CflowTrain"
    export_type: "openvino"
    export_root: "results/model/exported"
This configuration defines an **agent** and a sequence of **templates** to train and export a model based on a certain data configuration.

[!IMPORTANT] Attributes specified under the *_init keys (e.g., cflow_init) correspond directly to the Anomalib models parameters. Ensure that values are assigned correctly according to the official Anomalib documentation, as they affect the behavior and performance of the model.

To run the config, use the CLI:

sinapsis run name_of_config.yml

📙 Documentation

Documentation for this and other sinapsis packages is available on the sinapsis website

Tutorials for different projects within sinapsis are available at sinapsis tutorials page

🔍 License

This project is licensed under the AGPLv3 license, which encourages open collaboration and sharing. For more details, please refer to the LICENSE file.

For commercial use, please refer to our official Sinapsis website for information on obtaining a commercial license.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

sinapsis_anomalib-0.1.0.tar.gz (54.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

sinapsis_anomalib-0.1.0-py3-none-any.whl (43.9 kB view details)

Uploaded Python 3

File details

Details for the file sinapsis_anomalib-0.1.0.tar.gz.

File metadata

  • Download URL: sinapsis_anomalib-0.1.0.tar.gz
  • Upload date:
  • Size: 54.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.5.16

File hashes

Hashes for sinapsis_anomalib-0.1.0.tar.gz
Algorithm Hash digest
SHA256 0332cf582179cb411eb6448e8e95d74bded29e5fd357bced92cd2a6fe73aaf84
MD5 b9e45f4c52ed430ba3c2c25aa17bcc41
BLAKE2b-256 e5bdcee473c666810c22024299af5c8b99588e9f5da72eb12b7252b5715acb85

See more details on using hashes here.

File details

Details for the file sinapsis_anomalib-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for sinapsis_anomalib-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 a90e3d4cbaa0d709fa146d47209fd11a971f41c929f22e579745f917a2e2c38b
MD5 0a27021cdd4d461da24102db985d66d5
BLAKE2b-256 ce6e42e58503b04627ea29f1c6b47c5254570f27edce93d5d68778b170eaa982

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page