提交 7d114034 编写于 作者: A Aleksandr Rybnikov

Rewrote googlenet tests

上级 6ba22dea
......@@ -694,6 +694,7 @@ struct Net::Impl
for (it = layers.begin(); it != layers.end(); it++)
{
if (it->second.id != 0) {
it->second.inputBlobs.clear();
it->second.outputBlobs.clear();
it->second.internals.clear();
}
......@@ -1106,8 +1107,10 @@ struct Net::Impl
bnormData->skipFlags[DNN_BACKEND_DEFAULT] = true;
ld.outputBlobs = layers[lpNext.lid].outputBlobs;
if( bnormData->consumers.size() == 1 )
{
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
scaleData->skipFlags[DNN_BACKEND_DEFAULT] = true;
ld.outputBlobs = layers[lpNext.lid].outputBlobs;
if( scaleData->consumers.size() == 1 )
{
nextData = &layers[scaleData->consumers[0].lid];
lpNext = LayerPin(scaleData->consumers[0].lid, 0);
}
}
}
......@@ -1132,7 +1138,8 @@ struct Net::Impl
if( nextData )
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()));
nextData->skipFlags[DNN_BACKEND_DEFAULT] = true;
......
......@@ -198,6 +198,8 @@ public:
bool setActivation(const Ptr<ActivationLayer>& layer)
{
activ = layer;
if (activ.empty())
reluslope.clear();
return !activ.empty();
}
......
......@@ -146,9 +146,8 @@ class DnnCaffeModel(Framework):
return 'DNN'
def get_output(self, input_blob):
self.net.setBlob(self.in_blob_name, input_blob)
self.net.forward()
return self.net.getBlob(self.out_blob_name)
self.net.setInput(input_blob, self.in_blob_name)
return self.net.forward(self.out_blob_name)
class ClsAccEvaluation:
......
......@@ -56,16 +56,10 @@ static std::string _tf(TString filename)
return (getOpenCVExtraDir() + "/dnn/") + filename;
}
static void launchGoogleNetTest()
TEST(Reproducibility_GoogLeNet, Accuracy)
{
Net net;
{
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);
}
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")) );
......@@ -77,6 +71,12 @@ static void launchGoogleNetTest()
Mat ref = blobFromNPY(_tf("googlenet_prob.npy"));
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;
blobsNames.push_back("conv1/7x7_s2");
......@@ -84,7 +84,7 @@ static void launchGoogleNetTest()
blobsNames.push_back("inception_4c/1x1");
blobsNames.push_back("inception_4c/relu_1x1");
std::vector<Mat> outs;
Mat in = blobFromImage(inpMats[0]);
Mat in = blobFromImage(imread(_tf("googlenet_0.png")));
net.setInput(in, "data");
net.forward(outs, blobsNames);
CV_Assert(outs.size() == blobsNames.size());
......@@ -95,13 +95,37 @@ static void launchGoogleNetTest()
std::replace( filename.begin(), filename.end(), '/', '#');
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)
}
//! [Make forward pass]
tm.start();
Mat result = net.forward(oBlob);
tm.stop();
if (!resultFile.empty()) {
CV_Assert(result.isContinuous());
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册