Skip to content

Commit

Permalink
update roialign max pooling test; learned that onnxruntime Gold value…
Browse files Browse the repository at this point in the history
…s are incorrect
  • Loading branch information
bpickrel committed Oct 25, 2024
1 parent 1ad15d0 commit 5c8151d
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 38 deletions.
10 changes: 5 additions & 5 deletions test/onnx/gen_onnx.py
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
1 change: 0 additions & 1 deletion test/onnx/parse/roialign_default_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ TEST_CASE(roialign_default_test)
EXPECT(p == prog);
}


TEST_CASE(roialign_default_12_test)
{
// opset 12 version
Expand Down
16 changes: 8 additions & 8 deletions test/onnx/roialign_half_pixel_test.onnx
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,21 @@ half_pixel
spatial_scalefff?�roialign_half_pixel_testZ
x




Z


Z
rois



Z
batch_ind


b
b
y





B

B
Expand Down
32 changes: 21 additions & 11 deletions test/onnx/verify/roialign_half_pixel_verify_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<float> 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<float> 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));
}
Expand Down Expand Up @@ -85,14 +88,21 @@ TEST_CASE(roialign_half_pixel_max_verify_test)
std::vector<float> result_vector;
result.visit([&](auto output) { result_vector.assign(output.begin(), output.end()); });

// Gold values were generated with onnxruntime
std::vector<float> 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<float> 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));
}
27 changes: 14 additions & 13 deletions test/ref/roialign.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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}};
Expand Down Expand Up @@ -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;
}
Expand Down

0 comments on commit 5c8151d

Please sign in to comment.