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

Support trilinear sampling in Resize CPU and CUDA kernels #5300

Merged
merged 5 commits into from
Oct 2, 2020

Conversation

hariharans29
Copy link
Member

Description: Support 3-D input (or 5-D input with outermost 2 scales being 1.0 - batched multi-channel volumes [N,C, D, H, W]) for the "Linear" mode in the CPU and CUDA Resize kernels

Motivation and Context
Support a first party ONNX model in ORT

@hariharans29 hariharans29 requested a review from a team as a code owner September 25, 2020 23:37
@@ -363,8 +385,8 @@ void UpsampleBilinear(int64_t batch_size,
in_x1[x] = std::min(static_cast<int64_t>(in_x), input_width - 1);
in_x2[x] = std::min(in_x1[x] + 1, input_width - 1);

dx1[x] = std::abs(in_x - in_x1[x]);
dx2[x] = std::abs(in_x - in_x2[x]);
dx1[x] = std::fabs(in_x - in_x1[x]);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For consistency's sake - we use fabs everywhere else in this file

@@ -197,7 +197,66 @@ TEST(ResizeOpTest, ResizeOpLineartUpSampleTest_2DBilinear_align_corners) {
test.Run();
}

TEST(ResizeOpTest, ResizeOpLineartScalesNoOpTest) {
TEST(ResizeOpTest, ResizeOpLinearDownSampleTest_3DTrilinear_pytorch_half_pixel) {
Copy link
Member Author

@hariharans29 hariharans29 Sep 25, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

3D input + downsample

test.Run(OpTester::ExpectResult::kExpectSuccess, "", {kTensorrtExecutionProvider}); // TensorRT: results mismatch
}

TEST(ResizeOpTest, ResizeOpLinearUpSampleTest_5DTrilinear_pytorch_half_pixel) {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

5D input + upsample

@@ -23,7 +23,7 @@ void ResizeImpl(
TArray<int64_t>& input_strides,
TArray<fast_divmod>& output_div_pitches,
TArray<float>& scales_vals,
TArray<float>& roi,
TArray<float, 10>& roi,
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

default capacity is 8 which doesn't compile when input is 5D and roi vector contains 10 elements

@@ -310,24 +310,46 @@ void UpsampleBilinear(int64_t batch_size,
AllocatorPtr& alloc,
GetOriginalCoordinateFunc get_original_coordinate) {
std::vector<float> y_original;
y_original.reserve(output_height);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

best to reserve memory - we know the number of elements that we are going to put into this container.

@askhade
Copy link
Contributor

askhade commented Sep 30, 2020

Can you validate these newly supported scenarios using onnx's implementation of resize. Basically use the test data from your test cases with the resize implementation here https://github.com/onnx/onnx/blob/master/onnx/backend/test/case/node/resize.py and see whether the output's match.
This will help to validate whether the implementation in ort matches the spec.

@hariharans29
Copy link
Member Author

hariharans29 commented Oct 1, 2020

Can you validate these newly supported scenarios using onnx's implementation of resize. Basically use the test data from your test cases with the resize implementation here https://github.com/onnx/onnx/blob/master/onnx/backend/test/case/node/resize.py and see whether the output's match.
This will help to validate whether the implementation in ort matches the spec.

I believe I did that for the upsampling test. Let me run the downsampling test data for completeness’ sake.

@hariharans29
Copy link
Member Author

Can you validate these newly supported scenarios using onnx's implementation of resize. Basically use the test data from your test cases with the resize implementation here https://github.com/onnx/onnx/blob/master/onnx/backend/test/case/node/resize.py and see whether the output's match.
This will help to validate whether the implementation in ort matches the spec.

I believe I did that for the upsampling test. Let me run the downsampling test data foe completeness’ sake.

I ran both the test inputs to the interpolate_nd() method from the script that has the reference implementation and the results matched the expected output in the tests

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants