1
0
mirror of https://github.com/opencv/opencv.git synced 2026-07-29 23:33:05 +04:00

Enable SSD models from TensorFlow with OpenCL plugin of Intel's Inference Engine

This commit is contained in:
Dmitry Kurtaev
2018-06-08 16:55:21 +03:00
parent 1187a7fa34
commit 40765c5f8d
4 changed files with 75 additions and 44 deletions
+24 -15
View File
@@ -38,7 +38,7 @@ public:
void processNet(std::string weights, std::string proto,
Mat inp, const std::string& outputLayer = "",
std::string halideScheduler = "",
double l1 = 0.0, double lInf = 0.0)
double l1 = 0.0, double lInf = 0.0, double detectionConfThresh = 0.2)
{
if (backend == DNN_BACKEND_OPENCV && (target == DNN_TARGET_OPENCL || target == DNN_TARGET_OPENCL_FP16))
{
@@ -87,7 +87,7 @@ public:
}
Mat out = net.forward(outputLayer).clone();
check(outDefault, out, outputLayer, l1, lInf, "First run");
check(outDefault, out, outputLayer, l1, lInf, detectionConfThresh, "First run");
// Test 2: change input.
float* inpData = (float*)inp.data;
@@ -101,10 +101,11 @@ public:
net.setInput(inp);
outDefault = netDefault.forward(outputLayer).clone();
out = net.forward(outputLayer).clone();
check(outDefault, out, outputLayer, l1, lInf, "Second run");
check(outDefault, out, outputLayer, l1, lInf, detectionConfThresh, "Second run");
}
void check(Mat& ref, Mat& out, const std::string& outputLayer, double l1, double lInf, const char* msg)
void check(Mat& ref, Mat& out, const std::string& outputLayer, double l1, double lInf,
double detectionConfThresh, const char* msg)
{
if (outputLayer == "detection_out")
{
@@ -119,7 +120,7 @@ public:
}
out = out.rowRange(0, numDetections);
}
normAssertDetections(ref, out, msg, 0.2, l1, lInf);
normAssertDetections(ref, out, msg, detectionConfThresh, l1, lInf);
}
else
normAssert(ref, out, msg, l1, lInf);
@@ -188,20 +189,30 @@ TEST_P(DNNTestNetwork, MobileNet_SSD_Caffe)
inp, "detection_out", "", l1, lInf);
}
// TODO: update MobileNet model.
TEST_P(DNNTestNetwork, MobileNet_SSD_TensorFlow)
TEST_P(DNNTestNetwork, MobileNet_SSD_v1_TensorFlow)
{
if (backend == DNN_BACKEND_HALIDE ||
backend == DNN_BACKEND_INFERENCE_ENGINE)
if (backend == DNN_BACKEND_HALIDE)
throw SkipTestException("");
Mat sample = imread(findDataFile("dnn/street.png", false));
Mat inp = blobFromImage(sample, 1.0f / 127.5, Size(300, 300), Scalar(127.5, 127.5, 127.5), false);
float l1 = (backend == DNN_BACKEND_OPENCV && target == DNN_TARGET_OPENCL_FP16) ? 0.008 : 0.0;
float lInf = (backend == DNN_BACKEND_OPENCV && target == DNN_TARGET_OPENCL_FP16) ? 0.06 : 0.0;
processNet("dnn/ssd_mobilenet_v1_coco.pb", "dnn/ssd_mobilenet_v1_coco.pbtxt",
float l1 = (target == DNN_TARGET_OPENCL_FP16 || target == DNN_TARGET_MYRIAD) ? 0.011 : 0.0;
float lInf = (target == DNN_TARGET_OPENCL_FP16 || target == DNN_TARGET_MYRIAD) ? 0.06 : 0.0;
processNet("dnn/ssd_mobilenet_v1_coco_2017_11_17.pb", "dnn/ssd_mobilenet_v1_coco_2017_11_17.pbtxt",
inp, "detection_out", "", l1, lInf);
}
TEST_P(DNNTestNetwork, MobileNet_SSD_v2_TensorFlow)
{
if (backend == DNN_BACKEND_HALIDE)
throw SkipTestException("");
Mat sample = imread(findDataFile("dnn/street.png", false));
Mat inp = blobFromImage(sample, 1.0f / 127.5, Size(300, 300), Scalar(127.5, 127.5, 127.5), false);
float l1 = (target == DNN_TARGET_OPENCL_FP16 || target == DNN_TARGET_MYRIAD) ? 0.011 : 0.0;
float lInf = (target == DNN_TARGET_OPENCL_FP16 || target == DNN_TARGET_MYRIAD) ? 0.06 : 0.0;
processNet("dnn/ssd_mobilenet_v2_coco_2018_03_29.pb", "dnn/ssd_mobilenet_v2_coco_2018_03_29.pbtxt",
inp, "detection_out", "", l1, lInf, 0.25);
}
TEST_P(DNNTestNetwork, SSD_VGG16)
{
if (backend == DNN_BACKEND_HALIDE && target == DNN_TARGET_CPU)
@@ -265,9 +276,7 @@ TEST_P(DNNTestNetwork, opencv_face_detector)
TEST_P(DNNTestNetwork, Inception_v2_SSD_TensorFlow)
{
if (backend == DNN_BACKEND_HALIDE ||
(backend == DNN_BACKEND_INFERENCE_ENGINE && target == DNN_TARGET_OPENCL) ||
(backend == DNN_BACKEND_INFERENCE_ENGINE && target == DNN_TARGET_OPENCL_FP16))
if (backend == DNN_BACKEND_HALIDE)
throw SkipTestException("");
Mat sample = imread(findDataFile("dnn/street.png", false));
Mat inp = blobFromImage(sample, 1.0f / 127.5, Size(300, 300), Scalar(127.5, 127.5, 127.5), false);