CLI

Anomalib CLI.

class anomalib.utils.cli.AnomalibCLI(model_class: ~typing.Optional[~typing.Union[~typing.Type[~pytorch_lightning.core.module.LightningModule], ~typing.Callable[[...], ~pytorch_lightning.core.module.LightningModule]]] = None, datamodule_class: ~typing.Optional[~typing.Union[~typing.Type[~pytorch_lightning.core.datamodule.LightningDataModule], ~typing.Callable[[...], ~pytorch_lightning.core.datamodule.LightningDataModule]]] = None, save_config_callback: ~typing.Optional[~typing.Type[~pytorch_lightning.cli.SaveConfigCallback]] = <class 'pytorch_lightning.cli.SaveConfigCallback'>, save_config_kwargs: ~typing.Optional[~typing.Dict[str, ~typing.Any]] = None, trainer_class: ~typing.Union[~typing.Type[~pytorch_lightning.trainer.trainer.Trainer], ~typing.Callable[[...], ~pytorch_lightning.trainer.trainer.Trainer]] = <class 'pytorch_lightning.trainer.trainer.Trainer'>, trainer_defaults: ~typing.Optional[~typing.Dict[str, ~typing.Any]] = None, seed_everything_default: ~typing.Union[bool, int] = True, parser_kwargs: ~typing.Optional[~typing.Union[~typing.Dict[str, ~typing.Any], ~typing.Dict[str, ~typing.Dict[str, ~typing.Any]]]] = None, subclass_mode_model: bool = False, subclass_mode_data: bool = False, args: ~typing.Optional[~typing.Union[~typing.List[str], ~typing.Dict[str, ~typing.Any], ~jsonargparse.namespace.Namespace]] = None, run: bool = True, auto_configure_optimizers: bool = True, **kwargs: ~typing.Any)[source]

Bases: LightningCLI

Implementation 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.

Receives as input pytorch-lightning classes (or callables which return pytorch-lightning classes), which are called / instantiated using a parsed configuration file and / or command line args.

Parsing of configuration from environment variables can be enabled by setting parser_kwargs={"default_env": True}. A full configuration yaml would be parsed from PL_CONFIG if set. Individual settings are so parsed from variables named for example PL_TRAINER__MAX_EPOCHS.

For more info, read the CLI docs.

Warning

LightningCLI is in beta and subject to change.

Parameters:
  • model_class – An optional LightningModule class to train on or a callable which returns a LightningModule instance when called. If None, you can pass a registered model with --model=MyModel.

  • datamodule_class – An optional LightningDataModule class or a callable which returns a LightningDataModule instance when called. If None, you can pass a registered datamodule with --data=MyDataModule.

  • save_config_callback – A callback class to save the config.

  • save_config_kwargs – Parameters that will be used to instantiate the save_config_callback.

  • trainer_class – An optional subclass of the Trainer class or a callable which returns a Trainer instance when called.

  • trainer_defaults – Set to override Trainer defaults or add persistent callbacks. The callbacks added through this argument will not be configurable from a configuration file and will always be present for this particular CLI. Alternatively, configurable callbacks can be added as explained in the CLI docs.

  • seed_everything_default – Number for the seed_everything() seed value. Set to True to automatically choose a seed value. Setting it to False will avoid calling seed_everything.

  • parser_kwargs – Additional arguments to instantiate each LightningArgumentParser.

  • subclass_mode_model – Whether model can be any subclass of the given class.

  • subclass_mode_data

    Whether datamodule can be any subclass of the given class.

  • args – Arguments to parse. If None the arguments are taken from sys.argv. Command line style arguments can be given in a list. Alternatively, structured config options can be given in a dict or jsonargparse.Namespace.

  • run – Whether subcommands should be added to run a Trainer method. If set to False, the trainer and model classes will be instantiated only.

add_arguments_to_parser(parser: LightningArgumentParser) None[source]

Add default arguments.

Parameters:

parser (LightningArgumentParser) – Lightning Argument Parser.

before_instantiate_classes() None[source]

Modify the configuration to properly instantiate classes.