MCPcopy Create free account
hub / github.com/NVIDIA/DALI / RandomDataIterator

Class RandomDataIterator

dali/test/python/test_utils.py:413–440  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

411
412
413class RandomDataIterator(object):
414 def __init__(self, batch_size, shape=(10, 600, 800, 3), dtype=None, seed=0):
415 import_numpy()
416 # to avoid any numpy reference in the interface
417 if dtype is None:
418 dtype = np.uint8
419 self.batch_size = batch_size
420 self.test_data = []
421 self.np_rng = np.random.default_rng(seed=seed)
422 for _ in range(self.batch_size):
423 if dtype == np.float32:
424 self.test_data.append(
425 np.array(self.np_rng.random(shape) * (1.0), dtype=dtype) - 0.5
426 )
427 else:
428 self.test_data.append(np.array(self.np_rng.random(shape) * 255, dtype=dtype))
429
430 def __iter__(self):
431 self.i = 0
432 self.n = self.batch_size
433 return self
434
435 def __next__(self):
436 batch = self.test_data
437 self.i = (self.i + 1) % self.n
438 return batch
439
440 next = __next__
441
442
443class RandomlyShapedDataIterator(object):

Calls

no outgoing calls