albumentations.augmentations.other.temporal


Transforms for temporal image sequences.

UniformTemporalSubsampleclass

UniformTemporalSubsample(
    num_frames: int,
    p: float = 1.0
)

Select uniformly spaced frames to give videos a fixed sequence length for training or inference, repeating frames from shorter clips. Args: num_frames (int): Number of output frames. Must be positive. Requests longer than the input repeat frames. A request for one frame selects the first frame. p (float): Probability of applying the transform. Default: 1.0. Targets: images, masks, bboxes, keypoints Image types: uint8, float32 Note: - The `images` target is the temporal sequence. Supply NumPy videos as (T, H, W, C) or (T, H, W), and CPU Tensors as (T, C, H, W). - With at least two output frames, both endpoints are included. Intermediate evenly spaced positions are rounded down to frame indices. - Use Compose(frame_binding=["images", "masks"]) for one semantic mask per frame, or frame_binding=["images", "frame_annotations"] for per-frame dictionaries containing masks, bboxes, keypoints, or instances. Bound annotations follow the selected frames. Examples: >>> import albumentations as A >>> import numpy as np >>> video = np.zeros((24, 64, 96, 3), dtype=np.uint8) >>> masks = np.zeros((24, 64, 96), dtype=np.uint8) >>> transform = A.Compose( ... [A.UniformTemporalSubsample(num_frames=8)], ... frame_binding=["images", "masks"], ... ) >>> result = transform(images=video, masks=masks) >>> result["images"].shape, result["masks"].shape ((8, 64, 96, 3), (8, 64, 96)) Preprocess a video for classification with temporal selection, spatial augmentation, and normalization: >>> preprocess = A.Compose( ... [ ... A.UniformTemporalSubsample(num_frames=8), ... A.RandomResizedCrop(size=(224, 224), scale=(0.8, 1.0)), ... A.HorizontalFlip(p=0.5), ... A.Normalize(mean=(0.45, 0.45, 0.45), std=(0.225, 0.225, 0.225)), ... ], ... seed=137, ... ) >>> preprocess(images=video)["images"].shape (8, 224, 224, 3)

Parameters

NameTypeDefaultDescription
num_framesint--
pfloat1.0-