Build a dataloader for object detection with some default features. This interface is experimental. Args: dataset (list or torch.utils.data.Dataset): a list of dataset dicts, or a map-style pytorch dataset. They can be obtained by using :func:`DatasetCat
(
dataset, *, mapper, sampler=None, total_batch_size, aspect_ratio_grouping=True, num_workers=0
)
| 282 | |
| 283 | @configurable(from_config=_train_loader_from_config) |
| 284 | def build_detection_train_loader( |
| 285 | dataset, *, mapper, sampler=None, total_batch_size, aspect_ratio_grouping=True, num_workers=0 |
| 286 | ): |
| 287 | """ |
| 288 | Build a dataloader for object detection with some default features. |
| 289 | This interface is experimental. |
| 290 | |
| 291 | Args: |
| 292 | dataset (list or torch.utils.data.Dataset): a list of dataset dicts, |
| 293 | or a map-style pytorch dataset. They can be obtained by using |
| 294 | :func:`DatasetCatalog.get` or :func:`get_detection_dataset_dicts`. |
| 295 | mapper (callable): a callable which takes a sample (dict) from dataset and |
| 296 | returns the format to be consumed by the model. |
| 297 | When using cfg, the default choice is ``DatasetMapper(cfg, is_train=True)``. |
| 298 | sampler (torch.utils.data.sampler.Sampler or None): a sampler that |
| 299 | produces indices to be applied on ``dataset``. |
| 300 | Default to :class:`TrainingSampler`, which coordinates a random shuffle |
| 301 | sequence across all workers. |
| 302 | total_batch_size (int): total batch size across all workers. Batching |
| 303 | simply puts data into a list. |
| 304 | aspect_ratio_grouping (bool): whether to group images with similar |
| 305 | aspect ratio for efficiency. When enabled, it requires each |
| 306 | element in dataset be a dict with keys "width" and "height". |
| 307 | num_workers (int): number of parallel data loading workers |
| 308 | |
| 309 | Returns: |
| 310 | torch.utils.data.DataLoader: a dataloader. Each output from it is a |
| 311 | ``list[mapped_element]`` of length ``total_batch_size / num_workers``, |
| 312 | where ``mapped_element`` is produced by the ``mapper``. |
| 313 | """ |
| 314 | if isinstance(dataset, list): |
| 315 | dataset = DatasetFromList(dataset, copy=False) |
| 316 | if mapper is not None: |
| 317 | dataset = MapDataset(dataset, mapper) |
| 318 | if sampler is None: |
| 319 | sampler = TrainingSampler(len(dataset)) |
| 320 | assert isinstance(sampler, torch.utils.data.sampler.Sampler) |
| 321 | |
| 322 | return build_batch_data_loader( |
| 323 | dataset, |
| 324 | sampler, |
| 325 | total_batch_size, |
| 326 | aspect_ratio_grouping=aspect_ratio_grouping, |
| 327 | num_workers=num_workers, |
| 328 | ) |
| 329 | |
| 330 | |
| 331 | def get_config_from_name(cfg, dataset_name): |
no outgoing calls
no test coverage detected