otx.algorithms.anomaly.adapters.anomalib.data#

Initialization of Anomaly Dataset Utils.

Classes

OTXAnomalyDataModule(config, dataset, task_type)

Anomaly DataModule.

class otx.algorithms.anomaly.adapters.anomalib.data.OTXAnomalyDataModule(config: DictConfig | ListConfig, dataset: DatasetEntity, task_type: TaskType)[source]#

Bases: LightningDataModule

Anomaly DataModule.

This class converts OTX Dataset into Anomalib dataset and stores train/val/test dataloaders.

Parameters:
  • config (Union[DictConfig, ListConfig]) – Anomalib config

  • dataset (DatasetEntity) – OTX SDK Dataset

Example

>>> from tests.helpers.dataset import OTXAnomalyDatasetGenerator
>>> from otx.utils.data import AnomalyDataModule
>>> dataset_generator = OTXAnomalyDatasetGenerator()
>>> dataset = dataset_generator.generate()
>>> data_module = OTXAnomalyDataModule(config=config, dataset=dataset)
>>> i, data = next(enumerate(data_module.train_dataloader()))
>>> data["image"].shape
torch.Size([32, 3, 256, 256])
prepare_data_per_node#

If True, each LOCAL_RANK=0 will call prepare data. Otherwise only NODE_RANK=0, LOCAL_RANK=0 will prepare data.

allow_zero_length_dataloader_with_multiple_devices#

If True, dataloader with zero length within local rank is allowed. Default value is False.

predict_dataloader() DataLoader | List[DataLoader][source]#

Predict Dataloader.

Returns:

Predict Dataloader.

Return type:

Union[DataLoader, List[DataLoader]]

setup(stage: str | None = None) None[source]#

Setup Anomaly Data Module.

Parameters:

stage (Optional[str], optional) – train/val/test stages. Defaults to None.

summary()[source]#

Print size of the dataset, number of anomalous images and number of normal images.

test_dataloader() DataLoader | List[DataLoader][source]#

Test Dataloader.

Returns:

Test Dataloader.

Return type:

Union[DataLoader, List[DataLoader]]

train_dataloader() DataLoader | List[DataLoader] | Dict[str, DataLoader][source]#

Train Dataloader.

Returns:

Train dataloader.

Return type:

Union[DataLoader, List[DataLoader], Dict[str, DataLoader]]

val_dataloader() DataLoader | List[DataLoader][source]#

Validation Dataloader.

Returns:

Validation Dataloader.

Return type:

Union[DataLoader, List[DataLoader]]