Fix dilated convolution from Keras
authorDmitry Kurtaev <dmitry.kurtaev+github@gmail.com>
Tue, 29 May 2018 09:15:47 +0000 (12:15 +0300)
committerDmitry Kurtaev <dmitry.kurtaev+github@gmail.com>
Tue, 29 May 2018 09:15:47 +0000 (12:15 +0300)
modules/dnn/src/tensorflow/tf_importer.cpp
modules/dnn/test/test_tf_importer.cpp

index 195b516..bca150e 100644 (file)
@@ -644,8 +644,9 @@ void TFImporter::populateNet(Net dstNet)
                 CV_Assert(layer.input_size() == 3);
 
                 DictValue dilation = parseDims(getConstBlob(layer, value_id, 1));
-                CV_Assert(dilation.size() == 2 && dilation.get<int>(0) == dilation.get<int>(1));
-                layerParams.set("dilation", dilation.get<int>(0));
+                CV_Assert(dilation.size() == 2);
+                layerParams.set("dilation_h", dilation.get<int>(0));
+                layerParams.set("dilation_w", dilation.get<int>(1));
 
                 Mat paddings;
                 parseTensor<int>(getConstBlob(layer, value_id, 2), paddings);
@@ -655,6 +656,10 @@ void TFImporter::populateNet(Net dstNet)
                 layerParams.set("pad_w", paddings.at<float>(2));
 
                 StrIntVector next_layers = getNextLayers(net, name, "Conv2D");
+                if (next_layers.empty())
+                {
+                    next_layers = getNextLayers(net, name, "DepthwiseConv2dNative");
+                }
                 CV_Assert(next_layers.size() == 1);
                 layer = net.node(next_layers[0].second);
                 layers_to_ignore.insert(next_layers[0].first);
index 3f02fb2..66c43d6 100644 (file)
@@ -124,6 +124,7 @@ TEST_P(Test_TensorFlow_layers, conv)
     runTensorFlowNet("atrous_conv2d_valid", targetId);
     runTensorFlowNet("atrous_conv2d_same", targetId);
     runTensorFlowNet("depthwise_conv2d", targetId);
+    runTensorFlowNet("keras_atrous_conv2d_same", targetId);
 }
 
 TEST_P(Test_TensorFlow_layers, padding)