UCSD Data#
UCSD Pedestrian dataset.
- class anomalib.data.video.ucsd_ped.UCSDped(root='./datasets/ucsd', category='UCSDped2', clip_length_in_frames=2, frames_between_clips=10, target_frame=VideoTargetFrame.LAST, task=TaskType.SEGMENTATION, image_size=None, transform=None, train_transform=None, eval_transform=None, train_batch_size=8, eval_batch_size=8, num_workers=8, val_split_mode=ValSplitMode.SAME_AS_TEST, val_split_ratio=0.5, seed=None)#
Bases:
AnomalibVideoDataModule
UCSDped DataModule class.
- Parameters:
root (Path | str) – Path to the root of the dataset
category (str) – Sub-category of the dataset, e.g. “UCSDped1” or “UCSDped2”
clip_length_in_frames (int, optional) – Number of video frames in each clip.
frames_between_clips (int, optional) – Number of frames between each consecutive video clip.
target_frame (VideoTargetFrame) – Specifies the target frame in the video clip, used for ground truth retrieval
task (TaskType) – Task type, ‘classification’, ‘detection’ or ‘segmentation’
image_size (tuple[int, int], optional) – Size to which input images should be resized. Defaults to
None
.transform (Transform, optional) – Transforms that should be applied to the input images. Defaults to
None
.train_transform (Transform, optional) – Transforms that should be applied to the input images during training. Defaults to
None
.eval_transform (Transform, optional) – Transforms that should be applied to the input images during evaluation. Defaults to
None
.train_batch_size (int, optional) – Training batch size. Defaults to 32.
eval_batch_size (int, optional) – Test batch size. Defaults to 32.
num_workers (int, optional) – Number of workers. Defaults to 8.
val_split_mode (ValSplitMode) – Setting that determines how the validation subset is obtained.
val_split_ratio (float) – Fraction of train or test images that will be reserved for validation.
seed (int | None, optional) – Seed which may be set to a fixed value for reproducibility.
- prepare_data()#
Download the dataset if not available.
- Return type:
None
- class anomalib.data.video.ucsd_ped.UCSDpedClipsIndexer(video_paths, mask_paths, clip_length_in_frames=2, frames_between_clips=1)#
Bases:
ClipsIndexer
Clips class for UCSDped dataset.
- get_clip(idx)#
Get a subclip from a list of videos.
- Parameters:
idx (int) – index of the subclip. Must be between 0 and num_clips().
- Return type:
tuple
[Tensor
,Tensor
,dict
[str
,Any
],int
]- Returns:
video (torch.Tensor) audio (torch.Tensor) info (dict) video_idx (int): index of the video in video_paths
- get_mask(idx)#
Retrieve the masks from the file system.
- Return type:
ndarray
|None
- class anomalib.data.video.ucsd_ped.UCSDpedDataset(task, root, category, split, clip_length_in_frames=2, frames_between_clips=10, target_frame=VideoTargetFrame.LAST, transform=None)#
Bases:
AnomalibVideoDataset
UCSDped Dataset class.
- Parameters:
task (TaskType) – Task type, ‘classification’, ‘detection’ or ‘segmentation’
root (Path | str) – Path to the root of the dataset
category (str) – Sub-category of the dataset, e.g. “UCSDped1” or “UCSDped2”
split (str | Split | None) – Split of the dataset, usually Split.TRAIN or Split.TEST
clip_length_in_frames (int, optional) – Number of video frames in each clip.
frames_between_clips (int, optional) – Number of frames between each consecutive video clip.
target_frame (VideoTargetFrame) – Specifies the target frame in the video clip, used for ground truth retrieval.
transform (Transform, optional) – Transforms that should be applied to the input images. Defaults to
None
.
- anomalib.data.video.ucsd_ped.make_ucsd_dataset(path, split=None)#
Create UCSD Pedestrian dataset by parsing the file structure.
- The files are expected to follow the structure:
path/to/dataset/category/split/video_id/image_filename.tif path/to/dataset/category/split/video_id_gt/mask_filename.bmp
- Parameters:
path (Path) – Path to dataset
split (str | Split | None, optional) – Dataset split (ie., either train or test). Defaults to None.
Example
The following example shows how to get testing samples from UCSDped2 category:
>>> root = Path('./UCSDped') >>> category = 'UCSDped2' >>> path = root / category >>> path PosixPath('UCSDped/UCSDped2')
>>> samples = make_ucsd_dataset(path, split='test') >>> samples.head() root folder image_path mask_path split 0 UCSDped/UCSDped2 Test UCSDped/UCSDped2/Test/Test001 UCSDped/UCSDped2/Test/Test001_gt test 1 UCSDped/UCSDped2 Test UCSDped/UCSDped2/Test/Test002 UCSDped/UCSDped2/Test/Test002_gt test ...
- Returns:
an output dataframe containing samples for the requested split (ie., train or test)
- Return type:
DataFrame