UCSDped Datamodule

UCSDped Datamodule#

UCSD Pedestrian Data Module.

This module provides a PyTorch Lightning data module for the UCSD Pedestrian dataset. The dataset consists of surveillance videos of pedestrians, with anomalies defined as non-pedestrian entities like cars, bikes, etc.

class anomalib.data.datamodules.video.ucsd_ped.UCSDped(root='./datasets/ucsd', category='UCSDped2', clip_length_in_frames=2, frames_between_clips=10, target_frame=VideoTargetFrame.LAST, train_batch_size=8, eval_batch_size=8, num_workers=8, train_augmentations=None, val_augmentations=None, test_augmentations=None, augmentations=None, val_split_mode=ValSplitMode.SAME_AS_TEST, val_split_ratio=0.5, seed=None)#

Bases: AnomalibVideoDataModule

UCSD Pedestrian DataModule Class.

Parameters:
  • root (Path | str) – Path to the root directory where the dataset will be downloaded and extracted. Defaults to "./datasets/ucsd".

  • category (str) – Dataset subcategory. Must be either "UCSDped1" or "UCSDped2". Defaults to "UCSDped2".

  • clip_length_in_frames (int) – Number of frames in each video clip. Defaults to 2.

  • frames_between_clips (int) – Number of frames between consecutive video clips. Defaults to 10.

  • target_frame (VideoTargetFrame) – Specifies which frame in the clip should be used for ground truth. Defaults to VideoTargetFrame.LAST.

  • train_batch_size (int) – Batch size for training. Defaults to 8.

  • eval_batch_size (int) – Batch size for validation and testing. Defaults to 8.

  • num_workers (int) – Number of workers for data loading. Defaults to 8.

  • train_augmentations (Transform | None) – Augmentations to apply dto the training images Defaults to None.

  • val_augmentations (Transform | None) – Augmentations to apply to the validation images. Defaults to None.

  • test_augmentations (Transform | None) – Augmentations to apply to the test images. Defaults to None.

  • augmentations (Transform | None) – General augmentations to apply if stage-specific augmentations are not provided.

  • val_split_mode (ValSplitMode) – Determines how validation set is created. Defaults to ValSplitMode.SAME_AS_TEST.

  • val_split_ratio (float) – Fraction of data to use for validation. Must be between 0 and 1. Defaults to 0.5.

  • seed (int | None) – Random seed for reproducibility. Defaults to None.

Example

>>> datamodule = UCSDped(root="./datasets/ucsd")
>>> datamodule.setup()  # Downloads and prepares the dataset
>>> train_loader = datamodule.train_dataloader()
>>> val_loader = datamodule.val_dataloader()
>>> test_loader = datamodule.test_dataloader()
prepare_data()#

Download and extract the dataset if not already available.

The method checks if the dataset directory exists. If not, it downloads and extracts the dataset to the specified root directory.

Return type:

None