Merge pull request #12775 from radomsak:radomsak_dnn_fix_caffe_importer_reused_layers

pull/12843/head
Alexander Alekhin 6 years ago
commit f8a27d2603
  1. 6
      modules/dnn/src/caffe/caffe_importer.cpp
  2. 22
      modules/dnn/test/test_caffe_importer.cpp

@ -278,11 +278,13 @@ public:
int li;
for (li = 0; li != netBinary.layer_size(); li++)
{
if (netBinary.layer(li).name() == name)
const caffe::LayerParameter& binLayer = netBinary.layer(li);
// Break if the layer name is the same and the blobs are not cleared
if (binLayer.name() == name && binLayer.blobs_size() != 0)
break;
}
if (li == netBinary.layer_size() || netBinary.layer(li).blobs_size() == 0)
if (li == netBinary.layer_size())
return;
caffe::LayerParameter* binLayer = netBinary.mutable_layer(li);

@ -454,6 +454,28 @@ TEST(Test_Caffe, multiple_inputs)
normAssert(out, first_image + second_image);
}
TEST(Test_Caffe, shared_weights)
{
const string proto = findDataFile("dnn/layers/shared_weights.prototxt", false);
const string model = findDataFile("dnn/layers/shared_weights.caffemodel", false);
Net net = readNetFromCaffe(proto, model);
Mat input_1 = (Mat_<float>(2, 2) << 0., 2., 4., 6.);
Mat input_2 = (Mat_<float>(2, 2) << 1., 3., 5., 7.);
Mat blob_1 = blobFromImage(input_1);
Mat blob_2 = blobFromImage(input_2);
net.setInput(blob_1, "input_1");
net.setInput(blob_2, "input_2");
Mat sum = net.forward();
EXPECT_EQ(sum.at<float>(0,0), 12.);
EXPECT_EQ(sum.at<float>(0,1), 16.);
}
typedef testing::TestWithParam<tuple<std::string, Target> > opencv_face_detector;
TEST_P(opencv_face_detector, Accuracy)
{

Loading…
Cancel
Save