CLI#
Anomalib Command Line Interface.
This module provides the AnomalibCLI class for configuring and running Anomalib from the command line. The CLI supports configuration via both command line arguments and configuration files (.yaml or .json).
- class anomalib.cli.cli.AnomalibCLI(args=None, run=True)#
Bases:
object
Implementation of a fully configurable CLI tool for Anomalib.
This class provides a flexible command-line interface that can be configured through both CLI arguments and configuration files. It supports various subcommands for training, testing, and exporting models.
- Parameters:
Examples
Run from command line:
>>> import sys >>> sys.argv = ["anomalib", "train", "--model", "Padim", "--data", "MVTec"]
Run programmatically:
>>> from anomalib.cli import AnomalibCLI >>> cli = AnomalibCLI(["train", "--model", "Padim", "--data", "MVTec"], run=False)
Note
The CLI supports both YAML and JSON configuration files. Configuration can be provided via both files and command line arguments simultaneously.
- static add_arguments_to_parser(parser)#
Extend trainer’s arguments to add engine arguments. :rtype:
None
Note
Since
Engine
parameters are manually added, any change to theEngine
class should be reflected manually.
- add_subcommands(**kwargs)#
Initialize base subcommands and add anomalib specific on top of it.
- Return type:
- static anomalib_subcommands()#
Return a dictionary of subcommands and their description.
- before_instantiate_classes()#
Modify the configuration to properly instantiate classes and sets up tiler.
- Return type:
- static init_parser(**kwargs)#
Method that instantiates the argument parser.
- Return type:
ArgumentParser
- instantiate_classes()#
Instantiate classes depending on the subcommand.
For trainer related commands it instantiates all the model, datamodule and trainer classes. But for subcommands we do not want to instantiate any trainer specific classes such as datamodule, model, etc This is because the subcommand is responsible for instantiating and executing code based on the passed config
- Return type:
- instantiate_engine()#
Instantiate the engine. :rtype:
None
Note
Most of the code in this method is taken from
LightningCLI
’sinstantiate_trainer
method. Refer to that method for more details.
- static subcommands()#
Skip predict subcommand as it is added later.