|
|
@ -42,6 +42,8 @@ |
|
|
|
#include "test_precomp.hpp" |
|
|
|
#include "test_precomp.hpp" |
|
|
|
#include "npy_blob.hpp" |
|
|
|
#include "npy_blob.hpp" |
|
|
|
#include <opencv2/dnn/shape_utils.hpp> |
|
|
|
#include <opencv2/dnn/shape_utils.hpp> |
|
|
|
|
|
|
|
#include <opencv2/core/ocl.hpp> |
|
|
|
|
|
|
|
#include <opencv2/ts/ocl_test.hpp> |
|
|
|
|
|
|
|
|
|
|
|
namespace cvtest |
|
|
|
namespace cvtest |
|
|
|
{ |
|
|
|
{ |
|
|
@ -119,6 +121,43 @@ TEST_P(Reproducibility_AlexNet, Accuracy) |
|
|
|
|
|
|
|
|
|
|
|
INSTANTIATE_TEST_CASE_P(Test_Caffe, Reproducibility_AlexNet, testing::Values(true, false)); |
|
|
|
INSTANTIATE_TEST_CASE_P(Test_Caffe, Reproducibility_AlexNet, testing::Values(true, false)); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
typedef testing::TestWithParam<tuple<bool> > Reproducibility_OCL_AlexNet; |
|
|
|
|
|
|
|
OCL_TEST_P(Reproducibility_OCL_AlexNet, Accuracy) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
bool readFromMemory = get<0>(GetParam()); |
|
|
|
|
|
|
|
Net net; |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
const string proto = findDataFile("dnn/bvlc_alexnet.prototxt", false); |
|
|
|
|
|
|
|
const string model = findDataFile("dnn/bvlc_alexnet.caffemodel", false); |
|
|
|
|
|
|
|
if (readFromMemory) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
string dataProto; |
|
|
|
|
|
|
|
ASSERT_TRUE(readFileInMemory(proto, dataProto)); |
|
|
|
|
|
|
|
string dataModel; |
|
|
|
|
|
|
|
ASSERT_TRUE(readFileInMemory(model, dataModel)); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
net = readNetFromCaffe(dataProto.c_str(), dataProto.size(), |
|
|
|
|
|
|
|
dataModel.c_str(), dataModel.size()); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
else |
|
|
|
|
|
|
|
net = readNetFromCaffe(proto, model); |
|
|
|
|
|
|
|
ASSERT_FALSE(net.empty()); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
net.setPreferableBackend(DNN_BACKEND_DEFAULT); |
|
|
|
|
|
|
|
net.setPreferableTarget(DNN_TARGET_OPENCL); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Mat sample = imread(_tf("grace_hopper_227.png")); |
|
|
|
|
|
|
|
ASSERT_TRUE(!sample.empty()); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
net.setInput(blobFromImage(sample, 1.0f, Size(227, 227), Scalar(), false), "data"); |
|
|
|
|
|
|
|
Mat out = net.forward("prob"); |
|
|
|
|
|
|
|
Mat ref = blobFromNPY(_tf("caffe_alexnet_prob.npy")); |
|
|
|
|
|
|
|
normAssert(ref, out); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
OCL_INSTANTIATE_TEST_CASE_P(Test_Caffe, Reproducibility_OCL_AlexNet, testing::Values(true, false)); |
|
|
|
|
|
|
|
|
|
|
|
#if !defined(_WIN32) || defined(_WIN64) |
|
|
|
#if !defined(_WIN32) || defined(_WIN64) |
|
|
|
TEST(Reproducibility_FCN, Accuracy) |
|
|
|
TEST(Reproducibility_FCN, Accuracy) |
|
|
|
{ |
|
|
|
{ |
|
|
@ -201,6 +240,38 @@ TEST(Reproducibility_MobileNet_SSD, Accuracy) |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
OCL_TEST(Reproducibility_MobileNet_SSD, Accuracy) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
const string proto = findDataFile("dnn/MobileNetSSD_deploy.prototxt", false); |
|
|
|
|
|
|
|
const string model = findDataFile("dnn/MobileNetSSD_deploy.caffemodel", false); |
|
|
|
|
|
|
|
Net net = readNetFromCaffe(proto, model); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
net.setPreferableBackend(DNN_BACKEND_DEFAULT); |
|
|
|
|
|
|
|
net.setPreferableTarget(DNN_TARGET_OPENCL); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Mat sample = imread(_tf("street.png")); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Mat inp = blobFromImage(sample, 1.0f / 127.5, Size(300, 300), Scalar(127.5, 127.5, 127.5), false); |
|
|
|
|
|
|
|
net.setInput(inp); |
|
|
|
|
|
|
|
Mat out = net.forward(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Mat ref = blobFromNPY(_tf("mobilenet_ssd_caffe_out.npy")); |
|
|
|
|
|
|
|
normAssert(ref, out); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Check that detections aren't preserved.
|
|
|
|
|
|
|
|
inp.setTo(0.0f); |
|
|
|
|
|
|
|
net.setInput(inp); |
|
|
|
|
|
|
|
out = net.forward(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const int numDetections = out.size[2]; |
|
|
|
|
|
|
|
ASSERT_NE(numDetections, 0); |
|
|
|
|
|
|
|
for (int i = 0; i < numDetections; ++i) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
float confidence = out.ptr<float>(0, 0, i)[2]; |
|
|
|
|
|
|
|
ASSERT_EQ(confidence, 0); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
TEST(Reproducibility_ResNet50, Accuracy) |
|
|
|
TEST(Reproducibility_ResNet50, Accuracy) |
|
|
|
{ |
|
|
|
{ |
|
|
|
Net net = readNetFromCaffe(findDataFile("dnn/ResNet-50-deploy.prototxt", false), |
|
|
|
Net net = readNetFromCaffe(findDataFile("dnn/ResNet-50-deploy.prototxt", false), |
|
|
@ -216,6 +287,24 @@ TEST(Reproducibility_ResNet50, Accuracy) |
|
|
|
normAssert(ref, out); |
|
|
|
normAssert(ref, out); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
OCL_TEST(Reproducibility_ResNet50, Accuracy) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
Net net = readNetFromCaffe(findDataFile("dnn/ResNet-50-deploy.prototxt", false), |
|
|
|
|
|
|
|
findDataFile("dnn/ResNet-50-model.caffemodel", false)); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
net.setPreferableBackend(DNN_BACKEND_DEFAULT); |
|
|
|
|
|
|
|
net.setPreferableTarget(DNN_TARGET_OPENCL); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Mat input = blobFromImage(imread(_tf("googlenet_0.png")), 1.0f, Size(224,224), Scalar(), false); |
|
|
|
|
|
|
|
ASSERT_TRUE(!input.empty()); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
net.setInput(input); |
|
|
|
|
|
|
|
Mat out = net.forward(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Mat ref = blobFromNPY(_tf("resnet50_prob.npy")); |
|
|
|
|
|
|
|
normAssert(ref, out); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
TEST(Reproducibility_SqueezeNet_v1_1, Accuracy) |
|
|
|
TEST(Reproducibility_SqueezeNet_v1_1, Accuracy) |
|
|
|
{ |
|
|
|
{ |
|
|
|
Net net = readNetFromCaffe(findDataFile("dnn/squeezenet_v1.1.prototxt", false), |
|
|
|
Net net = readNetFromCaffe(findDataFile("dnn/squeezenet_v1.1.prototxt", false), |
|
|
@ -231,6 +320,24 @@ TEST(Reproducibility_SqueezeNet_v1_1, Accuracy) |
|
|
|
normAssert(ref, out); |
|
|
|
normAssert(ref, out); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
OCL_TEST(Reproducibility_SqueezeNet_v1_1, Accuracy) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
Net net = readNetFromCaffe(findDataFile("dnn/squeezenet_v1.1.prototxt", false), |
|
|
|
|
|
|
|
findDataFile("dnn/squeezenet_v1.1.caffemodel", false)); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
net.setPreferableBackend(DNN_BACKEND_DEFAULT); |
|
|
|
|
|
|
|
net.setPreferableTarget(DNN_TARGET_OPENCL); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Mat input = blobFromImage(imread(_tf("googlenet_0.png")), 1.0f, Size(227,227), Scalar(), false); |
|
|
|
|
|
|
|
ASSERT_TRUE(!input.empty()); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
net.setInput(input); |
|
|
|
|
|
|
|
Mat out = net.forward(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Mat ref = blobFromNPY(_tf("squeezenet_v1.1_prob.npy")); |
|
|
|
|
|
|
|
normAssert(ref, out); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
TEST(Reproducibility_AlexNet_fp16, Accuracy) |
|
|
|
TEST(Reproducibility_AlexNet_fp16, Accuracy) |
|
|
|
{ |
|
|
|
{ |
|
|
|
const float l1 = 1e-5; |
|
|
|
const float l1 = 1e-5; |
|
|
|