(dim, backend)
| 761 | |
| 762 | |
| 763 | def _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 | |
| 802 | def test_empty_input(): |
nothing calls this directly
no test coverage detected