Avenue Datamodule#
CUHK Avenue Data Module.
This module provides a PyTorch Lightning DataModule for the CUHK Avenue dataset. If
the dataset is not already present on the file system, the DataModule class will
download and extract the dataset, converting the .mat mask files to .png
format.
Example
Create an Avenue datamodule:
>>> from anomalib.data import Avenue
>>> datamodule = Avenue(
... root="./datasets/avenue",
... clip_length_in_frames=2,
... frames_between_clips=1,
... )
>>> datamodule.setup()
>>> i, data = next(enumerate(datamodule.train_dataloader()))
>>> data.keys()
dict_keys(['image', 'video_path', 'frames', 'last_frame', 'original_image'])
Notes
The directory structure after preparation will be:
root/
├── ground_truth_demo/
│ ├── ground_truth_show.m
│ ├── Readme.txt
│ ├── testing_label_mask/
│ └── testing_videos/
├── testing_videos/
│ ├── ...
│ └── 21.avi
├── testing_vol/
│ ├── ...
│ └── vol21.mat
├── training_videos/
│ ├── ...
│ └── 16.avi
└── training_vol/
├── ...
└── vol16.mat
- License:
The CUHK Avenue dataset is released for academic research only. For licensing details, see the original dataset website.
- Reference:
Lu, Cewu, Jianping Shi, and Jiaya Jia. “Abnormal event detection at 150 fps in Matlab.” In Proceedings of the IEEE International Conference on Computer Vision, 2013.
- class anomalib.data.datamodules.video.avenue.Avenue(root='./datasets/avenue', gt_dir='./datasets/avenue/ground_truth_demo', clip_length_in_frames=2, frames_between_clips=1, target_frame=VideoTargetFrame.LAST, train_batch_size=32, eval_batch_size=32, 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:
AnomalibVideoDataModuleAvenue DataModule class.
- Parameters:
root (
Path|str|None) – Path to the root of the dataset. Defaults to"./datasets/avenue".gt_dir (
Path|str|None) – Path to the ground truth files. Defaults to"./datasets/avenue/ground_truth_demo".clip_length_in_frames (
int) – Number of video frames in each clip. Defaults to2.frames_between_clips (
int) – Number of frames between consecutive clips. Defaults to1.target_frame (
VideoTargetFrame|str) – Target frame in clip for ground truth. Defaults toVideoTargetFrame.LAST.train_batch_size (
int) – Training batch size. Defaults to32.eval_batch_size (
int) – Test batch size. Defaults to32.num_workers (
int) – Number of workers. Defaults to8.train_augmentations (
Transform|None) – Augmentations to apply to the training images Defaults toNone.val_augmentations (
Transform|None) – Augmentations to apply to the validation images. Defaults toNone.test_augmentations (
Transform|None) – Augmentations to apply to the test images. Defaults toNone.augmentations (
Transform|None) – General augmentations to apply if stage-specific augmentations are not provided.val_split_mode (
ValSplitMode|str) – How validation subset is obtained. Defaults toValSplitMode.SAME_AS_TEST.val_split_ratio (
float) – Fraction of data reserved for validation. Defaults to0.5.seed (
int|None) – Seed for reproducibility. Defaults toNone.
Example
Create a dataloader for classification:
>>> datamodule = Avenue( ... clip_length_in_frames=2, ... frames_between_clips=1, ... target_frame=VideoTargetFrame.LAST ... ) >>> datamodule.setup() >>> i, data = next(enumerate(datamodule.train_dataloader())) >>> data["image"].shape torch.Size([32, 2, 3, 256, 256])
Notes
The dataloader returns batches of clips, where each clip contains
clip_length_in_framesconsecutive frames.frames_between_clipsdetermines frame spacing between clips.target_framespecifies which frame provides ground truth.- prepare_data()#
Download the dataset if not available.
This method checks if the specified dataset is available in the file system. If not, it downloads and extracts the dataset into the appropriate directory.
- Return type:
Example
Assume the dataset is not available on the file system:
>>> datamodule = Avenue() >>> datamodule.prepare_data()
The directory structure after preparation will be:
datasets/ └── avenue/ ├── ground_truth_demo/ │ ├── ground_truth_show.m │ ├── Readme.txt │ ├── testing_label_mask/ │ └── testing_videos/ ├── testing_videos/ │ ├── ... │ └── 21.avi ├── testing_vol/ │ ├── ... │ └── vol21.mat ├── training_videos/ │ ├── ... │ └── 16.avi └── training_vol/ ├── ... └── vol16.mat