Base Datamodules#
Anomalib datamodule base class.
- class anomalib.data.base.datamodule.AnomalibDataModule(train_batch_size, eval_batch_size, num_workers, val_split_mode, val_split_ratio, test_split_mode=None, test_split_ratio=None, seed=None)#
Bases:
LightningDataModule,ABCBase Anomalib data module.
- Parameters:
train_batch_size (int) – Batch size used by the train dataloader.
eval_batch_size (int) – Batch size used by the val and test dataloaders.
num_workers (int) – Number of workers used by the train, val and test dataloaders.
val_split_mode (ValSplitMode) – Determines how the validation split is obtained. Options: [none, same_as_test, from_test, synthetic]
val_split_ratio (float) – Fraction of the train or test images held our for validation.
test_split_mode (Optional[TestSplitMode], optional) – Determines how the test split is obtained. Options: [none, from_dir, synthetic]. Defaults to
None.test_split_ratio (float) – Fraction of the train images held out for testing. Defaults to
None.seed (int | None, optional) – Seed used during random subset splitting. Defaults to
None.
- property is_setup: bool#
Checks if setup() has been called.
At least one of [train_data, val_data, test_data] should be setup.
- predict_dataloader()#
Use the test dataloader for inference unless overridden.
- Return type:
Any
- setup(stage=None)#
Set up train, validation and test data.
- Parameters:
stage (
Optional[str]) – str | None: Train/Val/Test stages. Defaults toNone.- Return type:
None
- test_dataloader()#
Get test dataloader.
- Return type:
Any
- train_dataloader()#
Get train dataloader.
- Return type:
Any
- val_dataloader()#
Get validation dataloader.
- Return type:
Any
- anomalib.data.base.datamodule.collate_fn(batch)#
Collate bounding boxes as lists.
Bounding boxes are collated as a list of tensors, while the default collate function is used for all other entries.
- Parameters:
batch (List) – list of items in the batch where len(batch) is equal to the batch size.
- Returns:
Dictionary containing the collated batch information.
- Return type:
dict[str, Any]