diff --git a/docs/source/markdown/guides/developer/sdd.md b/docs/source/markdown/guides/developer/sdd.md index 19bb90b4a3..41088669e7 100644 --- a/docs/source/markdown/guides/developer/sdd.md +++ b/docs/source/markdown/guides/developer/sdd.md @@ -201,7 +201,7 @@ and depth data. Anomalib provides a collection of anomaly models within the image and video domains. The models are implemented sub-classing PyTorch Lightning's -`LightningModule` class, which is called `AnomalyModule`, which provides a set +`LightningModule` class, which is called `AnomalibModule`, which provides a set of APIs for defining the model architecture, loss function, and optimization algorithm. The models are designed to be modular and extensible, allowing users to easily modify the model architecture and training workflow based on their diff --git a/src/anomalib/callbacks/model_loader.py b/src/anomalib/callbacks/model_loader.py index bbdebfce0e..8c688b3127 100644 --- a/src/anomalib/callbacks/model_loader.py +++ b/src/anomalib/callbacks/model_loader.py @@ -8,7 +8,7 @@ import torch from lightning.pytorch import Callback, Trainer -from anomalib.models.components import AnomalyModule +from anomalib.models.components import AnomalibModule logger = logging.getLogger(__name__) @@ -27,7 +27,7 @@ class LoadModelCallback(Callback): def __init__(self, weights_path: str) -> None: self.weights_path = weights_path - def setup(self, trainer: Trainer, pl_module: AnomalyModule, stage: str | None = None) -> None: + def setup(self, trainer: Trainer, pl_module: AnomalibModule, stage: str | None = None) -> None: """Call when inference begins. Loads the model weights from ``weights_path`` into the PyTorch module. diff --git a/src/anomalib/callbacks/tiler_configuration.py b/src/anomalib/callbacks/tiler_configuration.py index a3018bd42b..f44a4d679f 100644 --- a/src/anomalib/callbacks/tiler_configuration.py +++ b/src/anomalib/callbacks/tiler_configuration.py @@ -9,7 +9,7 @@ from lightning.pytorch.callbacks import Callback from anomalib.data.utils.tiler import ImageUpscaleMode, Tiler -from anomalib.models.components import AnomalyModule +from anomalib.models.components import AnomalibModule __all__ = ["TilerConfigurationCallback"] @@ -61,7 +61,7 @@ def setup(self, trainer: pl.Trainer, pl_module: pl.LightningModule, stage: str | del trainer, stage # These variables are not used. if self.enable: - if isinstance(pl_module, AnomalyModule) and hasattr(pl_module.model, "tiler"): + if isinstance(pl_module, AnomalibModule) and hasattr(pl_module.model, "tiler"): pl_module.model.tiler = Tiler( tile_size=self.tile_size, stride=self.stride, diff --git a/src/anomalib/callbacks/visualizer.py b/src/anomalib/callbacks/visualizer.py index 41d56a7ebd..9b0b78dfa0 100644 --- a/src/anomalib/callbacks/visualizer.py +++ b/src/anomalib/callbacks/visualizer.py @@ -16,7 +16,7 @@ from anomalib.data.utils.image import save_image, show_image from anomalib.loggers import AnomalibWandbLogger from anomalib.loggers.base import ImageLoggerBase -from anomalib.models import AnomalyModule +from anomalib.models import AnomalibModule from anomalib.utils.visualization import ( BaseVisualizer, GeneratorResult, @@ -77,7 +77,7 @@ def __init__( def on_test_batch_end( self, trainer: Trainer, - pl_module: AnomalyModule, + pl_module: AnomalibModule, outputs: STEP_OUTPUT | None, batch: Any, # noqa: ANN401 batch_idx: int, @@ -114,7 +114,7 @@ def on_test_batch_end( if self.log: self._add_to_logger(result, pl_module, trainer) - def on_test_end(self, trainer: Trainer, pl_module: AnomalyModule) -> None: + def on_test_end(self, trainer: Trainer, pl_module: AnomalibModule) -> None: for generator in self.generators: if generator.visualize_on == VisualizationStep.STAGE_END: for result in generator(trainer=trainer, pl_module=pl_module): @@ -135,7 +135,7 @@ def on_test_end(self, trainer: Trainer, pl_module: AnomalyModule) -> None: def on_predict_batch_end( self, trainer: Trainer, - pl_module: AnomalyModule, + pl_module: AnomalibModule, outputs: STEP_OUTPUT | None, batch: Any, # noqa: ANN401 batch_idx: int, @@ -143,20 +143,20 @@ def on_predict_batch_end( ) -> None: return self.on_test_batch_end(trainer, pl_module, outputs, batch, batch_idx, dataloader_idx) - def on_predict_end(self, trainer: Trainer, pl_module: AnomalyModule) -> None: + def on_predict_end(self, trainer: Trainer, pl_module: AnomalibModule) -> None: return self.on_test_end(trainer, pl_module) @staticmethod def _add_to_logger( result: GeneratorResult, - module: AnomalyModule, + module: AnomalibModule, trainer: Trainer, ) -> None: """Add image to logger. Args: result (GeneratorResult): Output from the generators. - module (AnomalyModule): LightningModule from which the global step is extracted. + module (AnomalibModule): LightningModule from which the global step is extracted. trainer (Trainer): Trainer object. """ # Store names of logger and the logger in a dict diff --git a/src/anomalib/cli/cli.py b/src/anomalib/cli/cli.py index b272fdc81b..87492ac3f3 100644 --- a/src/anomalib/cli/cli.py +++ b/src/anomalib/cli/cli.py @@ -30,7 +30,7 @@ from anomalib.data import AnomalibDataModule from anomalib.engine import Engine - from anomalib.models import AnomalyModule + from anomalib.models import AnomalibModule from anomalib.utils.config import update_config except ImportError: @@ -166,7 +166,7 @@ def add_trainer_arguments(self, parser: ArgumentParser, subcommand: str) -> None self._add_default_arguments_to_parser(parser) self._add_trainer_arguments_to_parser(parser, add_optimizer=True, add_scheduler=True) parser.add_subclass_arguments( - AnomalyModule, + AnomalibModule, "model", fail_untyped=False, required=True, @@ -186,7 +186,7 @@ def add_train_arguments(self, parser: ArgumentParser) -> None: self._add_default_arguments_to_parser(parser) self._add_trainer_arguments_to_parser(parser, add_optimizer=True, add_scheduler=True) parser.add_subclass_arguments( - AnomalyModule, + AnomalibModule, "model", fail_untyped=False, required=True, @@ -205,7 +205,7 @@ def add_predict_arguments(self, parser: ArgumentParser) -> None: self._add_default_arguments_to_parser(parser) self._add_trainer_arguments_to_parser(parser) parser.add_subclass_arguments( - AnomalyModule, + AnomalibModule, "model", fail_untyped=False, required=True, @@ -228,7 +228,7 @@ def add_export_arguments(self, parser: ArgumentParser) -> None: self._add_default_arguments_to_parser(parser) self._add_trainer_arguments_to_parser(parser) parser.add_subclass_arguments( - AnomalyModule, + AnomalibModule, "model", fail_untyped=False, required=True, diff --git a/src/anomalib/engine/engine.py b/src/anomalib/engine/engine.py index 36bfcc3bf4..017e20bb93 100644 --- a/src/anomalib/engine/engine.py +++ b/src/anomalib/engine/engine.py @@ -20,7 +20,7 @@ from anomalib.callbacks.timer import TimerCallback from anomalib.data import AnomalibDataModule, AnomalibDataset, PredictDataset from anomalib.deploy import CompressionType, ExportType -from anomalib.models import AnomalyModule +from anomalib.models import AnomalibModule from anomalib.utils.path import create_versioned_dir from anomalib.visualization import ImageVisualizer @@ -64,11 +64,11 @@ class _TrainerArgumentsCache: def __init__(self, **kwargs) -> None: self._cached_args = {**kwargs} - def update(self, model: AnomalyModule) -> None: + def update(self, model: AnomalibModule) -> None: """Replace cached arguments with arguments retrieved from the model. Args: - model (AnomalyModule): The model used for training + model (AnomalibModule): The model used for training """ for key, value in model.trainer_arguments.items(): if key in self._cached_args and self._cached_args[key] != value: @@ -77,7 +77,7 @@ def update(self, model: AnomalyModule) -> None: ) self._cached_args[key] = value - def requires_update(self, model: AnomalyModule) -> bool: + def requires_update(self, model: AnomalibModule) -> bool: return any(self._cached_args.get(key, None) != value for key, value in model.trainer_arguments.items()) @property @@ -152,14 +152,14 @@ def trainer(self) -> Trainer: return self._trainer @property - def model(self) -> AnomalyModule: + def model(self) -> AnomalibModule: """Property to get the model. Raises: UnassignedError: When the model is not assigned yet. Returns: - AnomalyModule: Anomaly model. + AnomalibModule: Anomaly model. """ if not self.trainer.lightning_module: msg = "Trainer does not have a model assigned yet." @@ -190,7 +190,7 @@ def best_model_path(self) -> str | None: def _setup_workspace( self, - model: AnomalyModule, + model: AnomalibModule, train_dataloaders: TRAIN_DATALOADERS | None = None, val_dataloaders: EVAL_DATALOADERS | None = None, test_dataloaders: EVAL_DATALOADERS | None = None, @@ -205,7 +205,7 @@ def _setup_workspace( other artifacts will be saved in this directory. Args: - model (AnomalyModule): Input model. + model (AnomalibModule): Input model. train_dataloaders (TRAIN_DATALOADERS | None, optional): Train dataloaders. Defaults to ``None``. val_dataloaders (EVAL_DATALOADERS | None, optional): Validation dataloaders. @@ -255,7 +255,7 @@ def _setup_workspace( root_dir = Path(self._cache.args["default_root_dir"]) / model.name / dataset_name / category self._cache.args["default_root_dir"] = create_versioned_dir(root_dir) if versioned_dir else root_dir / "latest" - def _setup_trainer(self, model: AnomalyModule) -> None: + def _setup_trainer(self, model: AnomalibModule) -> None: """Instantiate the trainer based on the model parameters.""" # Check if the cache requires an update if self._cache.requires_update(model): @@ -291,7 +291,7 @@ def _setup_dataset_task( ) data.task = self.task - def _setup_anomalib_callbacks(self, model: AnomalyModule) -> None: + def _setup_anomalib_callbacks(self, model: AnomalibModule) -> None: """Set up callbacks for the trainer.""" _callbacks: list[Callback] = [] @@ -325,7 +325,7 @@ def _setup_anomalib_callbacks(self, model: AnomalyModule) -> None: @staticmethod def _should_run_validation( - model: AnomalyModule, + model: AnomalibModule, ckpt_path: str | Path | None, ) -> bool: """Check if we need to run validation to collect normalization statistics and thresholds. @@ -341,7 +341,7 @@ def _should_run_validation( are available. If neither is available, we can't run validation. Args: - model (AnomalyModule): Model passed to the entrypoint. + model (AnomalibModule): Model passed to the entrypoint. dataloaders (EVAL_DATALOADERS | None): Dataloaders passed to the entrypoint. datamodule (AnomalibDataModule | None): Lightning datamodule passed to the entrypoint. ckpt_path (str | Path | None): Checkpoint path passed to the entrypoint. @@ -357,7 +357,7 @@ def _should_run_validation( def fit( self, - model: AnomalyModule, + model: AnomalibModule, train_dataloaders: TRAIN_DATALOADERS | None = None, val_dataloaders: EVAL_DATALOADERS | None = None, datamodule: AnomalibDataModule | None = None, @@ -366,7 +366,7 @@ def fit( """Fit the model using the trainer. Args: - model (AnomalyModule): Model to be trained. + model (AnomalibModule): Model to be trained. train_dataloaders (TRAIN_DATALOADERS | None, optional): Train dataloaders. Defaults to None. val_dataloaders (EVAL_DATALOADERS | None, optional): Validation dataloaders. @@ -411,7 +411,7 @@ def fit( def validate( self, - model: AnomalyModule | None = None, + model: AnomalibModule | None = None, dataloaders: EVAL_DATALOADERS | None = None, ckpt_path: str | Path | None = None, verbose: bool = True, @@ -420,7 +420,7 @@ def validate( """Validate the model using the trainer. Args: - model (AnomalyModule | None, optional): Model to be validated. + model (AnomalibModule | None, optional): Model to be validated. Defaults to None. dataloaders (EVAL_DATALOADERS | None, optional): Dataloaders to be used for validation. @@ -460,7 +460,7 @@ def validate( def test( self, - model: AnomalyModule | None = None, + model: AnomalibModule | None = None, dataloaders: EVAL_DATALOADERS | None = None, ckpt_path: str | Path | None = None, verbose: bool = True, @@ -472,7 +472,7 @@ def test( finally tests the model. Args: - model (AnomalyModule | None, optional): + model (AnomalibModule | None, optional): The model to be tested. Defaults to None. dataloaders (EVAL_DATALOADERS | None, optional): @@ -545,7 +545,7 @@ def test( if model: self._setup_trainer(model) elif not self.model: - msg = "`Engine.test()` requires an `AnomalyModule` when it hasn't been passed in a previous run." + msg = "`Engine.test()` requires an `AnomalibModule` when it hasn't been passed in a previous run." raise RuntimeError(msg) self._setup_dataset_task(dataloaders) @@ -556,7 +556,7 @@ def test( def predict( self, - model: AnomalyModule | None = None, + model: AnomalibModule | None = None, dataloaders: EVAL_DATALOADERS | None = None, datamodule: AnomalibDataModule | None = None, dataset: Dataset | PredictDataset | None = None, @@ -570,7 +570,7 @@ def predict( validation dataloader is available. Finally, predicts using the model. Args: - model (AnomalyModule | None, optional): + model (AnomalibModule | None, optional): Model to be used for prediction. Defaults to None. dataloaders (EVAL_DATALOADERS | None, optional): @@ -623,7 +623,7 @@ def predict( ``` """ if not (model or self.model): - msg = "`Engine.predict()` requires an `AnomalyModule` when it hasn't been passed in a previous run." + msg = "`Engine.predict()` requires an `AnomalibModule` when it hasn't been passed in a previous run." raise ValueError(msg) if ckpt_path: @@ -668,7 +668,7 @@ def predict( def train( self, - model: AnomalyModule, + model: AnomalibModule, train_dataloaders: TRAIN_DATALOADERS | None = None, val_dataloaders: EVAL_DATALOADERS | None = None, test_dataloaders: EVAL_DATALOADERS | None = None, @@ -678,7 +678,7 @@ def train( """Fits the model and then calls test on it. Args: - model (AnomalyModule): Model to be trained. + model (AnomalibModule): Model to be trained. train_dataloaders (TRAIN_DATALOADERS | None, optional): Train dataloaders. Defaults to None. val_dataloaders (EVAL_DATALOADERS | None, optional): Validation dataloaders. @@ -731,7 +731,7 @@ def train( def export( self, - model: AnomalyModule, + model: AnomalibModule, export_type: ExportType | str, export_root: str | Path | None = None, input_size: tuple[int, int] | None = None, @@ -744,7 +744,7 @@ def export( r"""Export the model in PyTorch, ONNX or OpenVINO format. Args: - model (AnomalyModule): Trained model. + model (AnomalibModule): Trained model. export_type (ExportType): Export type. export_root (str | Path | None, optional): Path to the output directory. If it is not set, the model is exported to trainer.default_root_dir. Defaults to None. @@ -832,7 +832,7 @@ def from_config( cls: type["Engine"], config_path: str | Path, **kwargs, - ) -> tuple["Engine", AnomalyModule, AnomalibDataModule]: + ) -> tuple["Engine", AnomalibModule, AnomalibDataModule]: """Create an Engine instance from a configuration file. Args: @@ -840,7 +840,7 @@ def from_config( **kwargs (dict): Additional keyword arguments. Returns: - tuple[Engine, AnomalyModule, AnomalibDataModule]: Engine instance. + tuple[Engine, AnomalibModule, AnomalibDataModule]: Engine instance. Example: The following example shows training with full configuration file: diff --git a/src/anomalib/metrics/evaluator.py b/src/anomalib/metrics/evaluator.py index 91ef47aa6d..53f05af3b2 100644 --- a/src/anomalib/metrics/evaluator.py +++ b/src/anomalib/metrics/evaluator.py @@ -19,10 +19,10 @@ class Evaluator(nn.Module, Callback): """Evaluator module for LightningModule. The Evaluator module is a PyTorch module that computes and logs metrics during - validation and test steps. Each AnomalyModule should have an Evaluator module as + validation and test steps. Each AnomalibModule should have an Evaluator module as a submodule to compute and log metrics during validation and test steps. An Evaluation - module can be passed to the AnomalyModule as a parameter during initialization. When - no Evaluator module is provided, the AnomalyModule will use a default Evaluator module + module can be passed to the AnomalibModule as a parameter during initialization. When + no Evaluator module is provided, the AnomalibModule will use a default Evaluator module that logs a default set of metrics. Args: diff --git a/src/anomalib/models/__init__.py b/src/anomalib/models/__init__.py index 3b32c83367..26f8695ab6 100644 --- a/src/anomalib/models/__init__.py +++ b/src/anomalib/models/__init__.py @@ -9,7 +9,7 @@ from jsonargparse import Namespace from omegaconf import DictConfig, OmegaConf -from anomalib.models.components import AnomalyModule +from anomalib.models.components import AnomalibModule from anomalib.utils.path import convert_to_snake_case from .image import ( @@ -95,10 +95,14 @@ def get_available_models() -> set[str]: >>> get_available_models() ['ai_vad', 'cfa', 'cflow', 'csflow', 'dfkde', 'dfm', 'draem', 'efficient_ad', 'fastflow', ...] """ - return {convert_to_snake_case(cls.__name__) for cls in AnomalyModule.__subclasses__()} + return { + convert_to_snake_case(cls.__name__) + for cls in AnomalibModule.__subclasses__() + if cls.__name__ != "AnomalyModule" + } -def _get_model_class_by_name(name: str) -> type[AnomalyModule]: +def _get_model_class_by_name(name: str) -> type[AnomalibModule]: """Retrieves an anomaly model based on its name. Args: @@ -108,13 +112,13 @@ def _get_model_class_by_name(name: str) -> type[AnomalyModule]: UnknownModelError: If the model is not found. Returns: - type[AnomalyModule]: Anomaly Model + type[AnomalibModule]: Anomaly Model """ logger.info("Loading the model.") - model_class: type[AnomalyModule] | None = None + model_class: type[AnomalibModule] | None = None name = convert_snake_to_pascal_case(name).lower() - for model in AnomalyModule.__subclasses__(): + for model in AnomalibModule.__subclasses__(): if name == model.__name__.lower(): model_class = model if model_class is None: @@ -124,7 +128,7 @@ def _get_model_class_by_name(name: str) -> type[AnomalyModule]: return model_class -def get_model(model: DictConfig | str | dict | Namespace, *args, **kwdargs) -> AnomalyModule: +def get_model(model: DictConfig | str | dict | Namespace, *args, **kwdargs) -> AnomalibModule: """Get Anomaly Model. Args: @@ -145,9 +149,9 @@ def get_model(model: DictConfig | str | dict | Namespace, *args, **kwdargs) -> A TypeError: If unsupported type is passed. Returns: - AnomalyModule: Anomaly Model + AnomalibModule: Anomaly Model """ - _model: AnomalyModule + _model: AnomalibModule if isinstance(model, str): _model_class = _get_model_class_by_name(model) _model = _model_class(*args, **kwdargs) diff --git a/src/anomalib/models/components/__init__.py b/src/anomalib/models/components/__init__.py index b37daafefe..762345a93d 100644 --- a/src/anomalib/models/components/__init__.py +++ b/src/anomalib/models/components/__init__.py @@ -3,7 +3,7 @@ # Copyright (C) 2022-2024 Intel Corporation # SPDX-License-Identifier: Apache-2.0 -from .base import AnomalyModule, BufferListMixin, DynamicBufferMixin, MemoryBankMixin +from .base import AnomalibModule, BufferListMixin, DynamicBufferMixin, MemoryBankMixin from .dimensionality_reduction import PCA, SparseRandomProjection from .feature_extractors import TimmFeatureExtractor, TorchFXFeatureExtractor from .filters import GaussianBlur2d @@ -11,7 +11,7 @@ from .stats import GaussianKDE, MultiVariateGaussian __all__ = [ - "AnomalyModule", + "AnomalibModule", "BufferListMixin", "DynamicBufferMixin", "MemoryBankMixin", diff --git a/src/anomalib/models/components/base/__init__.py b/src/anomalib/models/components/base/__init__.py index b535c910cb..5214f966dc 100644 --- a/src/anomalib/models/components/base/__init__.py +++ b/src/anomalib/models/components/base/__init__.py @@ -3,9 +3,9 @@ # Copyright (C) 2022-2024 Intel Corporation # SPDX-License-Identifier: Apache-2.0 -from .anomaly_module import AnomalyModule +from .anomaly_module import AnomalibModule from .buffer_list import BufferListMixin from .dynamic_buffer import DynamicBufferMixin from .memory_bank_module import MemoryBankMixin -__all__ = ["AnomalyModule", "BufferListMixin", "DynamicBufferMixin", "MemoryBankMixin"] +__all__ = ["AnomalibModule", "BufferListMixin", "DynamicBufferMixin", "MemoryBankMixin"] diff --git a/src/anomalib/models/components/base/anomaly_module.py b/src/anomalib/models/components/base/anomaly_module.py index 336877f17a..6509351cfb 100644 --- a/src/anomalib/models/components/base/anomaly_module.py +++ b/src/anomalib/models/components/base/anomaly_module.py @@ -4,6 +4,7 @@ # SPDX-License-Identifier: Apache-2.0 import logging +import warnings from abc import ABC, abstractmethod from collections.abc import Sequence from pathlib import Path @@ -30,8 +31,8 @@ logger = logging.getLogger(__name__) -class AnomalyModule(ExportMixin, pl.LightningModule, ABC): - """AnomalyModule to train, validate, predict and test images. +class AnomalibModule(ExportMixin, pl.LightningModule, ABC): + """AnomalibModule to train, validate, predict and test images. Acts as a base class for all the Anomaly Modules in the library. """ @@ -98,7 +99,7 @@ def _resolve_pre_processor(self, pre_processor: PreProcessor | bool) -> PreProce raise TypeError(msg) def configure_callbacks(self) -> Sequence[Callback] | Callback: - """Configure default callbacks for AnomalyModule.""" + """Configure default callbacks for AnomalibModule.""" return [self.pre_processor] if self.pre_processor else [] def forward(self, batch: torch.Tensor, *args, **kwargs) -> InferenceBatch: @@ -187,7 +188,7 @@ def configure_pre_processor(cls, image_size: tuple[int, int] | None = None) -> P Examples: Get default pre-processor with custom image size: - >>> preprocessor = AnomalyModule.configure_pre_processor(image_size=(512, 512)) + >>> preprocessor = AnomalibModule.configure_pre_processor(image_size=(512, 512)) Create model with custom pre-processor: @@ -266,10 +267,10 @@ def input_size(self) -> tuple[int, int] | None: @classmethod def from_config( - cls: type["AnomalyModule"], + cls: type["AnomalibModule"], config_path: str | Path, **kwargs, - ) -> "AnomalyModule": + ) -> "AnomalibModule": """Create a model instance from the configuration. Args: @@ -277,20 +278,20 @@ def from_config( **kwargs (dict): Additional keyword arguments. Returns: - AnomalyModule: model instance. + AnomalibModule: model instance. Example: The following example shows how to get model from patchcore.yaml: .. code-block:: python >>> model_config = "configs/model/patchcore.yaml" - >>> model = AnomalyModule.from_config(config_path=model_config) + >>> model = AnomalibModule.from_config(config_path=model_config) The following example shows overriding the configuration file with additional keyword arguments: .. code-block:: python >>> override_kwargs = {"model.pre_trained": False} - >>> model = AnomalyModule.from_config(config_path=model_config, **override_kwargs) + >>> model = AnomalibModule.from_config(config_path=model_config, **override_kwargs) """ from jsonargparse import ActionConfigFile, ArgumentParser from lightning.pytorch import Trainer @@ -308,7 +309,7 @@ def from_config( action=ActionConfigFile, help="Path to a configuration file in json or yaml format.", ) - model_parser.add_subclass_arguments(AnomalyModule, "model", required=False, fail_untyped=False) + model_parser.add_subclass_arguments(AnomalibModule, "model", required=False, fail_untyped=False) model_parser.add_argument("--task", type=TaskType | str, default=TaskType.SEGMENTATION) model_parser.add_argument("--metrics.image", type=list[str] | str | None, default=["F1Score", "AUROC"]) model_parser.add_argument("--metrics.pixel", type=list[str] | str | None, default=None, required=False) @@ -320,8 +321,20 @@ def from_config( config = model_parser.parse_args(args=args) instantiated_classes = model_parser.instantiate_classes(config) model = instantiated_classes.get("model") - if isinstance(model, AnomalyModule): + if isinstance(model, AnomalibModule): return model - msg = f"Model is not an instance of AnomalyModule: {model}" + msg = f"Model is not an instance of AnomalibModule: {model}" raise ValueError(msg) + + +class AnomalyModule(AnomalibModule): + """Deprecated AnomalyModule class. Use AnomalibModule instead.""" + + def __init__(self, *args, **kwargs) -> None: + warnings.warn( + "AnomalyModule is deprecated and will be removed in a future release. Use AnomalibModule instead.", + DeprecationWarning, + stacklevel=2, + ) + super().__init__(*args, **kwargs) diff --git a/src/anomalib/models/image/cfa/lightning_model.py b/src/anomalib/models/image/cfa/lightning_model.py index 154ea4e3e8..ea4bf3a2bd 100644 --- a/src/anomalib/models/image/cfa/lightning_model.py +++ b/src/anomalib/models/image/cfa/lightning_model.py @@ -17,7 +17,7 @@ from anomalib import LearningType from anomalib.data import Batch from anomalib.metrics import Evaluator -from anomalib.models.components import AnomalyModule +from anomalib.models.components import AnomalibModule from anomalib.post_processing import PostProcessor from anomalib.pre_processing import PreProcessor @@ -29,7 +29,7 @@ __all__ = ["Cfa"] -class Cfa(AnomalyModule): +class Cfa(AnomalibModule): """CFA: Coupled-hypersphere-based Feature Adaptation for Target-Oriented Anomaly Localization. Args: diff --git a/src/anomalib/models/image/cflow/lightning_model.py b/src/anomalib/models/image/cflow/lightning_model.py index b6118d8e4e..d6b39751d0 100644 --- a/src/anomalib/models/image/cflow/lightning_model.py +++ b/src/anomalib/models/image/cflow/lightning_model.py @@ -24,7 +24,7 @@ from anomalib import LearningType from anomalib.data import Batch from anomalib.metrics import Evaluator -from anomalib.models.components import AnomalyModule +from anomalib.models.components import AnomalibModule from anomalib.post_processing import PostProcessor from anomalib.pre_processing import PreProcessor @@ -32,7 +32,7 @@ from .utils import get_logp, positional_encoding_2d -class Cflow(AnomalyModule): +class Cflow(AnomalibModule): """PL Lightning Module for the CFLOW algorithm. Args: diff --git a/src/anomalib/models/image/csflow/lightning_model.py b/src/anomalib/models/image/csflow/lightning_model.py index 0ae381c65b..3be936cc90 100644 --- a/src/anomalib/models/image/csflow/lightning_model.py +++ b/src/anomalib/models/image/csflow/lightning_model.py @@ -15,7 +15,7 @@ from anomalib import LearningType from anomalib.data import Batch from anomalib.metrics import Evaluator -from anomalib.models.components import AnomalyModule +from anomalib.models.components import AnomalibModule from anomalib.post_processing import PostProcessor from anomalib.pre_processing import PreProcessor @@ -27,7 +27,7 @@ __all__ = ["Csflow"] -class Csflow(AnomalyModule): +class Csflow(AnomalibModule): """Fully Convolutional Cross-Scale-Flows for Image-based Defect Detection. Args: diff --git a/src/anomalib/models/image/dfkde/lightning_model.py b/src/anomalib/models/image/dfkde/lightning_model.py index 9bd8388d49..d1b1fba497 100644 --- a/src/anomalib/models/image/dfkde/lightning_model.py +++ b/src/anomalib/models/image/dfkde/lightning_model.py @@ -13,7 +13,7 @@ from anomalib import LearningType from anomalib.data import Batch from anomalib.metrics import AUROC, Evaluator, F1Score -from anomalib.models.components import AnomalyModule, MemoryBankMixin +from anomalib.models.components import AnomalibModule, MemoryBankMixin from anomalib.models.components.classification import FeatureScalingMethod from anomalib.post_processing import PostProcessor from anomalib.pre_processing import PreProcessor @@ -23,7 +23,7 @@ logger = logging.getLogger(__name__) -class Dfkde(MemoryBankMixin, AnomalyModule): +class Dfkde(MemoryBankMixin, AnomalibModule): """DFKDE: Deep Feature Kernel Density Estimation. Args: diff --git a/src/anomalib/models/image/dfm/lightning_model.py b/src/anomalib/models/image/dfm/lightning_model.py index b0449d1e69..cc39b4e398 100644 --- a/src/anomalib/models/image/dfm/lightning_model.py +++ b/src/anomalib/models/image/dfm/lightning_model.py @@ -15,7 +15,7 @@ from anomalib import LearningType from anomalib.data import Batch from anomalib.metrics import Evaluator -from anomalib.models.components import AnomalyModule, MemoryBankMixin +from anomalib.models.components import AnomalibModule, MemoryBankMixin from anomalib.post_processing import PostProcessor from anomalib.pre_processing import PreProcessor @@ -24,7 +24,7 @@ logger = logging.getLogger(__name__) -class Dfm(MemoryBankMixin, AnomalyModule): +class Dfm(MemoryBankMixin, AnomalibModule): """DFM: Deep Featured Kernel Density Estimation. Args: diff --git a/src/anomalib/models/image/draem/lightning_model.py b/src/anomalib/models/image/draem/lightning_model.py index a072bcae0f..dd02fd168a 100644 --- a/src/anomalib/models/image/draem/lightning_model.py +++ b/src/anomalib/models/image/draem/lightning_model.py @@ -18,7 +18,7 @@ from anomalib.data import Batch from anomalib.data.utils import Augmenter from anomalib.metrics import Evaluator -from anomalib.models.components import AnomalyModule +from anomalib.models.components import AnomalibModule from anomalib.post_processing import PostProcessor from anomalib.pre_processing import PreProcessor @@ -28,7 +28,7 @@ __all__ = ["Draem"] -class Draem(AnomalyModule): +class Draem(AnomalibModule): """DRÆM: A discriminatively trained reconstruction embedding for surface anomaly detection. Args: diff --git a/src/anomalib/models/image/dsr/lightning_model.py b/src/anomalib/models/image/dsr/lightning_model.py index a5a6071868..23daa6b95d 100644 --- a/src/anomalib/models/image/dsr/lightning_model.py +++ b/src/anomalib/models/image/dsr/lightning_model.py @@ -19,7 +19,7 @@ from anomalib.data.utils import DownloadInfo, download_and_extract from anomalib.data.utils.augmenter import Augmenter from anomalib.metrics import Evaluator -from anomalib.models.components import AnomalyModule +from anomalib.models.components import AnomalibModule from anomalib.models.image.dsr.anomaly_generator import DsrAnomalyGenerator from anomalib.models.image.dsr.loss import DsrSecondStageLoss, DsrThirdStageLoss from anomalib.models.image.dsr.torch_model import DsrModel @@ -37,7 +37,7 @@ ) -class Dsr(AnomalyModule): +class Dsr(AnomalibModule): """DSR: A Dual Subspace Re-Projection Network for Surface Anomaly Detection. Args: diff --git a/src/anomalib/models/image/efficient_ad/lightning_model.py b/src/anomalib/models/image/efficient_ad/lightning_model.py index 88b29f7215..47ace2a073 100644 --- a/src/anomalib/models/image/efficient_ad/lightning_model.py +++ b/src/anomalib/models/image/efficient_ad/lightning_model.py @@ -21,7 +21,7 @@ from anomalib.data import Batch from anomalib.data.utils import DownloadInfo, download_and_extract from anomalib.metrics import Evaluator -from anomalib.models.components import AnomalyModule +from anomalib.models.components import AnomalibModule from anomalib.post_processing import PostProcessor from anomalib.pre_processing import PreProcessor @@ -42,7 +42,7 @@ ) -class EfficientAd(AnomalyModule): +class EfficientAd(AnomalibModule): """PL Lightning Module for the EfficientAd algorithm. Args: diff --git a/src/anomalib/models/image/fastflow/lightning_model.py b/src/anomalib/models/image/fastflow/lightning_model.py index 935df8468d..35a5f8dddb 100644 --- a/src/anomalib/models/image/fastflow/lightning_model.py +++ b/src/anomalib/models/image/fastflow/lightning_model.py @@ -15,7 +15,7 @@ from anomalib import LearningType from anomalib.data import Batch from anomalib.metrics import AUROC, Evaluator, F1Score -from anomalib.models.components import AnomalyModule +from anomalib.models.components import AnomalibModule from anomalib.post_processing import PostProcessor from anomalib.pre_processing import PreProcessor @@ -23,7 +23,7 @@ from .torch_model import FastflowModel -class Fastflow(AnomalyModule): +class Fastflow(AnomalibModule): """PL Lightning Module for the FastFlow algorithm. Args: diff --git a/src/anomalib/models/image/fre/lightning_model.py b/src/anomalib/models/image/fre/lightning_model.py index f3de232667..505beb7f1b 100755 --- a/src/anomalib/models/image/fre/lightning_model.py +++ b/src/anomalib/models/image/fre/lightning_model.py @@ -16,7 +16,7 @@ from anomalib import LearningType from anomalib.data import Batch from anomalib.metrics import Evaluator -from anomalib.models.components import AnomalyModule +from anomalib.models.components import AnomalibModule from anomalib.post_processing import PostProcessor from anomalib.pre_processing import PreProcessor @@ -25,7 +25,7 @@ logger = logging.getLogger(__name__) -class Fre(AnomalyModule): +class Fre(AnomalibModule): """FRE: Feature-reconstruction error using Tied AutoEncoder. Args: diff --git a/src/anomalib/models/image/ganomaly/lightning_model.py b/src/anomalib/models/image/ganomaly/lightning_model.py index de3a479aa8..982bd93d33 100644 --- a/src/anomalib/models/image/ganomaly/lightning_model.py +++ b/src/anomalib/models/image/ganomaly/lightning_model.py @@ -16,7 +16,7 @@ from anomalib import LearningType from anomalib.data import Batch from anomalib.metrics import AUROC, Evaluator, F1Score -from anomalib.models.components import AnomalyModule +from anomalib.models.components import AnomalibModule from anomalib.post_processing import PostProcessor from anomalib.pre_processing import PreProcessor @@ -26,7 +26,7 @@ logger = logging.getLogger(__name__) -class Ganomaly(AnomalyModule): +class Ganomaly(AnomalibModule): """PL Lightning Module for the GANomaly Algorithm. Args: diff --git a/src/anomalib/models/image/padim/lightning_model.py b/src/anomalib/models/image/padim/lightning_model.py index aed2163def..28d59fc9eb 100644 --- a/src/anomalib/models/image/padim/lightning_model.py +++ b/src/anomalib/models/image/padim/lightning_model.py @@ -14,7 +14,7 @@ from anomalib import LearningType from anomalib.data import Batch from anomalib.metrics import Evaluator -from anomalib.models.components import AnomalyModule, MemoryBankMixin +from anomalib.models.components import AnomalibModule, MemoryBankMixin from anomalib.post_processing import OneClassPostProcessor, PostProcessor from anomalib.pre_processing import PreProcessor @@ -25,7 +25,7 @@ __all__ = ["Padim"] -class Padim(MemoryBankMixin, AnomalyModule): +class Padim(MemoryBankMixin, AnomalibModule): """PaDiM: a Patch Distribution Modeling Framework for Anomaly Detection and Localization. Args: diff --git a/src/anomalib/models/image/patchcore/lightning_model.py b/src/anomalib/models/image/patchcore/lightning_model.py index f855a61d8e..d22a97d891 100644 --- a/src/anomalib/models/image/patchcore/lightning_model.py +++ b/src/anomalib/models/image/patchcore/lightning_model.py @@ -17,7 +17,7 @@ from anomalib import LearningType from anomalib.data import Batch from anomalib.metrics import Evaluator -from anomalib.models.components import AnomalyModule, MemoryBankMixin +from anomalib.models.components import AnomalibModule, MemoryBankMixin from anomalib.post_processing import OneClassPostProcessor, PostProcessor from anomalib.pre_processing import PreProcessor @@ -26,7 +26,7 @@ logger = logging.getLogger(__name__) -class Patchcore(MemoryBankMixin, AnomalyModule): +class Patchcore(MemoryBankMixin, AnomalibModule): """PatchcoreLightning Module to train PatchCore algorithm. Args: diff --git a/src/anomalib/models/image/reverse_distillation/lightning_model.py b/src/anomalib/models/image/reverse_distillation/lightning_model.py index a0cd8521f9..e052c864cb 100644 --- a/src/anomalib/models/image/reverse_distillation/lightning_model.py +++ b/src/anomalib/models/image/reverse_distillation/lightning_model.py @@ -15,7 +15,7 @@ from anomalib import LearningType from anomalib.data import Batch from anomalib.metrics import Evaluator -from anomalib.models.components import AnomalyModule +from anomalib.models.components import AnomalibModule from anomalib.post_processing import PostProcessor from anomalib.pre_processing import PreProcessor @@ -24,7 +24,7 @@ from .torch_model import ReverseDistillationModel -class ReverseDistillation(AnomalyModule): +class ReverseDistillation(AnomalibModule): """PL Lightning Module for Reverse Distillation Algorithm. Args: diff --git a/src/anomalib/models/image/rkde/lightning_model.py b/src/anomalib/models/image/rkde/lightning_model.py index 8d618127c0..20a18496fc 100644 --- a/src/anomalib/models/image/rkde/lightning_model.py +++ b/src/anomalib/models/image/rkde/lightning_model.py @@ -15,7 +15,7 @@ from anomalib import LearningType from anomalib.metrics import Evaluator -from anomalib.models.components import AnomalyModule, MemoryBankMixin +from anomalib.models.components import AnomalibModule, MemoryBankMixin from anomalib.models.components.classification import FeatureScalingMethod from anomalib.post_processing import PostProcessor from anomalib.pre_processing import PreProcessor @@ -26,7 +26,7 @@ logger = logging.getLogger(__name__) -class Rkde(MemoryBankMixin, AnomalyModule): +class Rkde(MemoryBankMixin, AnomalibModule): """Region Based Anomaly Detection With Real-Time Training and Analysis. Args: diff --git a/src/anomalib/models/image/stfpm/lightning_model.py b/src/anomalib/models/image/stfpm/lightning_model.py index 32cace71f1..9f37e46239 100644 --- a/src/anomalib/models/image/stfpm/lightning_model.py +++ b/src/anomalib/models/image/stfpm/lightning_model.py @@ -16,7 +16,7 @@ from anomalib import LearningType from anomalib.data import Batch from anomalib.metrics import Evaluator -from anomalib.models.components import AnomalyModule +from anomalib.models.components import AnomalibModule from anomalib.post_processing import PostProcessor from anomalib.pre_processing import PreProcessor @@ -26,7 +26,7 @@ __all__ = ["Stfpm"] -class Stfpm(AnomalyModule): +class Stfpm(AnomalibModule): """PL Lightning Module for the STFPM algorithm. Args: diff --git a/src/anomalib/models/image/uflow/lightning_model.py b/src/anomalib/models/image/uflow/lightning_model.py index ce88d4ae2e..60e7a26752 100644 --- a/src/anomalib/models/image/uflow/lightning_model.py +++ b/src/anomalib/models/image/uflow/lightning_model.py @@ -18,7 +18,7 @@ from anomalib import LearningType from anomalib.data import Batch from anomalib.metrics import Evaluator -from anomalib.models.components import AnomalyModule +from anomalib.models.components import AnomalibModule from anomalib.post_processing import PostProcessor from anomalib.pre_processing import PreProcessor @@ -30,7 +30,7 @@ __all__ = ["Uflow"] -class Uflow(AnomalyModule): +class Uflow(AnomalibModule): """Uflow model. Args: diff --git a/src/anomalib/models/image/vlm_ad/lightning_model.py b/src/anomalib/models/image/vlm_ad/lightning_model.py index 0c072f1330..6e47e58027 100644 --- a/src/anomalib/models/image/vlm_ad/lightning_model.py +++ b/src/anomalib/models/image/vlm_ad/lightning_model.py @@ -11,7 +11,7 @@ from anomalib import LearningType from anomalib.data import ImageBatch from anomalib.metrics import Evaluator, F1Score -from anomalib.models import AnomalyModule +from anomalib.models import AnomalibModule from anomalib.post_processing import PostProcessor from .backends import Backend, ChatGPT, Huggingface, Ollama @@ -20,7 +20,7 @@ logger = logging.getLogger(__name__) -class VlmAd(AnomalyModule): +class VlmAd(AnomalibModule): """Visual anomaly model.""" def __init__( diff --git a/src/anomalib/models/image/winclip/lightning_model.py b/src/anomalib/models/image/winclip/lightning_model.py index 3ce35f46f4..d3f7481df7 100644 --- a/src/anomalib/models/image/winclip/lightning_model.py +++ b/src/anomalib/models/image/winclip/lightning_model.py @@ -19,7 +19,7 @@ from anomalib.data import Batch from anomalib.data.predict import PredictDataset from anomalib.metrics import Evaluator -from anomalib.models.components import AnomalyModule +from anomalib.models.components import AnomalibModule from anomalib.post_processing import OneClassPostProcessor, PostProcessor from anomalib.pre_processing import PreProcessor @@ -30,7 +30,7 @@ __all__ = ["WinClip"] -class WinClip(AnomalyModule): +class WinClip(AnomalibModule): """WinCLIP Lightning model. Args: diff --git a/src/anomalib/models/video/ai_vad/lightning_model.py b/src/anomalib/models/video/ai_vad/lightning_model.py index 9625f4b565..750746f259 100644 --- a/src/anomalib/models/video/ai_vad/lightning_model.py +++ b/src/anomalib/models/video/ai_vad/lightning_model.py @@ -14,7 +14,7 @@ from anomalib import LearningType from anomalib.data import VideoBatch -from anomalib.models.components import AnomalyModule, MemoryBankMixin +from anomalib.models.components import AnomalibModule, MemoryBankMixin from anomalib.post_processing.one_class import OneClassPostProcessor, PostProcessor from anomalib.pre_processing import PreProcessor @@ -25,7 +25,7 @@ __all__ = ["AiVad"] -class AiVad(MemoryBankMixin, AnomalyModule): +class AiVad(MemoryBankMixin, AnomalibModule): """AI-VAD: Attribute-based Representations for Accurate and Interpretable Video Anomaly Detection. Args: diff --git a/src/anomalib/pipelines/benchmark/job.py b/src/anomalib/pipelines/benchmark/job.py index f56899ac5d..d98b689304 100644 --- a/src/anomalib/pipelines/benchmark/job.py +++ b/src/anomalib/pipelines/benchmark/job.py @@ -17,7 +17,7 @@ from anomalib.data import AnomalibDataModule from anomalib.engine import Engine -from anomalib.models import AnomalyModule +from anomalib.models import AnomalibModule from anomalib.pipelines.components import Job from anomalib.utils.logging import hide_output @@ -29,7 +29,7 @@ class BenchmarkJob(Job): Args: accelerator (str): The accelerator to use. - model (AnomalyModule): The model to use. + model (AnomalibModule): The model to use. datamodule (AnomalibDataModule): The data module to use. seed (int): The seed to use. flat_cfg (dict): The flat dictionary of configs with dotted keys. @@ -40,7 +40,7 @@ class BenchmarkJob(Job): def __init__( self, accelerator: str, - model: AnomalyModule, + model: AnomalibModule, datamodule: AnomalibDataModule, seed: int, flat_cfg: dict, diff --git a/src/anomalib/utils/visualization/metrics.py b/src/anomalib/utils/visualization/metrics.py index 48f426ea11..36f4948405 100644 --- a/src/anomalib/utils/visualization/metrics.py +++ b/src/anomalib/utils/visualization/metrics.py @@ -9,7 +9,7 @@ from .base import BaseVisualizer, GeneratorResult, VisualizationStep if TYPE_CHECKING: - from anomalib.models import AnomalyModule + from anomalib.models import AnomalibModule class MetricsVisualizer(BaseVisualizer): @@ -21,7 +21,7 @@ def __init__(self) -> None: @staticmethod def generate(**kwargs) -> Iterator[GeneratorResult]: """Generate metric plots and return them as an iterator.""" - pl_module: AnomalyModule = kwargs.get("pl_module", None) + pl_module: AnomalibModule = kwargs.get("pl_module", None) if pl_module is None: msg = "`pl_module` must be provided" raise ValueError(msg) diff --git a/src/anomalib/visualization/image/visualizer.py b/src/anomalib/visualization/image/visualizer.py index 7c83446ae5..c8eafc8ae8 100644 --- a/src/anomalib/visualization/image/visualizer.py +++ b/src/anomalib/visualization/image/visualizer.py @@ -9,7 +9,7 @@ from lightning.pytorch import Callback, Trainer from anomalib.data import ImageBatch -from anomalib.models import AnomalyModule +from anomalib.models import AnomalibModule from anomalib.utils.path import generate_output_filename from .item_visualizer import ( @@ -138,7 +138,7 @@ def __init__( def on_test_batch_end( self, trainer: Trainer, - pl_module: AnomalyModule, + pl_module: AnomalibModule, outputs: ImageBatch, batch: ImageBatch, batch_idx: int, @@ -176,7 +176,7 @@ def on_test_batch_end( def on_predict_batch_end( self, trainer: Trainer, - pl_module: AnomalyModule, + pl_module: AnomalibModule, outputs: ImageBatch, batch: ImageBatch, batch_idx: int, diff --git a/tests/integration/model/test_models.py b/tests/integration/model/test_models.py index 9c9c203d45..464c2cb1da 100644 --- a/tests/integration/model/test_models.py +++ b/tests/integration/model/test_models.py @@ -15,7 +15,7 @@ from anomalib.data import AnomalibDataModule, MVTec from anomalib.deploy import ExportType from anomalib.engine import Engine -from anomalib.models import AnomalyModule, get_available_models, get_model +from anomalib.models import AnomalibModule, get_available_models, get_model def models() -> set[str]: @@ -165,7 +165,7 @@ def _get_objects( model_name: str, dataset_path: Path, project_path: Path, - ) -> tuple[AnomalyModule, AnomalibDataModule, Engine]: + ) -> tuple[AnomalibModule, AnomalibDataModule, Engine]: """Return model, dataset, and engine objects. Args: @@ -174,7 +174,7 @@ def _get_objects( project_path (Path): path to the temporary project folder Returns: - tuple[AnomalyModule, AnomalibDataModule, Engine]: Returns the created objects for model, dataset, + tuple[AnomalibModule, AnomalibDataModule, Engine]: Returns the created objects for model, dataset, and engine """ # select task type diff --git a/tests/unit/models/components/base/test_anomaly_module.py b/tests/unit/models/components/base/test_anomaly_module.py index c77ab7c212..92e37af5b4 100644 --- a/tests/unit/models/components/base/test_anomaly_module.py +++ b/tests/unit/models/components/base/test_anomaly_module.py @@ -1,4 +1,4 @@ -"""Test AnomalyModule module.""" +"""Test AnomalibModule module.""" # Copyright (C) 2024 Intel Corporation # SPDX-License-Identifier: Apache-2.0 @@ -7,7 +7,7 @@ import pytest -from anomalib.models.components.base import AnomalyModule +from anomalib.models.components.base import AnomalibModule @pytest.fixture(scope="class") @@ -16,19 +16,19 @@ def model_config_folder_path() -> str: return "configs/model" -class TestAnomalyModule: - """Test AnomalyModule.""" +class TestAnomalibModule: + """Test AnomalibModule.""" @pytest.fixture(autouse=True) def setup(self, model_config_folder_path: str) -> None: - """Setup test AnomalyModule.""" + """Setup test AnomalibModule.""" self.model_config_folder_path = model_config_folder_path @staticmethod def test_from_config_with_wrong_config_path() -> None: - """Test AnomalyModule.from_config with wrong model name.""" + """Test AnomalibModule.from_config with wrong model name.""" with pytest.raises(FileNotFoundError): - AnomalyModule.from_config(config_path="wrong_configs.yaml") + AnomalibModule.from_config(config_path="wrong_configs.yaml") @pytest.mark.parametrize( "model_name", @@ -53,8 +53,8 @@ def test_from_config_with_wrong_config_path() -> None: ], ) def test_from_config(self, model_name: str) -> None: - """Test AnomalyModule.from_config.""" + """Test AnomalibModule.from_config.""" config_path = Path(self.model_config_folder_path) / f"{model_name}.yaml" - model = AnomalyModule.from_config(config_path=config_path) + model = AnomalibModule.from_config(config_path=config_path) assert model is not None - assert isinstance(model, AnomalyModule) + assert isinstance(model, AnomalibModule) diff --git a/tests/unit/utils/callbacks/visualizer_callback/dummy_lightning_model.py b/tests/unit/utils/callbacks/visualizer_callback/dummy_lightning_model.py index 33a215f56f..dc9c31e8db 100644 --- a/tests/unit/utils/callbacks/visualizer_callback/dummy_lightning_model.py +++ b/tests/unit/utils/callbacks/visualizer_callback/dummy_lightning_model.py @@ -11,7 +11,7 @@ from anomalib import LearningType from anomalib.data import ImageBatch, InferenceBatch -from anomalib.models.components import AnomalyModule +from anomalib.models.components import AnomalibModule from anomalib.post_processing import PostProcessor @@ -27,7 +27,7 @@ def forward(batch: InferenceBatch) -> InferenceBatch: return batch -class DummyModule(AnomalyModule): +class DummyModule(AnomalibModule): """A dummy model which calls visualizer callback on fake images and masks. TODO(ashwinvaidya17): Remove this when the DummyModels have been refactored. diff --git a/tools/inference/lightning_inference.py b/tools/inference/lightning_inference.py index 400b46ae00..e06c87c281 100644 --- a/tools/inference/lightning_inference.py +++ b/tools/inference/lightning_inference.py @@ -10,7 +10,7 @@ from anomalib.data import PredictDataset from anomalib.engine import Engine -from anomalib.models import AnomalyModule, get_model +from anomalib.models import AnomalibModule, get_model def get_parser() -> LightningArgumentParser: @@ -20,7 +20,7 @@ def get_parser() -> LightningArgumentParser: LightningArgumentParser: The parser object. """ parser = LightningArgumentParser(description="Inference on Anomaly models in Lightning format.") - parser.add_lightning_class_args(AnomalyModule, "model", subclass_mode=True) + parser.add_lightning_class_args(AnomalibModule, "model", subclass_mode=True) parser.add_lightning_class_args(Callback, "--callbacks", subclass_mode=True, required=False) parser.add_argument("--ckpt_path", type=str, required=True, help="Path to model weights") parser.add_class_arguments(PredictDataset, "--data", instantiate=False)