Merge pull request #14845 from vonchenplus:ocv_mirrorpad

* tensorflow support mirror pad

* revert macro define

* revert macro define

* reduce code duplication

* revert macro define
This commit is contained in:
Feng Chen 2019-06-24 17:27:42 +08:00 committed by Alexander Alekhin
parent f8c96cb18a
commit 5620306c70
2 changed files with 8 additions and 3 deletions

View File

@ -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<int32_t>(4) != paddings.at<int32_t>(5) ||
paddings.at<int32_t>(6) != paddings.at<int32_t>(7))
paddings.at<int32_t>(6) != paddings.at<int32_t>(7) || type == "MirrorPad")
{
// Just a single padding layer.
layerParams.set("paddings", DictValue::arrayInt<int*>((int*)paddings.data, paddings.total()));
if (type == "MirrorPad")
layerParams.set("type", "reflect");
int id = dstNet.addLayer(name, "Padding", layerParams);
layer_id[name] = id;

View File

@ -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)