1
0
mirror of https://github.com/opencv/opencv.git synced 2026-07-31 00:03:03 +04:00

Text TensorFlow graphs parsing. MobileNet-SSD for 90 classes.

This commit is contained in:
Dmitry Kurtaev
2017-09-28 16:51:47 +03:00
parent 8ac2c5d620
commit e4aa39f9e5
10 changed files with 536 additions and 83 deletions
+48 -12
View File
@@ -74,14 +74,15 @@ static std::string path(const std::string& file)
return findDataFile("dnn/tensorflow/" + file, false);
}
static void runTensorFlowNet(const std::string& prefix,
static void runTensorFlowNet(const std::string& prefix, bool hasText = false,
double l1 = 1e-5, double lInf = 1e-4)
{
std::string netPath = path(prefix + "_net.pb");
std::string netConfig = (hasText ? path(prefix + "_net.pbtxt") : "");
std::string inpPath = path(prefix + "_in.npy");
std::string outPath = path(prefix + "_out.npy");
Net net = readNetFromTensorflow(netPath);
Net net = readNetFromTensorflow(netPath, netConfig);
cv::Mat input = blobFromNPY(inpPath);
cv::Mat target = blobFromNPY(outPath);
@@ -120,6 +121,7 @@ TEST(Test_TensorFlow, batch_norm)
{
runTensorFlowNet("batch_norm");
runTensorFlowNet("fused_batch_norm");
runTensorFlowNet("batch_norm_text", true);
}
TEST(Test_TensorFlow, pooling)
@@ -148,26 +150,60 @@ TEST(Test_TensorFlow, reshape)
{
runTensorFlowNet("shift_reshape_no_reorder");
runTensorFlowNet("reshape_reduce");
runTensorFlowNet("flatten", true);
}
TEST(Test_TensorFlow, fp16)
{
const float l1 = 1e-3;
const float lInf = 1e-2;
runTensorFlowNet("fp16_single_conv", l1, lInf);
runTensorFlowNet("fp16_deconvolution", l1, lInf);
runTensorFlowNet("fp16_max_pool_odd_same", l1, lInf);
runTensorFlowNet("fp16_padding_valid", l1, lInf);
runTensorFlowNet("fp16_eltwise_add_mul", l1, lInf);
runTensorFlowNet("fp16_max_pool_odd_valid", l1, lInf);
runTensorFlowNet("fp16_pad_and_concat", l1, lInf);
runTensorFlowNet("fp16_max_pool_even", l1, lInf);
runTensorFlowNet("fp16_padding_same", l1, lInf);
runTensorFlowNet("fp16_single_conv", false, l1, lInf);
runTensorFlowNet("fp16_deconvolution", false, l1, lInf);
runTensorFlowNet("fp16_max_pool_odd_same", false, l1, lInf);
runTensorFlowNet("fp16_padding_valid", false, l1, lInf);
runTensorFlowNet("fp16_eltwise_add_mul", false, l1, lInf);
runTensorFlowNet("fp16_max_pool_odd_valid", false, l1, lInf);
runTensorFlowNet("fp16_pad_and_concat", false, l1, lInf);
runTensorFlowNet("fp16_max_pool_even", false, l1, lInf);
runTensorFlowNet("fp16_padding_same", false, l1, lInf);
}
TEST(Test_TensorFlow, MobileNet_SSD)
{
std::string netPath = findDataFile("dnn/ssd_mobilenet_v1_coco.pb", false);
std::string netConfig = findDataFile("dnn/ssd_mobilenet_v1_coco.pbtxt", false);
std::string imgPath = findDataFile("dnn/street.png", false);
Mat inp;
resize(imread(imgPath), inp, Size(300, 300));
inp = blobFromImage(inp, 1.0f / 127.5, Size(), Scalar(127.5, 127.5, 127.5), true);
std::vector<String> outNames(3);
outNames[0] = "concat";
outNames[1] = "concat_1";
outNames[2] = "detection_out";
std::vector<Mat> target(outNames.size());
for (int i = 0; i < outNames.size(); ++i)
{
std::string path = findDataFile("dnn/tensorflow/ssd_mobilenet_v1_coco." + outNames[i] + ".npy", false);
target[i] = blobFromNPY(path);
}
Net net = readNetFromTensorflow(netPath, netConfig);
net.setInput(inp);
std::vector<Mat> output;
net.forward(output, outNames);
normAssert(target[0].reshape(1, 1), output[0].reshape(1, 1));
normAssert(target[1].reshape(1, 1), output[1].reshape(1, 1), "", 1e-5, 2e-4);
normAssert(target[2].reshape(1, 1), output[2].reshape(1, 1), "", 4e-5, 1e-2);
}
TEST(Test_TensorFlow, lstm)
{
runTensorFlowNet("lstm");
runTensorFlowNet("lstm", true);
}
TEST(Test_TensorFlow, split)