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

Function _test_empty_input

dali/test/python/operator_2/test_resize.py:763–799  ·  view source on GitHub ↗
(dim, backend)

Source from the content-addressed store, hash-verified

761
762
763def _test_empty_input(dim, backend):
764 batch_size = 8
765 pipe = Pipeline(batch_size=batch_size, num_threads=8, device_id=0, seed=1234)
766 if dim == 2:
767 files, labels = dali.fn.readers.caffe(path=db_2d_folder, random_shuffle=True)
768 images_cpu = dali.fn.decoders.image(files, device="cpu")
769 else:
770 images_cpu = dali.fn.external_source(source=random_3d_loader(batch_size), layout="DHWC")
771
772 images = images_cpu if backend_device(backend) == "cpu" else images_cpu.gpu()
773
774 in_rel_shapes = np.ones([batch_size, dim], dtype=np.float32)
775
776 in_rel_shapes[::2, :] *= 0 # all zeros in every second sample
777
778 degenerate_images = fn.slice(
779 images, np.zeros([dim]), fn.external_source(lambda: in_rel_shapes), axes=list(range(dim))
780 )
781
782 sizes = np.random.randint(20, 50, [batch_size, dim], dtype=np.int32)
783 size_inp = fn.external_source(lambda: [x.astype(np.float32) for x in sizes])
784
785 resize_no_empty = resize_op(backend)(images, size=size_inp, mode="not_larger")
786 resize_with_empty = resize_op(backend)(degenerate_images, size=size_inp, mode="not_larger")
787
788 pipe.set_outputs(resize_no_empty, resize_with_empty)
789
790 for it in range(3):
791 out_no_empty, out_with_empty = pipe.run()
792 if backend_device(backend) == "gpu":
793 out_no_empty = out_no_empty.as_cpu()
794 out_with_empty = out_with_empty.as_cpu()
795 for i in range(batch_size):
796 if i % 2 != 0:
797 assert np.array_equal(out_no_empty.at(i), out_with_empty.at(i))
798 else:
799 assert np.prod(out_with_empty.at(i).shape) == 0
800
801
802def test_empty_input():

Callers

nothing calls this directly

Calls 9

set_outputsMethod · 0.95
runMethod · 0.95
PipelineClass · 0.90
random_3d_loaderClass · 0.85
backend_deviceFunction · 0.85
resize_opFunction · 0.85
gpuMethod · 0.45
sliceMethod · 0.45
atMethod · 0.45

Tested by

no test coverage detected