(cfg, *, mapper=None, dataset=None, sampler=None)
| 299 | |
| 300 | |
| 301 | def _train_loader_from_config(cfg, *, mapper=None, dataset=None, sampler=None): |
| 302 | if dataset is None: |
| 303 | dataset = get_detection_dataset_dicts( |
| 304 | cfg.DATASETS.TRAIN, |
| 305 | filter_empty=cfg.DATALOADER.FILTER_EMPTY_ANNOTATIONS, |
| 306 | min_keypoints=cfg.MODEL.ROI_KEYPOINT_HEAD.MIN_KEYPOINTS_PER_IMAGE |
| 307 | if cfg.MODEL.KEYPOINT_ON |
| 308 | else 0, |
| 309 | proposal_files=cfg.DATASETS.PROPOSAL_FILES_TRAIN if cfg.MODEL.LOAD_PROPOSALS else None, |
| 310 | ) |
| 311 | |
| 312 | if mapper is None: |
| 313 | mapper = DatasetMapper(cfg, True) |
| 314 | |
| 315 | if sampler is None: |
| 316 | sampler_name = cfg.DATALOADER.SAMPLER_TRAIN |
| 317 | logger = logging.getLogger(__name__) |
| 318 | logger.info("Using training sampler {}".format(sampler_name)) |
| 319 | if sampler_name == "TrainingSampler": |
| 320 | sampler = TrainingSampler(len(dataset)) |
| 321 | elif sampler_name == "RepeatFactorTrainingSampler": |
| 322 | repeat_factors = RepeatFactorTrainingSampler.repeat_factors_from_category_frequency( |
| 323 | dataset, cfg.DATALOADER.REPEAT_THRESHOLD |
| 324 | ) |
| 325 | sampler = RepeatFactorTrainingSampler(repeat_factors) |
| 326 | else: |
| 327 | raise ValueError("Unknown training sampler: {}".format(sampler_name)) |
| 328 | |
| 329 | return { |
| 330 | "dataset": dataset, |
| 331 | "sampler": sampler, |
| 332 | "mapper": mapper, |
| 333 | "total_batch_size": cfg.SOLVER.IMS_PER_BATCH, |
| 334 | "aspect_ratio_grouping": cfg.DATALOADER.ASPECT_RATIO_GROUPING, |
| 335 | "num_workers": cfg.DATALOADER.NUM_WORKERS, |
| 336 | } |
| 337 | |
| 338 | |
| 339 | # TODO can allow dataset as an iterable or IterableDataset to make this function more general |
nothing calls this directly
no test coverage detected