From 08fb355cea00c43915697649c1655d6a59aa6af9 Mon Sep 17 00:00:00 2001 From: Bohrhh <21636037@zju.edu.cn> Date: Sat, 21 Mar 2020 18:35:10 +0800 Subject: [PATCH 1/4] support align_corners for Resize operator --- builtin_op_importers.cpp | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/builtin_op_importers.cpp b/builtin_op_importers.cpp index d62d555e..c05426cf 100644 --- a/builtin_op_importers.cpp +++ b/builtin_op_importers.cpp @@ -2445,11 +2445,11 @@ DEFINE_BUILTIN_OP_IMPORTER(Resize) auto mode = attrs.get("mode", "nearest"); auto resizeMode = mode == "nearest" ? nvinfer1::ResizeMode::kNEAREST : nvinfer1::ResizeMode::kLINEAR; + auto transformationMode = attrs.get("coordinate_transformation_mode", "half_pixel"); if (ctx->getOpsetVersion() >= 11) { - auto transformationMode = attrs.get("coordinate_transformation_mode", "half_pixel"); - ASSERT((transformationMode == "asymmetric") && "This version of TensorRT only supports asymmetric resize!", + ASSERT(((transformationMode == "asymmetric") || (transformationMode == "align_corners")) && "This version of TensorRT only supports asymmetric resize!", ErrorCode::kUNSUPPORTED_NODE); ASSERT(mode != "cubic" && "This version of TensorRT does not support cubic interpolation!", ErrorCode::kUNSUPPORTED_NODE); @@ -2464,6 +2464,8 @@ DEFINE_BUILTIN_OP_IMPORTER(Resize) auto* resizeShape = &convertToTensor(inputs.at(3), ctx); layer->setInput(1, *resizeShape); layer->setResizeMode(resizeMode); + if (transformationMode=="align_corners") + layer->setAlignCorners(true); RETURN_FIRST_OUTPUT(layer); } } @@ -2483,6 +2485,8 @@ DEFINE_BUILTIN_OP_IMPORTER(Resize) } layer->setResizeMode(resizeMode); layer->setScales(scaleValues, inputRank); + if (transformationMode=="align_corners") + layer->setAlignCorners(true); RETURN_FIRST_OUTPUT(layer); } From 0d9f485dd31432059897967ae5ff8630a19b0e06 Mon Sep 17 00:00:00 2001 From: Bohrhh <21636037@zju.edu.cn> Date: Sat, 28 Mar 2020 23:50:21 +0800 Subject: [PATCH 2/4] test --- builtin_op_importers.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/builtin_op_importers.cpp b/builtin_op_importers.cpp index c05426cf..fe778443 100644 --- a/builtin_op_importers.cpp +++ b/builtin_op_importers.cpp @@ -2449,7 +2449,7 @@ DEFINE_BUILTIN_OP_IMPORTER(Resize) if (ctx->getOpsetVersion() >= 11) { - ASSERT(((transformationMode == "asymmetric") || (transformationMode == "align_corners")) && "This version of TensorRT only supports asymmetric resize!", + ASSERT(((transformationMode == "asymmetric") || (transformationMode == "align_corners")) && "This version of TensorRT only supports asymmetric and align_corners resize!", ErrorCode::kUNSUPPORTED_NODE); ASSERT(mode != "cubic" && "This version of TensorRT does not support cubic interpolation!", ErrorCode::kUNSUPPORTED_NODE); From ed30ed1afe554fba78573a3c397bb4081a5c14af Mon Sep 17 00:00:00 2001 From: Bohrhh <21636037@zju.edu.cn> Date: Sun, 29 Mar 2020 00:06:20 +0800 Subject: [PATCH 3/4] support align_corners in resize operator --- builtin_op_importers.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/builtin_op_importers.cpp b/builtin_op_importers.cpp index fe778443..b66472fc 100644 --- a/builtin_op_importers.cpp +++ b/builtin_op_importers.cpp @@ -2471,6 +2471,7 @@ DEFINE_BUILTIN_OP_IMPORTER(Resize) } // Resizes that use scale factors have the same import logic between opsets + ASSERT(((transformationMode != "align_corners", "Align_corners should use size information not scale factors!"); auto scales = ctx->getOpsetVersion() >= 11 ? inputs.at(2) : inputs.at(1); ASSERT(scales.is_weights() && "Resize scales must be an initializer!", ErrorCode::kUNSUPPORTED_NODE); ShapedWeights scales_weights = scales.weights(); @@ -2485,8 +2486,6 @@ DEFINE_BUILTIN_OP_IMPORTER(Resize) } layer->setResizeMode(resizeMode); layer->setScales(scaleValues, inputRank); - if (transformationMode=="align_corners") - layer->setAlignCorners(true); RETURN_FIRST_OUTPUT(layer); } From c1faba01e2393add0c7f1d6d0c639a1839522616 Mon Sep 17 00:00:00 2001 From: "kemin.li" <21636037@zju.edu.cn> Date: Mon, 20 Apr 2020 19:43:01 +0800 Subject: [PATCH 4/4] support align_corners in resize operator --- builtin_op_importers.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/builtin_op_importers.cpp b/builtin_op_importers.cpp index b66472fc..b91cbb45 100644 --- a/builtin_op_importers.cpp +++ b/builtin_op_importers.cpp @@ -2471,7 +2471,7 @@ DEFINE_BUILTIN_OP_IMPORTER(Resize) } // Resizes that use scale factors have the same import logic between opsets - ASSERT(((transformationMode != "align_corners", "Align_corners should use size information not scale factors!"); + ASSERT(transformationMode != "align_corners" && "Align_corners should use size information not scale factors!", ErrorCode::kUNSUPPORTED_NODE); auto scales = ctx->getOpsetVersion() >= 11 ? inputs.at(2) : inputs.at(1); ASSERT(scales.is_weights() && "Resize scales must be an initializer!", ErrorCode::kUNSUPPORTED_NODE); ShapedWeights scales_weights = scales.weights();