Commit 77336540 authored by Alexander Alekhin's avatar Alexander Alekhin

Merge pull request #9037 from arrybn:googlenet_test

parents cb0a61b9 7d114034
...@@ -694,6 +694,7 @@ struct Net::Impl ...@@ -694,6 +694,7 @@ struct Net::Impl
for (it = layers.begin(); it != layers.end(); it++) for (it = layers.begin(); it != layers.end(); it++)
{ {
if (it->second.id != 0) { if (it->second.id != 0) {
it->second.inputBlobs.clear();
it->second.outputBlobs.clear(); it->second.outputBlobs.clear();
it->second.internals.clear(); it->second.internals.clear();
} }
...@@ -1106,8 +1107,10 @@ struct Net::Impl ...@@ -1106,8 +1107,10 @@ struct Net::Impl
bnormData->skipFlags[DNN_BACKEND_DEFAULT] = true; bnormData->skipFlags[DNN_BACKEND_DEFAULT] = true;
ld.outputBlobs = layers[lpNext.lid].outputBlobs; ld.outputBlobs = layers[lpNext.lid].outputBlobs;
if( bnormData->consumers.size() == 1 ) if( bnormData->consumers.size() == 1 )
{
nextData = &layers[bnormData->consumers[0].lid]; nextData = &layers[bnormData->consumers[0].lid];
lpNext = LayerPin(bnormData->consumers[0].lid, 0); lpNext = LayerPin(bnormData->consumers[0].lid, 0);
}
} }
} }
...@@ -1124,7 +1127,10 @@ struct Net::Impl ...@@ -1124,7 +1127,10 @@ struct Net::Impl
scaleData->skipFlags[DNN_BACKEND_DEFAULT] = true; scaleData->skipFlags[DNN_BACKEND_DEFAULT] = true;
ld.outputBlobs = layers[lpNext.lid].outputBlobs; ld.outputBlobs = layers[lpNext.lid].outputBlobs;
if( scaleData->consumers.size() == 1 ) if( scaleData->consumers.size() == 1 )
{
nextData = &layers[scaleData->consumers[0].lid]; nextData = &layers[scaleData->consumers[0].lid];
lpNext = LayerPin(scaleData->consumers[0].lid, 0);
}
} }
} }
...@@ -1132,7 +1138,8 @@ struct Net::Impl ...@@ -1132,7 +1138,8 @@ struct Net::Impl
if( nextData ) if( nextData )
nextActivLayer = nextData->layerInstance.dynamicCast<ActivationLayer>(); nextActivLayer = nextData->layerInstance.dynamicCast<ActivationLayer>();
if( !nextActivLayer.empty() && currLayer->setActivation(nextActivLayer) ) if( !nextActivLayer.empty() && pinsToKeep.count(lpNext) == 0
&& currLayer->setActivation(nextActivLayer) )
{ {
printf_(("\tfused with %s\n", nextActivLayer->name.c_str())); printf_(("\tfused with %s\n", nextActivLayer->name.c_str()));
nextData->skipFlags[DNN_BACKEND_DEFAULT] = true; nextData->skipFlags[DNN_BACKEND_DEFAULT] = true;
......
...@@ -198,6 +198,8 @@ public: ...@@ -198,6 +198,8 @@ public:
bool setActivation(const Ptr<ActivationLayer>& layer) bool setActivation(const Ptr<ActivationLayer>& layer)
{ {
activ = layer; activ = layer;
if (activ.empty())
reluslope.clear();
return !activ.empty(); return !activ.empty();
} }
......
...@@ -146,9 +146,8 @@ class DnnCaffeModel(Framework): ...@@ -146,9 +146,8 @@ class DnnCaffeModel(Framework):
return 'DNN' return 'DNN'
def get_output(self, input_blob): def get_output(self, input_blob):
self.net.setBlob(self.in_blob_name, input_blob) self.net.setInput(input_blob, self.in_blob_name)
self.net.forward() return self.net.forward(self.out_blob_name)
return self.net.getBlob(self.out_blob_name)
class ClsAccEvaluation: class ClsAccEvaluation:
......
...@@ -56,16 +56,10 @@ static std::string _tf(TString filename) ...@@ -56,16 +56,10 @@ static std::string _tf(TString filename)
return (getOpenCVExtraDir() + "/dnn/") + filename; return (getOpenCVExtraDir() + "/dnn/") + filename;
} }
static void launchGoogleNetTest() TEST(Reproducibility_GoogLeNet, Accuracy)
{ {
Net net; Net net = readNetFromCaffe(findDataFile("dnn/bvlc_googlenet.prototxt", false),
{ findDataFile("dnn/bvlc_googlenet.caffemodel", false));
const string proto = findDataFile("dnn/bvlc_googlenet.prototxt", false);
const string model = findDataFile("dnn/bvlc_googlenet.caffemodel", false);
Ptr<Importer> importer = createCaffeImporter(proto, model);
ASSERT_TRUE(importer != NULL);
importer->populateNet(net);
}
std::vector<Mat> inpMats; std::vector<Mat> inpMats;
inpMats.push_back( imread(_tf("googlenet_0.png")) ); inpMats.push_back( imread(_tf("googlenet_0.png")) );
...@@ -77,6 +71,12 @@ static void launchGoogleNetTest() ...@@ -77,6 +71,12 @@ static void launchGoogleNetTest()
Mat ref = blobFromNPY(_tf("googlenet_prob.npy")); Mat ref = blobFromNPY(_tf("googlenet_prob.npy"));
normAssert(out, ref); normAssert(out, ref);
}
TEST(IntermediateBlobs_GoogLeNet, Accuracy)
{
Net net = readNetFromCaffe(findDataFile("dnn/bvlc_googlenet.prototxt", false),
findDataFile("dnn/bvlc_googlenet.caffemodel", false));
std::vector<String> blobsNames; std::vector<String> blobsNames;
blobsNames.push_back("conv1/7x7_s2"); blobsNames.push_back("conv1/7x7_s2");
...@@ -84,7 +84,7 @@ static void launchGoogleNetTest() ...@@ -84,7 +84,7 @@ static void launchGoogleNetTest()
blobsNames.push_back("inception_4c/1x1"); blobsNames.push_back("inception_4c/1x1");
blobsNames.push_back("inception_4c/relu_1x1"); blobsNames.push_back("inception_4c/relu_1x1");
std::vector<Mat> outs; std::vector<Mat> outs;
Mat in = blobFromImage(inpMats[0]); Mat in = blobFromImage(imread(_tf("googlenet_0.png")));
net.setInput(in, "data"); net.setInput(in, "data");
net.forward(outs, blobsNames); net.forward(outs, blobsNames);
CV_Assert(outs.size() == blobsNames.size()); CV_Assert(outs.size() == blobsNames.size());
...@@ -95,13 +95,37 @@ static void launchGoogleNetTest() ...@@ -95,13 +95,37 @@ static void launchGoogleNetTest()
std::replace( filename.begin(), filename.end(), '/', '#'); std::replace( filename.begin(), filename.end(), '/', '#');
Mat ref = blobFromNPY(_tf("googlenet_" + filename + ".npy")); Mat ref = blobFromNPY(_tf("googlenet_" + filename + ".npy"));
//normAssert(outs[i], ref, "", 1E-4, 1E-2); normAssert(outs[i], ref, "", 1E-4, 1E-2);
} }
} }
TEST(Reproducibility_GoogLeNet, Accuracy) TEST(SeveralCalls_GoogLeNet, Accuracy)
{ {
launchGoogleNetTest(); Net net = readNetFromCaffe(findDataFile("dnn/bvlc_googlenet.prototxt", false),
findDataFile("dnn/bvlc_googlenet.caffemodel", false));
std::vector<Mat> inpMats;
inpMats.push_back( imread(_tf("googlenet_0.png")) );
inpMats.push_back( imread(_tf("googlenet_1.png")) );
ASSERT_TRUE(!inpMats[0].empty() && !inpMats[1].empty());
net.setInput(blobFromImages(inpMats), "data");
Mat out = net.forward();
Mat ref = blobFromNPY(_tf("googlenet_prob.npy"));
normAssert(out, ref);
std::vector<String> blobsNames;
blobsNames.push_back("conv1/7x7_s2");
std::vector<Mat> outs;
Mat in = blobFromImage(inpMats[0]);
net.setInput(in, "data");
net.forward(outs, blobsNames);
CV_Assert(outs.size() == blobsNames.size());
ref = blobFromNPY(_tf("googlenet_conv1#7x7_s2.npy"));
normAssert(outs[0], ref, "", 1E-4, 1E-2);
} }
} }
...@@ -85,7 +85,9 @@ int main(int argc, char **argv) ...@@ -85,7 +85,9 @@ int main(int argc, char **argv)
} }
//! [Make forward pass] //! [Make forward pass]
tm.start();
Mat result = net.forward(oBlob); Mat result = net.forward(oBlob);
tm.stop();
if (!resultFile.empty()) { if (!resultFile.empty()) {
CV_Assert(result.isContinuous()); CV_Assert(result.isContinuous());
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment