From fa953e4205327224a1124be10b90d497d7cfa32f Mon Sep 17 00:00:00 2001 From: Sergei Slashchinin <62052793+sl-sergei@users.noreply.github.com> Date: Thu, 17 Sep 2020 14:05:22 +0300 Subject: [PATCH] Merge pull request #18316 from sl-sergei:fix_18253 Fix loading of ONNX models with Resize operation with Opset 11 for newer versions of Pytorch * Add reproducer for Resize operation from newer versions of Pytorch * Fix loading of scales parameter for Resize layer * Change check type for better diagnostic messages --- modules/dnn/src/onnx/onnx_importer.cpp | 4 +++- modules/dnn/test/test_onnx_importer.cpp | 5 +++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/modules/dnn/src/onnx/onnx_importer.cpp b/modules/dnn/src/onnx/onnx_importer.cpp index 995800310f..318c2cc290 100644 --- a/modules/dnn/src/onnx/onnx_importer.cpp +++ b/modules/dnn/src/onnx/onnx_importer.cpp @@ -1588,7 +1588,9 @@ void ONNXImporter::populateNet(Net dstNet) Mat shapes = getBlob(node_proto, constBlobs, node_proto.input_size() - 1); CV_CheckEQ(shapes.size[0], 4, ""); CV_CheckEQ(shapes.size[1], 1, ""); - CV_CheckTypeEQ(shapes.depth(), CV_32S, ""); + CV_CheckDepth(shapes.depth(), shapes.depth() == CV_32S || shapes.depth() == CV_32F, ""); + if (shapes.depth() == CV_32F) + shapes.convertTo(shapes, CV_32S); int height = shapes.at(2); int width = shapes.at(3); if (node_proto.input_size() == 3) diff --git a/modules/dnn/test/test_onnx_importer.cpp b/modules/dnn/test/test_onnx_importer.cpp index 2a4555619f..4234fa8d8b 100644 --- a/modules/dnn/test/test_onnx_importer.cpp +++ b/modules/dnn/test/test_onnx_importer.cpp @@ -636,6 +636,11 @@ TEST_P(Test_ONNX_layers, MatmulWithTwoInputs) testONNXModels("matmul_with_two_inputs"); } +TEST_P(Test_ONNX_layers, ResizeOpset11_Torch1_6) +{ + testONNXModels("resize_opset11_torch1.6"); +} + INSTANTIATE_TEST_CASE_P(/*nothing*/, Test_ONNX_layers, dnnBackendsAndTargets()); class Test_ONNX_nets : public Test_ONNX_layers