Build DataLoader using iterable dataset
(
cls,
data_path_and_name_and_type,
preprocess_fn,
collate_fn,
key_file: Optional[str] = None,
batch_size: int = 1,
dtype: Optional[Any] = np.float32,
num_workers: int = 1,
allow_variable_data_keys: bool = False,
ngpu: int = 0,
inference: bool = False,
mode: Optional[str] = None,
multi_task_dataset: bool = False,
)
| 2397 | @classmethod |
| 2398 | @typechecked |
| 2399 | def build_streaming_iterator( |
| 2400 | cls, |
| 2401 | data_path_and_name_and_type, |
| 2402 | preprocess_fn, |
| 2403 | collate_fn, |
| 2404 | key_file: Optional[str] = None, |
| 2405 | batch_size: int = 1, |
| 2406 | dtype: Optional[Any] = np.float32, |
| 2407 | num_workers: int = 1, |
| 2408 | allow_variable_data_keys: bool = False, |
| 2409 | ngpu: int = 0, |
| 2410 | inference: bool = False, |
| 2411 | mode: Optional[str] = None, |
| 2412 | multi_task_dataset: bool = False, |
| 2413 | ) -> DataLoader: |
| 2414 | """Build DataLoader using iterable dataset""" |
| 2415 | # For backward compatibility for pytorch DataLoader |
| 2416 | if collate_fn is not None: |
| 2417 | kwargs = dict(collate_fn=collate_fn) |
| 2418 | else: |
| 2419 | kwargs = {} |
| 2420 | |
| 2421 | if multi_task_dataset: |
| 2422 | dataset_class = ESPnetMultiTaskDataset |
| 2423 | else: |
| 2424 | dataset_class = IterableESPnetDataset |
| 2425 | dataset = dataset_class( |
| 2426 | data_path_and_name_and_type, |
| 2427 | float_dtype=dtype, |
| 2428 | preprocess=preprocess_fn, |
| 2429 | key_file=key_file, |
| 2430 | ) |
| 2431 | |
| 2432 | if dataset.apply_utt2category: |
| 2433 | kwargs.update(batch_size=1) |
| 2434 | else: |
| 2435 | kwargs.update(batch_size=batch_size) |
| 2436 | |
| 2437 | cls.check_task_requirements( |
| 2438 | dataset, allow_variable_data_keys, train=False, inference=inference |
| 2439 | ) |
| 2440 | |
| 2441 | return DataLoader( |
| 2442 | dataset=dataset, |
| 2443 | pin_memory=ngpu > 0, |
| 2444 | num_workers=num_workers, |
| 2445 | sampler=getattr(dataset, "example_list", None), |
| 2446 | **kwargs, |
| 2447 | ) |
| 2448 | |
| 2449 | # ~~~~~~~~~ The methods below are mainly used for inference ~~~~~~~~~ |
| 2450 | @classmethod |
no test coverage detected