GanomalyExport
Python template · sinapsis_anomalib.templates.anomalib_export
Overview
Export functionality for trained Anomalib models.
Ganomaly — inherited documentation
PL Lightning Module for the GANomaly Algorithm.
The GANomaly model consists of a generator and discriminator network. The generator learns to reconstruct normal images while the discriminator helps ensure the reconstructions are realistic. Anomalies are detected by measuring the reconstruction error and latent space differences.
Args: batch_size (int): Number of samples in each batch. Defaults to ``32``. n_features (int): Number of feature channels in CNN layers. Defaults to ``64``. latent_vec_size (int): Dimension of the latent space vectors. Defaults to ``100``. extra_layers (int, optional): Number of extra layers in encoder/decoder. Defaults to ``0``. add_final_conv_layer (bool, optional): Add convolution layer at the end. Defaults to ``True``. wadv (int, optional): Weight for adversarial loss component. Defaults to ``1``. wcon (int, optional): Weight for image reconstruction loss component. Defaults to ``50``. wenc (int, optional): Weight for latent vector encoding loss component. Defaults to ``1``. lr (float, optional): Learning rate for optimizers. Defaults to ``0.0002``. beta1 (float, optional): Beta1 parameter for Adam optimizers. Defaults to ``0.5``. beta2 (float, optional): Beta2 parameter for Adam optimizers. Defaults to ``0.999``. pre_processor (PreProcessor | bool, optional): Pre-processor to transform inputs before passing to model. Defaults to ``True``. post_processor (PostProcessor | bool, optional): Post-processor to generate predictions from model outputs. Defaults to ``True``. evaluator (Evaluator | bool, optional): Evaluator to compute metrics. Defaults to ``True``. visualizer (Visualizer | bool, optional): Visualizer to display results. Defaults to ``True``.
Example: >>> from anomalib.models import Ganomaly >>> model = Ganomaly( ... batch_size=32, ... n_features=64, ... latent_vec_size=100, ... wadv=1, ... wcon=50, ... wenc=1, ... )
See Also: :class:`anomalib.models.image.ganomaly.torch_model.GanomalyModel`: PyTorch implementation of the GANomaly model architecture. :class:`anomalib.models.image.ganomaly.loss.GeneratorLoss`: Loss function for the generator network. :class:`anomalib.models.image.ganomaly.loss.DiscriminatorLoss`: Loss function for the discriminator network.
Capabilities
Capabilities: not setInstallation
Install the published package using pip or uv.
pip install sinapsis-anomalib==1.0.0uv pip install sinapsis-anomalib==1.0.0uv add sinapsis-anomalib==1.0.0Configuration
Effective fields from the inspector schema, including nested Pydantic model fields.
Optional
Default: null
Metric used for compression calibration.
Optional
Default: null
OpenVINO-specific export arguments.
Optional
Default: null
Optional
Default: false
If True, compresses the model weights to FP16 precision. Defaults to None. Print detailed information about conversion.
Optional
Default: null
Optional
Default: null
Optional
Default: null
Explicit path to model checkpoint.
Optional
Default: null
Optional
Default: null
Expected input dimensions (height, width).
Optional
Default: null
Root directory for exported files.
Optional
Default: null
Target export format. Defaults to TORCH.
Optional
Default: "torch"
Required
Default: null
Optional
Default: 0.0002
Optional
Default: 1
Optional
Default: 50
Optional
Default: 1
Optional
Default: 0.5
Optional
Default: 0.999
Optional
Default: true
Optional
Default: 32
Optional
Default: 64
Optional
Default: true
Optional
Default: 0
Optional
Default: true
Optional
Default: true
Optional
Default: 100
Optional
Default: true
Optional
Default: null
Optional
Default: null
Optional
Default: null
Optional
Default: null
Optional
Default: null
Quantization/compression method.
Optional
Default: null
Optional
Default: null
A descriptive name for the dataset.
Required
Default: null
The root directory where the dataset is located.
Optional
Default: null
A random seed for reproducibility in data splitting.
Optional
Default: null
Optional
Default: null
Optional
Default: null
Path to the directory containing normal images.
Required
Default: null
The number of subprocesses to use for data loading. Defaults to 8.
Optional
Default: 8
Path to the directory for abnormal images.
Optional
Default: null
Optional
Default: "from_test"
The number of samples per batch for evaluation. Defaults to 32.
Optional
Default: 32
Optional
Default: null
Optional
Default: "from_dir"
Optional
Default: 0.5
Optional
Default: 0.2
The number of samples per batch for training. Defaults to 32.
Optional
Default: 32
Optional
Default: 0.2
Key to retrieve training results. ganomaly_init batch_size <class 'int'>: default: 32 n_features <class 'int'>: default: 64 latent_vec_size <class 'int'>: default: 100 extra_layers <class 'int'>: default: 0… Read full field description
Key to retrieve training results. ganomaly_init batch_size <class 'int'>: default: 32 n_features <class 'int'>: default: 64 latent_vec_size <class 'int'>: default: 100 extra_layers <class 'int'>: default: 0 add_final_conv_layer <class 'bool'>: default: True wadv <class 'int'>: default: 1 wcon <class 'int'>: default: 50 wenc <class 'int'>: default: 1 lr <class 'float'>: default: 0.0002 beta1 <class 'float'>: default: 0.5 beta2 <class 'float'>: default: 0.999 pre_processor typing.Union[anomalib.pre_processing.pre_processor.PreProcessor, bool]: default: True post_processor typing.Union[anomalib.post_processing.post_processor.PostProcessor, bool]: default: True evaluator typing.Union[anomalib.metrics.evaluator.Evaluator, bool]: default: True visualizer typing.Union[anomalib.visualization.base.Visualizer, bool]: default: True
Optional
Default: null
Configuration example
Generated from documented defaults. Replace any placeholders and complete required nested settings before running.
templates:
- template_name: "GanomalyExport"
class_name: "GanomalyExport"
attributes:
logger: null
metric: null
ov_args:
verbose: false
compress_to_fp16: null
callbacks: null
ckpt_path: null
threshold: null
input_size: null
export_root: null
export_type: {}
ganomaly_init:
lr: 0.0002
wadv: 1
wcon: 50
wenc: 1
beta1: 0.5
beta2: 0.999
evaluator: true
batch_size: 32
n_features: 64
visualizer: true
extra_layers: 0
pre_processor: true
post_processor: true
latent_vec_size: 100
add_final_conv_layer: true
image_metrics: null
normalization: null
pixel_metrics: null
logger_configs: null
callback_configs: null
compression_type: null
folder_attributes:
name: "<required>"
root: null
seed: null
mask_dir: null
extensions: null
normal_dir: "<required>"
num_workers: 8
abnormal_dir: null
val_split_mode: "from_test"
eval_batch_size: 32
normal_test_dir: null
test_split_mode: "from_dir"
val_split_ratio: 0.5
test_split_ratio: 0.2
train_batch_size: 32
normal_split_ratio: 0.2
generic_key_chkpt: null
View original docstring example
The source example references CfaExport, not GanomalyExport.
agent:
name: my_test_agent
templates:
- template_name: InputTemplate
class_name: InputTemplate
attributes: {}
- template_name: CfaExport
class_name: CfaExport
template_input: InputTemplate
attributes:
folder_attributes_config_path: null
generic_key: 'my_generic_key'
callbacks: null
normalization: null
threshold: null
task: null
image_metrics: null
pixel_metrics: null
logger: null
callback_configs: null
logger_configs: null
export_type: 'openvino'
export_root: null
input_size: null
transform: null
compression_type: null
metric: null
ov_args: null
ckpt_path: null
generic_key_chkpt: 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
For a full list of options use the sinapsis cli: sinapsis info --all-template-names
If you want to see all available models, please visit:
https://anomalib.readthedocs.io/en/v1.2.0/markdown/guides/reference/models/image/index.html
Notes:
- Supports multiple export formats via ExportType
- Enables model compression through CompressionType.
- Can load models from checkpoints or previous training results.Inheritance
sinapsis_anomalib.templates.anomalib_export.AnomalibExportEnvironment variables
Environment definitions belong to their canonical Python modules.