mirror of
https://github.com/opencv/opencv.git
synced 2026-07-31 00:03:03 +04:00
Merge remote-tracking branch 'upstream/3.4' into merge-3.4
This commit is contained in:
@@ -65,6 +65,34 @@ TEST(Test_Darknet, read_yolo_voc)
|
||||
ASSERT_FALSE(net.empty());
|
||||
}
|
||||
|
||||
TEST(Test_Darknet, read_yolo_voc_stream)
|
||||
{
|
||||
Mat ref;
|
||||
Mat sample = imread(_tf("dog416.png"));
|
||||
Mat inp = blobFromImage(sample, 1.0/255, Size(416, 416), Scalar(), true, false);
|
||||
const std::string cfgFile = findDataFile("dnn/yolo-voc.cfg", false);
|
||||
const std::string weightsFile = findDataFile("dnn/yolo-voc.weights", false);
|
||||
// Import by paths.
|
||||
{
|
||||
Net net = readNetFromDarknet(cfgFile, weightsFile);
|
||||
net.setInput(inp);
|
||||
net.setPreferableBackend(DNN_BACKEND_OPENCV);
|
||||
ref = net.forward();
|
||||
}
|
||||
// Import from bytes array.
|
||||
{
|
||||
std::string cfg, weights;
|
||||
readFileInMemory(cfgFile, cfg);
|
||||
readFileInMemory(weightsFile, weights);
|
||||
|
||||
Net net = readNetFromDarknet(&cfg[0], cfg.size(), &weights[0], weights.size());
|
||||
net.setInput(inp);
|
||||
net.setPreferableBackend(DNN_BACKEND_OPENCV);
|
||||
Mat out = net.forward();
|
||||
normAssert(ref, out);
|
||||
}
|
||||
}
|
||||
|
||||
class Test_Darknet_layers : public DNNTestLayer
|
||||
{
|
||||
public:
|
||||
|
||||
@@ -104,8 +104,14 @@ TEST_P(Convolution, Accuracy)
|
||||
int backendId = get<0>(get<7>(GetParam()));
|
||||
int targetId = get<1>(get<7>(GetParam()));
|
||||
|
||||
if ((backendId == DNN_BACKEND_INFERENCE_ENGINE && targetId == DNN_TARGET_MYRIAD) ||
|
||||
(backendId == DNN_BACKEND_OPENCV && targetId == DNN_TARGET_OPENCL_FP16))
|
||||
if (backendId == DNN_BACKEND_INFERENCE_ENGINE && targetId == DNN_TARGET_MYRIAD)
|
||||
throw SkipTestException("");
|
||||
|
||||
// TODO: unstable test cases
|
||||
if (backendId == DNN_BACKEND_OPENCV && (targetId == DNN_TARGET_OPENCL || targetId == DNN_TARGET_OPENCL_FP16) &&
|
||||
inChannels == 6 && outChannels == 9 && group == 1 && inSize == Size(5, 6) &&
|
||||
kernel == Size(3, 1) && stride == Size(1, 1) && pad == Size(0, 1) && dilation == Size(1, 1) &&
|
||||
hasBias)
|
||||
throw SkipTestException("");
|
||||
|
||||
int sz[] = {outChannels, inChannels / group, kernel.height, kernel.width};
|
||||
@@ -353,8 +359,7 @@ TEST_P(FullyConnected, Accuracy)
|
||||
bool hasBias = get<3>(GetParam());
|
||||
int backendId = get<0>(get<4>(GetParam()));
|
||||
int targetId = get<1>(get<4>(GetParam()));
|
||||
if (backendId == DNN_BACKEND_INFERENCE_ENGINE ||
|
||||
(backendId == DNN_BACKEND_OPENCV && targetId == DNN_TARGET_OPENCL_FP16))
|
||||
if (backendId == DNN_BACKEND_INFERENCE_ENGINE)
|
||||
throw SkipTestException("");
|
||||
|
||||
Mat weights(outChannels, inChannels * inSize.height * inSize.width, CV_32F);
|
||||
@@ -692,10 +697,6 @@ TEST_P(Eltwise, Accuracy)
|
||||
int backendId = get<0>(get<4>(GetParam()));
|
||||
int targetId = get<1>(get<4>(GetParam()));
|
||||
|
||||
if (backendId == DNN_BACKEND_OPENCV &&
|
||||
(targetId == DNN_TARGET_OPENCL || targetId == DNN_TARGET_OPENCL_FP16))
|
||||
throw SkipTestException("");
|
||||
|
||||
Net net;
|
||||
|
||||
std::vector<int> convLayerIds(numConv);
|
||||
|
||||
@@ -763,8 +763,7 @@ TEST_P(Test_Caffe_layers, Average_pooling_kernel_area)
|
||||
// Test PriorBoxLayer in case of no aspect ratios (just squared proposals).
|
||||
TEST_P(Test_Caffe_layers, PriorBox_squares)
|
||||
{
|
||||
if (backend == DNN_BACKEND_INFERENCE_ENGINE ||
|
||||
(backend == DNN_BACKEND_OPENCV && (target == DNN_TARGET_OPENCL || target == DNN_TARGET_OPENCL_FP16)))
|
||||
if (backend == DNN_BACKEND_INFERENCE_ENGINE)
|
||||
throw SkipTestException("");
|
||||
LayerParams lp;
|
||||
lp.name = "testPriorBox";
|
||||
@@ -791,7 +790,8 @@ TEST_P(Test_Caffe_layers, PriorBox_squares)
|
||||
0.25, 0.0, 1.0, 1.0,
|
||||
0.1f, 0.1f, 0.2f, 0.2f,
|
||||
0.1f, 0.1f, 0.2f, 0.2f);
|
||||
normAssert(out.reshape(1, 4), ref);
|
||||
double l1 = (target == DNN_TARGET_OPENCL_FP16 || target == DNN_TARGET_MYRIAD) ? 2e-5 : 1e-5;
|
||||
normAssert(out.reshape(1, 4), ref, "", l1);
|
||||
}
|
||||
|
||||
typedef TestWithParam<tuple<int, int> > Layer_Test_DWconv_Prelu;
|
||||
|
||||
@@ -243,10 +243,15 @@ TEST_P(Test_TensorFlow_layers, l2_normalize_3d)
|
||||
runTensorFlowNet("l2_normalize_3d");
|
||||
}
|
||||
|
||||
typedef testing::TestWithParam<Target> Test_TensorFlow_nets;
|
||||
class Test_TensorFlow_nets : public DNNTestLayer {};
|
||||
|
||||
TEST_P(Test_TensorFlow_nets, MobileNet_SSD)
|
||||
{
|
||||
checkBackend();
|
||||
if ((backend == DNN_BACKEND_INFERENCE_ENGINE && target != DNN_TARGET_CPU) ||
|
||||
(backend == DNN_BACKEND_OPENCV && target == DNN_TARGET_OPENCL_FP16))
|
||||
throw SkipTestException("");
|
||||
|
||||
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);
|
||||
@@ -260,29 +265,30 @@ TEST_P(Test_TensorFlow_nets, MobileNet_SSD)
|
||||
outNames[1] = "concat_1";
|
||||
outNames[2] = "detection_out";
|
||||
|
||||
std::vector<Mat> target(outNames.size());
|
||||
std::vector<Mat> refs(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);
|
||||
refs[i] = blobFromNPY(path);
|
||||
}
|
||||
|
||||
Net net = readNetFromTensorflow(netPath, netConfig);
|
||||
net.setPreferableBackend(DNN_BACKEND_OPENCV);
|
||||
net.setPreferableTarget(GetParam());
|
||||
net.setPreferableBackend(backend);
|
||||
net.setPreferableTarget(target);
|
||||
|
||||
net.setInput(inp);
|
||||
|
||||
std::vector<Mat> output;
|
||||
net.forward(output, outNames);
|
||||
|
||||
normAssert(target[0].reshape(1, 1), output[0].reshape(1, 1), "", 1e-5, 1.5e-4);
|
||||
normAssert(target[1].reshape(1, 1), output[1].reshape(1, 1), "", 1e-5, 3e-4);
|
||||
normAssertDetections(target[2], output[2], "", 0.2);
|
||||
normAssert(refs[0].reshape(1, 1), output[0].reshape(1, 1), "", 1e-5, 1.5e-4);
|
||||
normAssert(refs[1].reshape(1, 1), output[1].reshape(1, 1), "", 1e-5, 3e-4);
|
||||
normAssertDetections(refs[2], output[2], "", 0.2);
|
||||
}
|
||||
|
||||
TEST_P(Test_TensorFlow_nets, Inception_v2_SSD)
|
||||
{
|
||||
checkBackend();
|
||||
std::string proto = findDataFile("dnn/ssd_inception_v2_coco_2017_11_17.pbtxt", false);
|
||||
std::string model = findDataFile("dnn/ssd_inception_v2_coco_2017_11_17.pb", false);
|
||||
|
||||
@@ -290,8 +296,8 @@ TEST_P(Test_TensorFlow_nets, Inception_v2_SSD)
|
||||
Mat img = imread(findDataFile("dnn/street.png", false));
|
||||
Mat blob = blobFromImage(img, 1.0f / 127.5, Size(300, 300), Scalar(127.5, 127.5, 127.5), true, false);
|
||||
|
||||
net.setPreferableBackend(DNN_BACKEND_OPENCV);
|
||||
net.setPreferableTarget(GetParam());
|
||||
net.setPreferableBackend(backend);
|
||||
net.setPreferableTarget(target);
|
||||
|
||||
net.setInput(blob);
|
||||
// Output has shape 1x1xNx7 where N - number of detections.
|
||||
@@ -302,16 +308,24 @@ TEST_P(Test_TensorFlow_nets, Inception_v2_SSD)
|
||||
0, 3, 0.75838411, 0.44668293, 0.45907149, 0.49459291, 0.52197015,
|
||||
0, 10, 0.95932811, 0.38349164, 0.32528657, 0.40387636, 0.39165527,
|
||||
0, 10, 0.93973452, 0.66561931, 0.37841269, 0.68074018, 0.42907384);
|
||||
normAssertDetections(ref, out, "", 0.5);
|
||||
double scoreDiff = (target == DNN_TARGET_OPENCL_FP16 || target == DNN_TARGET_MYRIAD) ? 5e-3 : default_l1;
|
||||
double iouDiff = (target == DNN_TARGET_OPENCL_FP16 || target == DNN_TARGET_MYRIAD) ? 0.025 : default_lInf;
|
||||
normAssertDetections(ref, out, "", 0.5, scoreDiff, iouDiff);
|
||||
}
|
||||
|
||||
TEST_P(Test_TensorFlow_nets, Inception_v2_Faster_RCNN)
|
||||
{
|
||||
checkBackend();
|
||||
if (backend == DNN_BACKEND_INFERENCE_ENGINE ||
|
||||
(backend == DNN_BACKEND_OPENCV && target == DNN_TARGET_OPENCL_FP16))
|
||||
throw SkipTestException("");
|
||||
|
||||
std::string proto = findDataFile("dnn/faster_rcnn_inception_v2_coco_2018_01_28.pbtxt", false);
|
||||
std::string model = findDataFile("dnn/faster_rcnn_inception_v2_coco_2018_01_28.pb", false);
|
||||
|
||||
Net net = readNetFromTensorflow(model, proto);
|
||||
net.setPreferableBackend(DNN_BACKEND_OPENCV);
|
||||
net.setPreferableBackend(backend);
|
||||
net.setPreferableTarget(target);
|
||||
Mat img = imread(findDataFile("dnn/dog416.png", false));
|
||||
Mat blob = blobFromImage(img, 1.0f / 127.5, Size(800, 600), Scalar(127.5, 127.5, 127.5), true, false);
|
||||
|
||||
@@ -324,6 +338,11 @@ TEST_P(Test_TensorFlow_nets, Inception_v2_Faster_RCNN)
|
||||
|
||||
TEST_P(Test_TensorFlow_nets, opencv_face_detector_uint8)
|
||||
{
|
||||
checkBackend();
|
||||
if (backend == DNN_BACKEND_INFERENCE_ENGINE &&
|
||||
(target == DNN_TARGET_OPENCL || target == DNN_TARGET_OPENCL_FP16 || target == DNN_TARGET_MYRIAD))
|
||||
throw SkipTestException("");
|
||||
|
||||
std::string proto = findDataFile("dnn/opencv_face_detector.pbtxt", false);
|
||||
std::string model = findDataFile("dnn/opencv_face_detector_uint8.pb", false);
|
||||
|
||||
@@ -331,9 +350,8 @@ TEST_P(Test_TensorFlow_nets, opencv_face_detector_uint8)
|
||||
Mat img = imread(findDataFile("gpu/lbpcascade/er.png", false));
|
||||
Mat blob = blobFromImage(img, 1.0, Size(), Scalar(104.0, 177.0, 123.0), false, false);
|
||||
|
||||
net.setPreferableBackend(DNN_BACKEND_OPENCV);
|
||||
net.setPreferableTarget(GetParam());
|
||||
|
||||
net.setPreferableBackend(backend);
|
||||
net.setPreferableTarget(target);
|
||||
net.setInput(blob);
|
||||
// Output has shape 1x1xNx7 where N - number of detections.
|
||||
// An every detection is a vector of values [id, classId, confidence, left, top, right, bottom]
|
||||
@@ -346,7 +364,9 @@ TEST_P(Test_TensorFlow_nets, opencv_face_detector_uint8)
|
||||
0, 1, 0.98977017, 0.23901358, 0.09084064, 0.29902688, 0.1769477,
|
||||
0, 1, 0.97203469, 0.67965847, 0.06876482, 0.73999709, 0.1513494,
|
||||
0, 1, 0.95097077, 0.51901293, 0.45863652, 0.5777427, 0.5347801);
|
||||
normAssertDetections(ref, out, "", 0.9, 3.4e-3, 1e-2);
|
||||
double scoreDiff = (target == DNN_TARGET_OPENCL_FP16 || target == DNN_TARGET_MYRIAD) ? 4e-3 : 3.4e-3;
|
||||
double iouDiff = (target == DNN_TARGET_OPENCL_FP16 || target == DNN_TARGET_MYRIAD) ? 0.017 : 1e-2;
|
||||
normAssertDetections(ref, out, "", 0.9, scoreDiff, iouDiff);
|
||||
}
|
||||
|
||||
// inp = cv.imread('opencv_extra/testdata/cv/ximgproc/sources/08.png')
|
||||
@@ -360,6 +380,10 @@ TEST_P(Test_TensorFlow_nets, opencv_face_detector_uint8)
|
||||
// np.save('east_text_detection.geometry.npy', geometry)
|
||||
TEST_P(Test_TensorFlow_nets, EAST_text_detection)
|
||||
{
|
||||
checkBackend();
|
||||
if (target == DNN_TARGET_OPENCL_FP16 || target == DNN_TARGET_MYRIAD)
|
||||
throw SkipTestException("");
|
||||
|
||||
std::string netPath = findDataFile("dnn/frozen_east_text_detection.pb", false);
|
||||
std::string imgPath = findDataFile("cv/ximgproc/sources/08.png", false);
|
||||
std::string refScoresPath = findDataFile("dnn/east_text_detection.scores.npy", false);
|
||||
@@ -367,7 +391,8 @@ TEST_P(Test_TensorFlow_nets, EAST_text_detection)
|
||||
|
||||
Net net = readNet(findDataFile("dnn/frozen_east_text_detection.pb", false));
|
||||
|
||||
net.setPreferableTarget(GetParam());
|
||||
net.setPreferableBackend(backend);
|
||||
net.setPreferableTarget(target);
|
||||
|
||||
Mat img = imread(imgPath);
|
||||
Mat inp = blobFromImage(img, 1.0, Size(), Scalar(123.68, 116.78, 103.94), true, false);
|
||||
@@ -386,7 +411,7 @@ TEST_P(Test_TensorFlow_nets, EAST_text_detection)
|
||||
normAssert(geometry, blobFromNPY(refGeometryPath), "geometry", 1e-4, 3e-3);
|
||||
}
|
||||
|
||||
INSTANTIATE_TEST_CASE_P(/**/, Test_TensorFlow_nets, availableDnnTargets());
|
||||
INSTANTIATE_TEST_CASE_P(/**/, Test_TensorFlow_nets, dnnBackendsAndTargets());
|
||||
|
||||
TEST_P(Test_TensorFlow_layers, fp16_weights)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user