From 5c8151d651f0a390d9833ced0d932ec2f5b9336c Mon Sep 17 00:00:00 2001 From: Brian Pickrell Date: Fri, 25 Oct 2024 16:14:08 +0000 Subject: [PATCH] update roialign max pooling test; learned that onnxruntime Gold values are incorrect --- test/onnx/gen_onnx.py | 10 +++--- test/onnx/parse/roialign_default_test.cpp | 1 - test/onnx/roialign_half_pixel_test.onnx | 16 +++++----- .../roialign_half_pixel_verify_test.cpp | 32 ++++++++++++------- test/ref/roialign.cpp | 27 ++++++++-------- 5 files changed, 48 insertions(+), 38 deletions(-) diff --git a/test/onnx/gen_onnx.py b/test/onnx/gen_onnx.py index 272f5747ee..62af0db9e3 100644 --- a/test/onnx/gen_onnx.py +++ b/test/onnx/gen_onnx.py @@ -10642,15 +10642,15 @@ def roialign_test(): mode="avg", coordinate_transformation_mode="output_half_pixel") - return ([node], [x, roi, bi]) + return ([node], [x, roi, bi], [y]) @onnx_test() def roialign_half_pixel_test(): - x = helper.make_tensor_value_info('x', TensorProto.FLOAT, [5, 2, 5, 4]) - roi = helper.make_tensor_value_info('rois', TensorProto.FLOAT, [4, 4]) - bi = helper.make_tensor_value_info('batch_ind', TensorProto.INT64, [4]) - y = helper.make_tensor_value_info('y', TensorProto.FLOAT, [2, 4, 5, 5]) + x = helper.make_tensor_value_info('x', TensorProto.FLOAT, [2, 2, 4, 3]) + roi = helper.make_tensor_value_info('rois', TensorProto.FLOAT, [2, 4]) + bi = helper.make_tensor_value_info('batch_ind', TensorProto.INT64, [2]) + y = helper.make_tensor_value_info('y', TensorProto.FLOAT, [3, 2, 2, 2]) # half_pixel is the newer mode for ROIAlign node = onnx.helper.make_node('RoiAlign', diff --git a/test/onnx/parse/roialign_default_test.cpp b/test/onnx/parse/roialign_default_test.cpp index 9a14778c12..9506925ded 100644 --- a/test/onnx/parse/roialign_default_test.cpp +++ b/test/onnx/parse/roialign_default_test.cpp @@ -48,7 +48,6 @@ TEST_CASE(roialign_default_test) EXPECT(p == prog); } - TEST_CASE(roialign_default_12_test) { // opset 12 version diff --git a/test/onnx/roialign_half_pixel_test.onnx b/test/onnx/roialign_half_pixel_test.onnx index a34c903214..f9daf594bd 100644 --- a/test/onnx/roialign_half_pixel_test.onnx +++ b/test/onnx/roialign_half_pixel_test.onnx @@ -12,21 +12,21 @@ half_pixel spatial_scalefff? roialign_half_pixel_testZ x  -  - -Z + + +Z rois  - + Z batch_ind  -b +b y  +  - - -B \ No newline at end of file + +B \ No newline at end of file diff --git a/test/onnx/verify/roialign_half_pixel_verify_test.cpp b/test/onnx/verify/roialign_half_pixel_verify_test.cpp index 9b64fa55da..df515cb37c 100644 --- a/test/onnx/verify/roialign_half_pixel_verify_test.cpp +++ b/test/onnx/verify/roialign_half_pixel_verify_test.cpp @@ -52,10 +52,13 @@ TEST_CASE(roialign_half_pixel_verify_test) result.visit([&](auto output) { result_vector.assign(output.begin(), output.end()); }); // Gold values were generated with onnxruntime - std::vector gold = {5.38, 5.4799995, 5.4799995, 6.58, 6.68, 6.68, - 17.38, 17.48, 17.48, 18.58, 18.68, 18.68, - 29.454998, 14.74, 0., 30.654999, 15.34, 0., - 41.455, 20.74, 0., 42.655003, 21.34, 0.}; + std::vector gold = {1.276, 1.546, 1.6359999, 1.9059999, 1.9959998, 2.2659998, + + 13.276001, 13.546, 13.636, 13.906, 13.996, 14.266, + + 25.478498, 26.1535, 25.838501, 26.5135, 26.198502, 26.8735, + + 37.4785, 38.1535, 37.8385, 38.5135, 38.1985, 38.8735}; EXPECT(migraphx::verify::verify_rms_range(result_vector, gold)); } @@ -85,14 +88,21 @@ TEST_CASE(roialign_half_pixel_max_verify_test) std::vector result_vector; result.visit([&](auto output) { result_vector.assign(output.begin(), output.end()); }); - // Gold values were generated with onnxruntime - std::vector gold = {4.7, 4.7, 4.7, 5.2799997, 5.2799997, 5.2799997, - + // Note: these Gold values have not been cross-checked with onnxruntime because + // at the time of writing, onnxruntime is reporting a bug in its own max pooling + // feature (onnxruntime commit f25f3868a75d4422cde0090abc2781a5277e8eee). Ref. the + // following log message in onnxruntime/core/providers/cpu/object_detection/roialign.h: + // // TODO(fdwr): Issue #6146. ORT 1.13 will correct the incorrect summation of max mode with + // PR #7354. LOGS_DEFAULT(WARNING) << "The existing summation for max mode and sampling ratios + // besides 1 is incorrect " + // << "and will be fixed in the next ORT 1.13 release. Thus the results + // of RoiAlign " + // << "will be different."; + // TODO for AMDMIGraphX: Recheck the gold values when onnxruntime fix is released + std::vector gold = {4.700000, 4.700000, 4.700000, 5.280000, 5.280000, 5.280000, 15.979999, 15.979999, 15.979999, 13.199999, 13.199999, 13.199999, - - 27.477499, 27.477499, 0., 19.440002, 19.440002, 0., - - 38.8475, 38.8475, 0., 26.730003, 26.730003, 0.}; + 27.259998, 27.259998, 0.000000, 21.119999, 21.119999, 0.000000, + 38.539997, 38.539997, 0.000000, 29.039999, 29.039999, 0.000000}; EXPECT(migraphx::verify::verify_rms_range(result_vector, gold)); } diff --git a/test/ref/roialign.cpp b/test/ref/roialign.cpp index a412e140f7..8d5ec4df12 100644 --- a/test/ref/roialign.cpp +++ b/test/ref/roialign.cpp @@ -84,10 +84,11 @@ TEST_CASE(roialign_out_of_bound_test) } } -auto create_program(const std::string& trans_mode = "half_pixel", - const migraphx::op::pooling_mode pooling_mode = - migraphx::op::pooling_mode::average, - int64_t sampling_ratio = 2) { +auto create_program( + const std::string& trans_mode = "half_pixel", + const migraphx::op::pooling_mode pooling_mode = migraphx::op::pooling_mode::average, + int64_t sampling_ratio = 2) +{ migraphx::program p; auto* mm = p.get_main_module(); migraphx::shape x_s{migraphx::shape::float_type, {5, 2, 5, 4}}; @@ -131,15 +132,15 @@ auto create_program(const std::string& trans_mode = "half_pixel", auto roi = mm->add_literal(migraphx::literal(roi_s, roi_vec)); auto ind = mm->add_literal(migraphx::literal(ind_s, ind_vec)); auto r = mm->add_instruction(migraphx::make_op("roialign", - {{"coordinate_transformation_mode", trans_mode}, - {"spatial_scale", 0.9}, - {"output_height", 3}, - {"output_width", 2}, - {"sampling_ratio", sampling_ratio}, - {"mode", pooling_mode}}), - x, - roi, - ind); + {{"coordinate_transformation_mode", trans_mode}, + {"spatial_scale", 0.9}, + {"output_height", 3}, + {"output_width", 2}, + {"sampling_ratio", sampling_ratio}, + {"mode", pooling_mode}}), + x, + roi, + ind); mm->add_return({r}); return p; }