CLI#
Anomalib CLI.
- class anomalib.cli.AnomalibCLI(save_config_callback=<class 'lightning.pytorch.cli.SaveConfigCallback'>, save_config_kwargs=None, trainer_class=<class 'lightning.pytorch.trainer.trainer.Trainer'>, trainer_defaults=None, seed_everything_default=True, parser_kwargs=None, args=None, run=True, auto_configure_optimizers=True)#
Bases:
LightningCLIImplementation of a fully configurable CLI tool for anomalib.
The advantage of this tool is its flexibility to configure the pipeline from both the CLI and a configuration file (.yaml or .json). It is even possible to use both the CLI and a configuration file simultaneously. For more details, the reader could refer to PyTorch Lightning CLI documentation.
save_config_kwargsis set tooverwrite=Trueso that theSaveConfigCallbackoverwrites the config if it already exists.- add_arguments_to_parser(parser)#
Extend trainer’s arguments to add engine arguments. :rtype:
NoneNote
Since
Engineparameters are manually added, any change to theEngineclass should be reflected manually.
- add_benchmark_arguments(parser)#
Add benchmark arguments to the parser.
- Return type:
None
Example
$ anomalib benchmark –benchmark_config tools/benchmarking/benchmark_params.yaml
- add_export_arguments(parser)#
Add export arguments to the parser.
- Return type:
None
- add_hpo_arguments(parser)#
Add hyperparameter optimization arguments.
- Return type:
None
- add_predict_arguments(parser)#
Add predict arguments to the parser.
- Return type:
None
- add_train_arguments(parser)#
Add train arguments to the parser.
- Return type:
None
- static anomalib_subcommands()#
Return a dictionary of subcommands and their description.
- Return type:
dict[str,dict[str,str]]
- before_instantiate_classes()#
Modify the configuration to properly instantiate classes and sets up tiler.
- Return type:
None
- benchmark()#
Run benchmark subcommand.
- Return type:
None
- property export: Callable[[...], Path | None]#
Export the model using engine’s export method.
- property fit: Callable[[...], None]#
Fit the model using engine’s fit method.
- hpo()#
Run hpo subcommand.
- Return type:
None
- init_parser(**kwargs)#
Method that instantiates the argument parser.
- Return type:
LightningArgumentParser
- 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:
None
- instantiate_engine()#
Instantiate the engine. :rtype:
EngineNote
Most of the code in this method is taken from
LightningCLI’sinstantiate_trainermethod. Refer to that method for more details.
- property predict: Callable[[...], List[Any] | List[List[Any]] | None]#
Predict using engine’s predict method.
- static subcommands()#
Skip predict subcommand as it is added later.
- Return type:
dict[str,set[str]]
- property test: Callable[[...], List[Mapping[str, float]]]#
Test the model using engine’s test method.
- property train: Callable[[...], List[Mapping[str, float]]]#
Train the model using engine’s train method.
- property validate: Callable[[...], List[Mapping[str, float]] | None]#
Validate the model using engine’s validate method.