torchvideo.samplers¶
Samplers¶
Different video models use different strategies in sampling frames: some use sparse sampling strategies (like TSN, TRN) whereas others like 3D CNNs use dense sampling strategies. In order to accommodate these different architectures we offer a variety of sampling strategies with the opportunity to implement your own.
FrameSampler¶
ClipSampler¶
-
class
torchvideo.samplers.ClipSampler(clip_length, frame_step=1, test=False)[source]¶ Bases:
torchvideo.samplers.FrameSamplerSample clips of a fixed duration uniformly randomly from a video.
- Parameters
clip_length (
int) – Duration of clip in framesframe_step (
int) – The step size between frames, this controls FPS reduction, a step size of 2 will halve FPS, step size of 3 will reduce FPS to 1/3.test (
bool) – Whether or not to sample in test mode (in test mode the central clip is sampled from the video)
FullVideoSampler¶
-
class
torchvideo.samplers.FullVideoSampler(frame_step=1)[source]¶ Bases:
torchvideo.samplers.FrameSamplerSample all frames in a video.
- Parameters
frame_step – The step size between frames, this controls FPS reduction, a step size of 2 will halve FPS, step size of 3 will reduce FPS to 1/3.
TemporalSegmentSampler¶
-
class
torchvideo.samplers.TemporalSegmentSampler(segment_count, snippet_length, *, sample_count=None, test=False)[source]¶ Bases:
torchvideo.samplers.FrameSampler[TSN] style sampling.
The video is equally divided into a number of segments,
segment_countand from within each segment a snippet, a contiguous sequence of frames,snippet_lengthfr+ames long is sampled.There are two variants of sampling. One for training and one for testing. During training the snippet location within the segment is uniformly randomly sampled. During testing snippets are sampled centrally within their segment (i.e. deterministically).
[TSN] Uses the following configurations:
Network
Train/Test
segment_countsnippet_lengthRGB
Train
3
1
Test
25
1
Flow
Train
3
5
Test
25
5
- Parameters
segment_count (
int) – Number of segments to split the video into, from which a snippet is sampled.snippet_length (
int) – The number of frames in each snippetsample_count (
Optional[int]) – Override the number of samples to be drawn from the segments, by default the sampler will sample a total ofsegment_countsnippets from the video. In some cases it can be useful to sample fewer than this (effectively choosingsample_countsnippets fromsegment_count).test (
bool) – Whether to sample in test mode or not (see class docstring for training/testing differences)
LambdaSampler¶
-
class
torchvideo.samplers.LambdaSampler(sampler)[source]¶ Bases:
torchvideo.samplers.FrameSamplerCustom sampler constructed from a user provided function.