Constructs the data loader for the given dataset. Args: cfg (CfgNode): configs. Details can be found in slowfast/config/defaults.py split (str): the split of the data loader. Options include `train`, `val`, and `test`.
(cfg, split, is_precise_bn=False)
| 83 | |
| 84 | |
| 85 | def construct_loader(cfg, split, is_precise_bn=False): |
| 86 | """ |
| 87 | Constructs the data loader for the given dataset. |
| 88 | Args: |
| 89 | cfg (CfgNode): configs. Details can be found in |
| 90 | slowfast/config/defaults.py |
| 91 | split (str): the split of the data loader. Options include `train`, |
| 92 | `val`, and `test`. |
| 93 | """ |
| 94 | assert split in ["train", "val", "test"] |
| 95 | if split in ["train"]: |
| 96 | dataset_name = cfg.TRAIN.DATASET |
| 97 | batch_size = int(cfg.TRAIN.BATCH_SIZE / max(1, cfg.NUM_GPUS)) |
| 98 | shuffle = True |
| 99 | drop_last = True |
| 100 | elif split in ["val"]: |
| 101 | dataset_name = cfg.TRAIN.DATASET |
| 102 | batch_size = int(cfg.TRAIN.BATCH_SIZE / max(1, cfg.NUM_GPUS)) |
| 103 | shuffle = False |
| 104 | drop_last = False |
| 105 | elif split in ["test"]: |
| 106 | dataset_name = cfg.TEST.DATASET |
| 107 | batch_size = int(cfg.TEST.BATCH_SIZE / max(1, cfg.NUM_GPUS)) |
| 108 | shuffle = False |
| 109 | drop_last = False |
| 110 | |
| 111 | # Construct the dataset |
| 112 | dataset = build_dataset(dataset_name, cfg, split) |
| 113 | |
| 114 | if isinstance(dataset, torch.utils.data.IterableDataset): |
| 115 | loader = torch.utils.data.DataLoader( |
| 116 | dataset, |
| 117 | batch_size=batch_size, |
| 118 | num_workers=cfg.DATA_LOADER.NUM_WORKERS, |
| 119 | pin_memory=cfg.DATA_LOADER.PIN_MEMORY, |
| 120 | drop_last=drop_last, |
| 121 | collate_fn=detection_collate if cfg.DETECTION.ENABLE else None, |
| 122 | worker_init_fn=utils.loader_worker_init_fn(dataset), |
| 123 | persistent_workers=True |
| 124 | ) |
| 125 | else: |
| 126 | if ( |
| 127 | cfg.MULTIGRID.SHORT_CYCLE |
| 128 | and split in ["train"] |
| 129 | and not is_precise_bn |
| 130 | ): |
| 131 | # Create a sampler for multi-process training |
| 132 | sampler = utils.create_sampler(dataset, shuffle, cfg) |
| 133 | batch_sampler = ShortCycleBatchSampler( |
| 134 | sampler, batch_size=batch_size, drop_last=drop_last, cfg=cfg |
| 135 | ) |
| 136 | # Create a loader |
| 137 | loader = torch.utils.data.DataLoader( |
| 138 | dataset, |
| 139 | batch_sampler=batch_sampler, |
| 140 | num_workers=cfg.DATA_LOADER.NUM_WORKERS, |
| 141 | pin_memory=cfg.DATA_LOADER.PIN_MEMORY, |
| 142 | worker_init_fn=utils.loader_worker_init_fn(dataset), |
nothing calls this directly
no test coverage detected