From 5620306c702422d109952d4b4b79f52e369f4101 Mon Sep 17 00:00:00 2001 From: Feng Chen Date: Mon, 24 Jun 2019 17:27:42 +0800 Subject: [PATCH] Merge pull request #14845 from vonchenplus:ocv_mirrorpad * tensorflow support mirror pad * revert macro define * revert macro define * reduce code duplication * revert macro define --- modules/dnn/src/tensorflow/tf_importer.cpp | 10 +++++++--- modules/dnn/test/test_tf_importer.cpp | 1 + 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/modules/dnn/src/tensorflow/tf_importer.cpp b/modules/dnn/src/tensorflow/tf_importer.cpp index f7a515c0a3..3a5bd34fcb 100644 --- a/modules/dnn/src/tensorflow/tf_importer.cpp +++ b/modules/dnn/src/tensorflow/tf_importer.cpp @@ -792,7 +792,7 @@ void TFImporter::populateNet(Net dstNet) int predictedLayout = predictOutputDataLayout(net, layer, data_layouts); data_layouts[name] = predictedLayout; - if (type == "Conv2D" || type == "SpaceToBatchND" || type == "DepthwiseConv2dNative" || type == "Pad" || type == "Conv3D") + if (type == "Conv2D" || type == "SpaceToBatchND" || type == "DepthwiseConv2dNative" || type == "Pad" || type == "MirrorPad" || type == "Conv3D") { // The first node of dilated convolution subgraph. // Extract input node, dilation rate and paddings. @@ -804,6 +804,7 @@ void TFImporter::populateNet(Net dstNet) if (next_layers.empty()) next_layers = getNextLayers(net, name, "DepthwiseConv2dNative"); } + if (type == "SpaceToBatchND") { // op: "SpaceToBatchND" @@ -830,7 +831,7 @@ void TFImporter::populateNet(Net dstNet) name = layer.name(); type = layer.op(); } - else if (type == "Pad") + else if (type == "Pad" || type == "MirrorPad") { Mat paddings = getTensorContent(getConstBlob(layer, value_id, 1)); CV_Assert(paddings.type() == CV_32SC1); @@ -848,12 +849,15 @@ void TFImporter::populateNet(Net dstNet) // N C H W // 0 1 2 3 4 5 6 7 } + if (next_layers.empty() || paddings.total() != 8 || paddings.at(4) != paddings.at(5) || - paddings.at(6) != paddings.at(7)) + paddings.at(6) != paddings.at(7) || type == "MirrorPad") { // Just a single padding layer. layerParams.set("paddings", DictValue::arrayInt((int*)paddings.data, paddings.total())); + if (type == "MirrorPad") + layerParams.set("type", "reflect"); int id = dstNet.addLayer(name, "Padding", layerParams); layer_id[name] = id; diff --git a/modules/dnn/test/test_tf_importer.cpp b/modules/dnn/test/test_tf_importer.cpp index d3d138daa4..41b4154940 100644 --- a/modules/dnn/test/test_tf_importer.cpp +++ b/modules/dnn/test/test_tf_importer.cpp @@ -146,6 +146,7 @@ TEST_P(Test_TensorFlow_layers, padding) runTensorFlowNet("padding_valid"); runTensorFlowNet("spatial_padding"); runTensorFlowNet("keras_pad_concat"); + runTensorFlowNet("mirror_pad"); } TEST_P(Test_TensorFlow_layers, padding_same)