def _test_scalar(device, as_tensors): """Test propagation of scalars from external source""" batch_size = 4 src_pipe = Pipeline(batch_size, 1, 0) src_ext = fn.external_source( source=lambda i: [np.float32(i * 10 + i + 1) for i in range(batch_size)], device=device) src_pipe.set_outputs(src_ext) src_pipe.build() dst_pipe = Pipeline(batch_size, 1, 0, exec_async=False, exec_pipelined=False) dst_pipe.set_outputs(fn.external_source(name="ext", device=device)) dst_pipe.build() for iter in range(3): src = src_pipe.run() data = src[0] if as_tensors: data = [data[i] for i in range(len(data))] dst_pipe.feed_input("ext", data) dst = dst_pipe.run() check_batch(src[0], dst[0], batch_size, 0, 0, "")
def _test_feed_input(device): src_pipe, batch_size = build_src_pipe(device) dst_pipe = Pipeline(batch_size, 1, 0, exec_async=False, exec_pipelined=False) dst_pipe.set_outputs(fn.external_source(name="ext", device=device)) dst_pipe.build() for iter in range(3): out1 = src_pipe.run() dst_pipe.feed_input("ext", out1[0]) out2 = dst_pipe.run() check_batch(out2[0], out1[0], batch_size, 0, 0, "XY")
class DaliChecker: def __init__(self, batch_size, prefetch=2, device="mixed", device_id=0): log.debug("making checker") self.batch_size = batch_size self.prefetch = prefetch self.device = device self.device_id = device_id self.make_pipe() self.pipe.build() def make_pipe(self): log.debug("making pipe") self.pipe = Pipeline(batch_size=self.batch_size, num_threads=2, device_id=self.device_id, prefetch_queue_depth=self.prefetch) with self.pipe: self.files = fn.external_source() images = fn.image_decoder(self.files, device=self.device) self.pipe.set_outputs(images) def feed(self, images): self.pipe.feed_input(self.files, images)
def test_layout_changing(): src_pipe = Pipeline(1, 1, 0) src_pipe.set_outputs(fn.external_source(name="input")) src_pipe.build() src_pipe.feed_input("input", [np.zeros((1))], layout="W") src_pipe.feed_input("input", [np.zeros((1))], layout="H")