Fix multiple inputs for models from Intel's Model Optimizer
authorDmitry Kurtaev <dmitry.kurtaev+github@gmail.com>
Wed, 11 Apr 2018 10:28:07 +0000 (13:28 +0300)
committerDmitry Kurtaev <dmitry.kurtaev+github@gmail.com>
Wed, 11 Apr 2018 10:28:07 +0000 (13:28 +0300)
modules/dnn/src/dnn.cpp
modules/dnn/test/test_layers.cpp

index 611e35e..dfa5e28 100644 (file)
@@ -1944,7 +1944,8 @@ Net Net::readFromModelOptimizer(const String& xml, const String& bin)
         ld.layerInstance = Ptr<Layer>(new InfEngineBackendLayer(it.second));
         ld.backendNodes[DNN_BACKEND_INFERENCE_ENGINE] = backendNode;
 
-        cvNet.connect(0, 0, lid, 0);
+        for (int i = 0; i < inputsNames.size(); ++i)
+            cvNet.connect(0, i, lid, i);
     }
     cvNet.setPreferableBackend(DNN_BACKEND_INFERENCE_ENGINE);
 
index dd5a06b..413e527 100644 (file)
@@ -866,6 +866,44 @@ TEST(Layer_Test_Convolution_DLDT, Accuracy)
 
     normAssert(outDefault, out);
 }
+
+// 1. Create a .prototxt file with the following network:
+// layer {
+//   type: "Input" name: "data" top: "data"
+//   input_param { shape { dim: 1 dim: 2 dim: 3 } }
+// }
+// layer {
+//   type: "Input" name: "second_input" top: "second_input"
+//   input_param { shape { dim: 1 dim: 2 dim: 3 } }
+// }
+// layer {
+//  type: "Eltwise" name: "output" top: "output"
+//  bottom: "data" bottom: "second_input"
+//  eltwise_param { operation: SUM }
+// }
+//
+// 2. Create a .caffemodel file using Caffe:
+//
+// import caffe
+// net = caffe.Net('/path/to/prototxt', caffe.TEST)
+// net.save('/path/to/caffemodel')
+//
+// 3. Convert using ModelOptimizer.
+TEST(Test_DLDT, two_inputs)
+{
+    Net net = readNet(_tf("net_two_inputs.xml"), _tf("net_two_inputs.bin"));
+    int inpSize[] = {1, 2, 3};
+    Mat firstInp(3, &inpSize[0], CV_32F);
+    Mat secondInp(3, &inpSize[0], CV_32F);
+    randu(firstInp, -1, 1);
+    randu(secondInp, -1, 1);
+
+    net.setInput(firstInp, "data");
+    net.setInput(secondInp, "second_input");
+    Mat out = net.forward();
+
+    normAssert(out, firstInp + secondInp);
+}
 #endif  // HAVE_INF_ENGINE
 
 }} // namespace