Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix CPU resize with mixed NN/other resampling filters. #5647

Merged
merged 3 commits into from
Sep 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions dali/kernels/imgproc/resample/separable_cpu.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2019-2021, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
// Copyright (c) 2019-2021, 2024, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -96,7 +96,7 @@ struct ResamplingSetupCPU : SeparableResamplingSetup<_spatial_ndim> {

for (int stage = 0; stage < num_stages; stage++) {
size_t extent = resized_dim_extent(stage);
size_t support = filter_support(stage);
int support = std::max(0, filter_support(stage)); // support() returns -1 for NN interp.
size_t num_coeffs = extent * support;

if (extent > req.indices_size)
Expand Down
46 changes: 46 additions & 0 deletions dali/test/python/operator_2/test_resize.py
Original file line number Diff line number Diff line change
Expand Up @@ -843,6 +843,52 @@ def resize_pipe():
assert np.max(np.abs(out - large_data_resized)) < 2


@params(("cpu", 0), ("cpu", 1), ("gpu", 0), ("gpu", 1))
def test_nn_on_one_axis(device, axis):
# Checks whether having NN interpolation in one axis and full resampling in the other works
data = np.array(
[
[0, 0, 0],
[0, 1, 0],
[0, 2, 0],
],
dtype=np.float32,
)

# magnification is NN, minification is triangular
ref = np.array(
[
[0, 0, 0.3333334, 0.3333334, 0, 0],
[0, 0, 1.6666667, 1.6666667, 0, 0],
],
dtype=np.float32,
)

if axis == 1:
data = np.transpose(data, (1, 0))
ref = np.transpose(ref, (1, 0))

# add channel
data = data[..., np.newaxis]
ref = ref[..., np.newaxis]

@pipeline_def(batch_size=1, device_id=0, num_threads=1)
def test_pipe():
src = dali.types.Constant(data, device=device)
return fn.resize(
src,
size=ref.shape[:-1],
min_filter=dali.types.INTERP_LINEAR,
mag_filter=dali.types.INTERP_NN,
antialias=True,
)

pipe = test_pipe()
pipe.build()
(out,) = pipe.run()
check_batch(out, [ref], 1, 1e-5, 1e-5, None, False)


def test_checkerboard_dali_vs_onnx_ref():
improc_data_dir = os.path.join(test_data_root, "db", "imgproc")
ref_dir = os.path.join(improc_data_dir, "ref", "resampling")
Expand Down
Loading