MCPcopy Create free account
hub / github.com/OpenGVLab/UniFormerV2 / Mit

Class Mit

slowfast/datasets/mit.py:23–420  ·  view source on GitHub ↗

MiT video loader. Construct the MiT video loader, then sample clips from the videos. For training and validation, a single clip is randomly sampled from every video with random cropping, scaling, and flipping. For testing, multiple clips are uniformaly sampled from every video w

Source from the content-addressed store, hash-verified

21
22@DATASET_REGISTRY.register()
23class Mit(torch.utils.data.Dataset):
24 """
25 MiT video loader. Construct the MiT video loader, then sample
26 clips from the videos. For training and validation, a single clip is
27 randomly sampled from every video with random cropping, scaling, and
28 flipping. For testing, multiple clips are uniformaly sampled from every
29 video with uniform cropping. For uniform cropping, we take the left, center,
30 and right crop if the width is larger than height, or take top, center, and
31 bottom crop if the height is larger than the width.
32 """
33
34 def __init__(self, cfg, mode, num_retries=10):
35 """
36 Construct the MiT video loader with a given csv file. The format of
37 the csv file is:
38 ```
39 path_to_video_1 label_1
40 path_to_video_2 label_2
41 ...
42 path_to_video_N label_N
43 ```
44 Args:
45 cfg (CfgNode): configs.
46 mode (string): Options includes `train`, `val`, or `test` mode.
47 For the train and val mode, the data loader will take data
48 from the train or val set, and sample one clip per video.
49 For the test mode, the data loader will take data from test set,
50 and sample multiple clips per video.
51 num_retries (int): number of retries.
52 """
53 # Only support train, val, and test mode.
54 assert mode in [
55 "train",
56 "val",
57 "test",
58 ], "Split '{}' not supported for MiT".format(mode)
59 self.mode = mode
60 self.cfg = cfg
61
62 self._video_meta = {}
63 self._num_retries = num_retries
64 # For training or validation mode, one single clip is sampled from every
65 # video. For testing, NUM_ENSEMBLE_VIEWS clips are sampled from every
66 # video. For every clip, NUM_SPATIAL_CROPS is cropped spatially from
67 # the frames.
68 if self.mode in ["train", "val"]:
69 self._num_clips = 1
70 cfg.TEST.NUM_ENSEMBLE_VIEWS = 1
71 cfg.TEST.NUM_SPATIAL_CROPS = 1
72 elif self.mode in ["test"]:
73 self._num_clips = (
74 cfg.TEST.NUM_ENSEMBLE_VIEWS * cfg.TEST.NUM_SPATIAL_CROPS
75 )
76
77 logger.info("Constructing MiT {}...".format(mode))
78 self._construct_loader()
79 self.aug = False
80 self.rand_erase = False

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected