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

Function check_prepare_first_batch

dali/test/python/test_fw_iterators.py:1608–1649  ·  view source on GitHub ↗
(Iterator, *args, to_np=None, **kwargs)

Source from the content-addressed store, hash-verified

1606
1607
1608def check_prepare_first_batch(Iterator, *args, to_np=None, **kwargs):
1609 max_batch_size = 4
1610 iter_limit = 4
1611 runs = 3
1612 test_data_shape = [2, 3, 4]
1613 i = 0
1614 dataset = [
1615 [
1616 [
1617 np.random.randint(0, 255, size=test_data_shape, dtype=np.uint8)
1618 for _ in range(max_batch_size)
1619 ]
1620 ]
1621 for _ in range(iter_limit)
1622 ]
1623
1624 def get_data():
1625 nonlocal i
1626 if i == iter_limit:
1627 i = 0
1628 raise StopIteration
1629 out = dataset[i]
1630 i += 1
1631 return out
1632
1633 pipe = Pipeline(batch_size=max_batch_size, num_threads=1, device_id=0)
1634 with pipe:
1635 outs = fn.external_source(source=get_data, num_outputs=1)
1636 pipe.set_outputs(*outs)
1637
1638 it = Iterator([pipe], *args, auto_reset=True, prepare_first_batch=False, **kwargs)
1639 counter = 0
1640 for r in range(runs):
1641 if r == 0:
1642 # when prepare_first_batch=False pipeline should not be run until first call to next(it)
1643 assert i == 0, "external_source should not be run yet"
1644 for j, data in enumerate(it):
1645 if not isinstance(data, dict):
1646 data = data[0]
1647 assert (to_np(data) == np.concatenate(dataset[j])).all()
1648 counter += 1
1649 assert counter == iter_limit * runs
1650
1651
1652@attr("pytorch")

Calls 4

set_outputsMethod · 0.95
PipelineClass · 0.90
IteratorClass · 0.85
allMethod · 0.80

Tested by

no test coverage detected