MCPcopy Create free account
hub / github.com/UX-Decoder/Semantic-SAM / build_detection_test_loader

Function build_detection_test_loader

datasets/build.py:188–250  ·  view source on GitHub ↗

Similar to `build_detection_train_loader`, with default batch size = 1, and sampler = :class:`InferenceSampler`. This sampler coordinates all workers to produce the exact set of all samples. Args: dataset: a list of dataset dicts, or a pytorch dataset (either ma

(
    dataset: Union[List[Any], torchdata.Dataset],
    *,
    mapper: Callable[[Dict[str, Any]], Any],
    sampler: Optional[torchdata.Sampler] = None,
    batch_size: int = 1,
    num_workers: int = 0,
    collate_fn: Optional[Callable[[List[Any]], Any]] = None,
)

Source from the content-addressed store, hash-verified

186
187@configurable(from_config=_test_loader_from_config)
188def build_detection_test_loader(
189 dataset: Union[List[Any], torchdata.Dataset],
190 *,
191 mapper: Callable[[Dict[str, Any]], Any],
192 sampler: Optional[torchdata.Sampler] = None,
193 batch_size: int = 1,
194 num_workers: int = 0,
195 collate_fn: Optional[Callable[[List[Any]], Any]] = None,
196) -> torchdata.DataLoader:
197 """
198 Similar to `build_detection_train_loader`, with default batch size = 1,
199 and sampler = :class:`InferenceSampler`. This sampler coordinates all workers
200 to produce the exact set of all samples.
201
202 Args:
203 dataset: a list of dataset dicts,
204 or a pytorch dataset (either map-style or iterable). They can be obtained
205 by using :func:`DatasetCatalog.get` or :func:`get_detection_dataset_dicts`.
206 mapper: a callable which takes a sample (dict) from dataset
207 and returns the format to be consumed by the model.
208 When using cfg, the default choice is ``DatasetMapper(cfg, is_train=False)``.
209 sampler: a sampler that produces
210 indices to be applied on ``dataset``. Default to :class:`InferenceSampler`,
211 which splits the dataset across all workers. Sampler must be None
212 if `dataset` is iterable.
213 batch_size: the batch size of the data loader to be created.
214 Default to 1 image per worker since this is the standard when reporting
215 inference time in papers.
216 num_workers: number of parallel data loading workers
217 collate_fn: same as the argument of `torch.utils.data.DataLoader`.
218 Defaults to do no collation and return a list of data.
219
220 Returns:
221 DataLoader: a torch DataLoader, that loads the given detection
222 dataset, with test-time transformation and batching.
223
224 Examples:
225 ::
226 data_loader = build_detection_test_loader(
227 DatasetRegistry.get("my_test"),
228 mapper=DatasetMapper(...))
229
230 # or, instantiate with a CfgNode:
231 data_loader = build_detection_test_loader(cfg, "my_test")
232 """
233
234 if isinstance(dataset, list):
235 dataset = DatasetFromList(dataset, copy=False)
236 if mapper is not None:
237 dataset = MapDataset(dataset, mapper)
238 if isinstance(dataset, torchdata.IterableDataset):
239 assert sampler is None, "sampler must be None if dataset is IterableDataset"
240 else:
241 if sampler is None:
242 sampler = InferenceSampler(len(dataset))
243 return torchdata.DataLoader(
244 dataset,
245 batch_size=batch_size,

Callers 1

build_eval_dataloaderFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected