(device, layout, out_of_bounds_policy)
| 764 | ("constant", "const", "pad", "clamp", "edge", "reflect", "reflect_1001", "reflect_101", "wrap"), |
| 765 | ) |
| 766 | def test_border_modes(device, layout, out_of_bounds_policy): |
| 767 | @pipeline_def(batch_size=1, num_threads=4, device_id=0, seed=1234) |
| 768 | def make_pipe(): |
| 769 | file, _ = fn.readers.file( |
| 770 | file_root=os.path.join(test_data_root, "db", "single", "jpeg"), |
| 771 | random_shuffle=False, |
| 772 | ) |
| 773 | img = fn.decoders.image(file, device="mixed" if device == "gpu" else "cpu") |
| 774 | shape = img.shape() |
| 775 | h, w = shape[0], shape[1] |
| 776 | |
| 777 | input = img |
| 778 | |
| 779 | if layout == "CHW": # convert to CHW |
| 780 | input = fn.transpose(input, perm=(2, 0, 1)) |
| 781 | |
| 782 | top = fn.random.uniform(range=fn.stack(1.0 * h, 2.0 * h), dtype=types.INT64) |
| 783 | bottom = fn.random.uniform(range=fn.stack(1.0 * h, 2.0 * h), dtype=types.INT64) |
| 784 | left = fn.random.uniform(range=fn.stack(1.0 * w, 2.0 * w), dtype=types.INT64) |
| 785 | right = fn.random.uniform(range=fn.stack(1.0 * w, 2.0 * w), dtype=types.INT64) |
| 786 | |
| 787 | fill = [0x76, 0xB9, 0x00] if out_of_bounds_policy in ["constant", "const", "pad"] else None |
| 788 | output = fn.crop( |
| 789 | input, |
| 790 | crop_h=h + top + bottom + 0.0, |
| 791 | crop_w=w + left + right + 0.0, |
| 792 | crop_pos_x=left / (left + right), |
| 793 | crop_pos_y=top / (top + bottom), |
| 794 | out_of_bounds_policy=out_of_bounds_policy, |
| 795 | fill_values=fill, |
| 796 | ) |
| 797 | |
| 798 | if layout == "CHW": |
| 799 | output = fn.transpose(output, perm=(1, 2, 0)) |
| 800 | |
| 801 | return img, output, fn.stack(left, top, right, bottom) |
| 802 | |
| 803 | pipe = make_pipe() |
| 804 | inputs, outputs, margins = pipe.run() |
| 805 | if device == "gpu": |
| 806 | inputs = inputs.as_cpu() |
| 807 | outputs = outputs.as_cpu() |
| 808 | margins = margins.as_cpu() |
| 809 | |
| 810 | for i in range(len(inputs)): |
| 811 | in_img = as_array(inputs[i]) |
| 812 | out_img = as_array(outputs[i]) |
| 813 | h, w = in_img.shape[:2] |
| 814 | l, t, r, b = as_array(margins[i]) |
| 815 | ref = cv2.copyMakeBorder( |
| 816 | in_img, t, b, l, r, to_cv_border_type(out_of_bounds_policy), None, [0x76, 0xB9, 0x00] |
| 817 | ) |
| 818 | if not np.array_equal(ref, out_img): |
| 819 | dump_as_core_artifacts( |
| 820 | f"border_mode_{out_of_bounds_policy}_{layout}_{device}_{i}", out_img, ref |
| 821 | ) |
| 822 | assert np.array_equal(ref, out_img) |
nothing calls this directly
no test coverage detected