Construct the MiT video loader with a given csv file. The format of the csv file is: ``` path_to_video_1 label_1 path_to_video_2 label_2 ... path_to_video_N label_N ``` Args: cfg (CfgNode): configs. mode
(self, cfg, mode, num_retries=10)
| 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 |
| 81 | self.use_temporal_gradient = False |
| 82 | self.temporal_gradient_rate = 0.0 |
| 83 | |
| 84 | if self.mode == "train" and self.cfg.AUG.ENABLE: |
| 85 | self.aug = True |
| 86 | if self.cfg.AUG.RE_PROB > 0: |
| 87 | self.rand_erase = True |
| 88 | |
| 89 | def _construct_loader(self): |
| 90 | """ |
nothing calls this directly
no test coverage detected