MCPcopy Create free account
hub / github.com/PeizeSun/SparseR-CNN / build_detection_test_loader

Function build_detection_test_loader

detectron2/data/build.py:407–448  ·  view source on GitHub ↗

Similar to `build_detection_train_loader`, but uses a batch size of 1. 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:`Dataset

(dataset, *, mapper, num_workers=0)

Source from the content-addressed store, hash-verified

405
406@configurable(from_config=_test_loader_from_config)
407def build_detection_test_loader(dataset, *, mapper, num_workers=0):
408 """
409 Similar to `build_detection_train_loader`, but uses a batch size of 1.
410 This interface is experimental.
411
412 Args:
413 dataset (list or torch.utils.data.Dataset): a list of dataset dicts,
414 or a map-style pytorch dataset. They can be obtained by using
415 :func:`DatasetCatalog.get` or :func:`get_detection_dataset_dicts`.
416 mapper (callable): a callable which takes a sample (dict) from dataset
417 and returns the format to be consumed by the model.
418 When using cfg, the default choice is ``DatasetMapper(cfg, is_train=False)``.
419 num_workers (int): number of parallel data loading workers
420
421 Returns:
422 DataLoader: a torch DataLoader, that loads the given detection
423 dataset, with test-time transformation and batching.
424
425 Examples:
426 ::
427 data_loader = build_detection_test_loader(
428 DatasetRegistry.get("my_test"),
429 mapper=DatasetMapper(...))
430
431 # or, instantiate with a CfgNode:
432 data_loader = build_detection_test_loader(cfg, "my_test")
433 """
434 if isinstance(dataset, list):
435 dataset = DatasetFromList(dataset, copy=False)
436 if mapper is not None:
437 dataset = MapDataset(dataset, mapper)
438 sampler = InferenceSampler(len(dataset))
439 # Always use 1 image per worker during inference since this is the
440 # standard when reporting inference time in papers.
441 batch_sampler = torch.utils.data.sampler.BatchSampler(sampler, 1, drop_last=False)
442 data_loader = torch.utils.data.DataLoader(
443 dataset,
444 num_workers=num_workers,
445 batch_sampler=batch_sampler,
446 collate_fn=trivial_batch_collator,
447 )
448 return data_loader
449
450
451def trivial_batch_collator(batch):

Callers 6

do_testFunction · 0.90
benchmark_evalFunction · 0.90
do_flopFunction · 0.90
do_activationFunction · 0.90
build_test_loaderMethod · 0.90

Calls 3

DatasetFromListClass · 0.85
MapDatasetClass · 0.85
InferenceSamplerClass · 0.85

Tested by

no test coverage detected