(device, layout, out_of_bounds_policy)
| 1228 | ("constant", "const", "pad", "clamp", "edge", "reflect", "reflect_1001", "reflect_101", "wrap"), |
| 1229 | ) |
| 1230 | def test_border_modes(device, layout, out_of_bounds_policy): |
| 1231 | @pipeline_def(batch_size=10, num_threads=4, device_id=0, seed=1234) |
| 1232 | def make_pipe(): |
| 1233 | file, _ = fn.readers.file( |
| 1234 | file_root=os.path.join(test_data_root, "db", "single", "jpeg"), |
| 1235 | random_shuffle=False, |
| 1236 | ) |
| 1237 | img = fn.decoders.image(file, device="mixed" if device == "gpu" else "cpu") |
| 1238 | shape = img.shape() |
| 1239 | h, w = shape[0], shape[1] |
| 1240 | |
| 1241 | input = img |
| 1242 | |
| 1243 | if layout == "CHW": # convert to CHW |
| 1244 | input = fn.transpose(input, perm=(2, 0, 1)) |
| 1245 | |
| 1246 | top = fn.random.uniform(range=fn.stack(1.0 * h, 2.0 * h), dtype=types.INT64) |
| 1247 | bottom = fn.random.uniform(range=fn.stack(1.0 * h, 2.0 * h), dtype=types.INT64) |
| 1248 | left = fn.random.uniform(range=fn.stack(1.0 * w, 2.0 * w), dtype=types.INT64) |
| 1249 | right = fn.random.uniform(range=fn.stack(1.0 * w, 2.0 * w), dtype=types.INT64) |
| 1250 | |
| 1251 | anchor = fn.stack(-left, -top) |
| 1252 | shape = fn.stack(w + left + right, h + top + bottom) |
| 1253 | fill = [0x76, 0xB9, 0x00] if out_of_bounds_policy in ["constant", "const", "pad"] else None |
| 1254 | output = fn.slice( |
| 1255 | input, |
| 1256 | anchor, |
| 1257 | shape, |
| 1258 | axis_names="WH", |
| 1259 | out_of_bounds_policy=out_of_bounds_policy, |
| 1260 | fill_values=fill, |
| 1261 | ) |
| 1262 | |
| 1263 | if layout == "CHW": # convert back to HWC |
| 1264 | output = fn.transpose(output, perm=(1, 2, 0)) |
| 1265 | |
| 1266 | return img, output, fn.stack(left, top, right, bottom) |
| 1267 | |
| 1268 | pipe = make_pipe() |
| 1269 | inputs, outputs, margins = pipe.run() |
| 1270 | if device == "gpu": |
| 1271 | inputs = inputs.as_cpu() |
| 1272 | outputs = outputs.as_cpu() |
| 1273 | margins = margins.as_cpu() |
| 1274 | |
| 1275 | for i in range(len(inputs)): |
| 1276 | in_img = as_array(inputs[i]) |
| 1277 | out_img = as_array(outputs[i]) |
| 1278 | h, w = in_img.shape[:2] |
| 1279 | l, t, r, b = as_array(margins[i]) |
| 1280 | ref = cv2.copyMakeBorder( |
| 1281 | in_img, t, b, l, r, to_cv_border_type(out_of_bounds_policy), None, [0x76, 0xB9, 0x00] |
| 1282 | ) |
| 1283 | if not np.array_equal(ref, out_img): |
| 1284 | dump_as_core_artifacts( |
| 1285 | f"border_mode_{out_of_bounds_policy}_{layout}_{device}_{i}", out_img, ref |
| 1286 | ) |
| 1287 | assert np.array_equal(ref, out_img) |
nothing calls this directly
no test coverage detected