Skip to content

Commit 3b84acf

Browse files
committed
add ocl accuracy test for tf mobilenet ssd
Signed-off-by: Li Peng <peng.li@intel.com>
1 parent 436d7e4 commit 3b84acf

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed

modules/dnn/test/test_tf_importer.cpp

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ Test for Tensorflow models loading
1111

1212
#include "test_precomp.hpp"
1313
#include "npy_blob.hpp"
14+
#include <opencv2/core/ocl.hpp>
15+
#include <opencv2/ts/ocl_test.hpp>
1416

1517
namespace cvtest
1618
{
@@ -219,6 +221,43 @@ TEST(Test_TensorFlow, MobileNet_SSD)
219221
normAssert(target[2].reshape(1, 1), output[2].reshape(1, 1), "", 4e-5, 1e-2);
220222
}
221223

224+
OCL_TEST(Test_TensorFlow, MobileNet_SSD)
225+
{
226+
std::string netPath = findDataFile("dnn/ssd_mobilenet_v1_coco.pb", false);
227+
std::string netConfig = findDataFile("dnn/ssd_mobilenet_v1_coco.pbtxt", false);
228+
std::string imgPath = findDataFile("dnn/street.png", false);
229+
230+
Mat inp;
231+
resize(imread(imgPath), inp, Size(300, 300));
232+
inp = blobFromImage(inp, 1.0f / 127.5, Size(), Scalar(127.5, 127.5, 127.5), true);
233+
234+
std::vector<String> outNames(3);
235+
outNames[0] = "concat";
236+
outNames[1] = "concat_1";
237+
outNames[2] = "detection_out";
238+
239+
std::vector<Mat> target(outNames.size());
240+
for (int i = 0; i < outNames.size(); ++i)
241+
{
242+
std::string path = findDataFile("dnn/tensorflow/ssd_mobilenet_v1_coco." + outNames[i] + ".npy", false);
243+
target[i] = blobFromNPY(path);
244+
}
245+
246+
Net net = readNetFromTensorflow(netPath, netConfig);
247+
248+
net.setPreferableBackend(DNN_BACKEND_DEFAULT);
249+
net.setPreferableTarget(DNN_TARGET_OPENCL);
250+
251+
net.setInput(inp);
252+
253+
std::vector<Mat> output;
254+
net.forward(output, outNames);
255+
256+
normAssert(target[0].reshape(1, 1), output[0].reshape(1, 1));
257+
normAssert(target[1].reshape(1, 1), output[1].reshape(1, 1), "", 1e-5, 2e-4);
258+
normAssert(target[2].reshape(1, 1), output[2].reshape(1, 1), "", 4e-5, 1e-2);
259+
}
260+
222261
TEST(Test_TensorFlow, lstm)
223262
{
224263
runTensorFlowNet("lstm", true);

0 commit comments

Comments
 (0)