MCPcopy Create free account
hub / github.com/CompVis/flow-poke-transformer / make_loader

Method make_loader

myriad/data_2d.py:435–496  ·  view source on GitHub ↗
(
        self,
        shards: str,
        batch_size: int,
        num_workers: int,
        shuffle: int = 0,
    )

Source from the content-addressed store, hash-verified

433 return valid
434
435 def make_loader(
436 self,
437 shards: str,
438 batch_size: int,
439 num_workers: int,
440 shuffle: int = 0,
441 ):
442 # resolve base directories
443 base_dirs = self.tar_base
444 if isinstance(base_dirs, (str, Path)):
445 base_dirs = [base_dirs]
446 elif isinstance(base_dirs, ListConfig):
447 base_dirs = OmegaConf.to_object(base_dirs)
448 elif isinstance(base_dirs, list):
449 base_dirs = base_dirs
450 else:
451 raise NotImplementedError(f'Tar base is of type {type(base_dirs)} which is not supported as of now')
452
453 base_dirs = [Path(b).expanduser().resolve() for b in base_dirs]
454
455 # search for shards
456 if shards is None:
457 shard_urls = [
458 str(p) for base in base_dirs for p in base.rglob("*.tar")
459 ]
460 else:
461 if isinstance(shards, ListConfig):
462 shards = OmegaConf.to_object(shards)
463 if isinstance(shards, (list, tuple)):
464 patterns = shards
465 else: # a single string
466 patterns = [shards]
467
468 shard_urls = []
469 for base in base_dirs:
470 for pat in patterns:
471 full_pat = str(base / pat)
472 matches = glob.glob(full_pat)
473 shard_urls.extend(matches)
474
475 if len(shard_urls) == 0:
476 raise FileNotFoundError("No shards matched patterns")
477
478 shard_urls = list(set(shard_urls)) # deduplicate
479 shard_urls.sort() # sort
480
481 # data pipeline
482 dataset = wds.DataPipeline(
483 wds.SimpleShardList(shard_urls),
484 wds.detshuffle() if self.shuffle else lambda x: x,
485 wds.split_by_node,
486 wds.split_by_worker,
487 partial(wds.tarfile_samples, handler=wds.warn_and_continue),
488 *([wds.shuffle(shuffle)] if shuffle != 0 and self.shuffle else []),
489 wds.map(self._decode),
490 wds.select(self._filter_valid),
491 wds.batched(batch_size, partial=False, collation_fn=dict_collation_fn),
492 )

Callers 2

train_dataloaderMethod · 0.95
val_dataloaderMethod · 0.95

Calls

no outgoing calls

Tested by

no test coverage detected