ShanghaiTech Datamodule#
ShanghaiTech Campus Data Module.
This module provides a PyTorch Lightning DataModule for the ShanghaiTech Campus dataset. If the dataset is not available locally, it will be downloaded and extracted automatically. The video files are also converted to a format readable by pyav.
Example
Create a ShanghaiTech datamodule:
>>> from anomalib.data import ShanghaiTech
>>> datamodule = ShanghaiTech(
... root="./datasets/shanghaitech",
... scene=1,
... 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', 'label'])
Notes
The directory structure after preparation will be:
root/
├── testing/
│ ├── frames/
│ ├── test_frame_mask/
│ └── test_pixel_mask/
└── training/
├── frames/
├── converted_videos/
└── videos/
- License:
ShanghaiTech Campus Dataset is released under the BSD 2-Clause License.
- Reference:
Liu, W., Luo, W., Lian, D., & Gao, S. (2018). Future frame prediction for anomaly detection–a new baseline. In Proceedings of the IEEE conference on computer vision and pattern recognition (pp. 6536-6545).
- class anomalib.data.datamodules.video.shanghaitech.ShanghaiTech(root='./datasets/shanghaitech', scene=1, 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:
AnomalibVideoDataModuleShanghaiTech DataModule class.
- Parameters:
root (
Path|str|None) – Path to the root directory of the dataset. Defaults to"./datasets/shanghaitech".scene (
int) – Scene index in range [1, 13]. Defaults to1.clip_length_in_frames (
int) – Number of frames in each video clip. Defaults to2.frames_between_clips (
int) – Number of frames between consecutive clips. Defaults to1.target_frame (
VideoTargetFrame) – Specifies which frame in the clip should be used 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 for data loading. 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) – Setting that determines how validation subset is obtained. Defaults toValSplitMode.SAME_AS_TEST.val_split_ratio (
float) – Fraction of train or test images that will be reserved for validation. Defaults to0.5.seed (
int|None) – Random seed for reproducibility. Defaults toNone.