mirror of
https://github.com/opencv/opencv.git
synced 2026-07-29 23:33:05 +04:00
Merge pull request #28678 from omrope79:caffe-importer-cleanup
Caffe importer cleanup #28678 Merge with: https://github.com/opencv/opencv_extra/pull/1324 ### Pull Request Readiness Checklist See details at https://github.com/opencv/opencv/wiki/How_to_contribute#making-a-good-pull-request - [x] I agree to contribute to the project under Apache 2 License. - [x] To the best of my knowledge, the proposed patch is not based on a code under GPL or another license that is incompatible with OpenCV - [x] The PR is proposed to the proper branch - [x] There is a reference to the original bug report and related work - [x] There is accuracy test, performance test and test data in opencv_extra repository, if applicable - [x] The feature is well documented and sample code can be built with the project CMake
This commit is contained in:
@@ -63,155 +63,6 @@ static String _tf(TString filename)
|
||||
return (basetestdir + "dnn/layers/") + filename;
|
||||
}
|
||||
|
||||
class Test_Caffe_layers : public DNNTestLayer
|
||||
{
|
||||
public:
|
||||
void testLayerUsingCaffeModels(const String& basename, bool useCaffeModel = false,
|
||||
bool useCommonInputBlob = true, double l1 = 0.0, double lInf = 0.0,
|
||||
int numInps = 1, int numOuts = 1)
|
||||
{
|
||||
CV_Assert_N(numInps >= 1, numInps <= 10, numOuts >= 1, numOuts <= 10);
|
||||
String prototxt = _tf(basename + ".prototxt");
|
||||
String caffemodel = _tf(basename + ".caffemodel");
|
||||
|
||||
std::vector<Mat> inps, refs, outs;
|
||||
|
||||
if (numInps > 1)
|
||||
{
|
||||
for (int i = 0; i < numInps; i++)
|
||||
{
|
||||
String inpfile = _tf(basename + cv::format(".input_%d.npy", i));
|
||||
inps.push_back(blobFromNPY(inpfile));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
String inpfile = (useCommonInputBlob) ? _tf("blob.npy") : _tf(basename + ".input.npy");
|
||||
inps.push_back(blobFromNPY(inpfile));
|
||||
}
|
||||
|
||||
if (numOuts > 1)
|
||||
{
|
||||
for (int i = 0; i < numOuts; i++)
|
||||
{
|
||||
String outfile = _tf(basename + cv::format("_%d.npy", i));
|
||||
refs.push_back(blobFromNPY(outfile));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
String outfile = _tf(basename + ".npy");
|
||||
refs.push_back(blobFromNPY(outfile));
|
||||
}
|
||||
|
||||
Net net = readNetFromCaffe(prototxt, (useCaffeModel) ? caffemodel : String());
|
||||
ASSERT_FALSE(net.empty());
|
||||
checkBackend(&inps[0], &refs[0]);
|
||||
|
||||
net.setPreferableBackend(backend);
|
||||
net.setPreferableTarget(target);
|
||||
|
||||
String inp_name = "input";
|
||||
if (numInps > 1)
|
||||
{
|
||||
for (int i = 0; i < numInps; i++)
|
||||
{
|
||||
net.setInput(inps[i], inp_name + cv::format("_%d", i));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
net.setInput(inps.back(), inp_name);
|
||||
}
|
||||
|
||||
net.forward(outs);
|
||||
for (int i = 0; i < refs.size(); i++)
|
||||
{
|
||||
normAssert(refs[i], outs[i], "", l1 ? l1 : default_l1, lInf ? lInf : default_lInf);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
TEST_P(Test_Caffe_layers, Softmax)
|
||||
{
|
||||
testLayerUsingCaffeModels("layer_softmax");
|
||||
}
|
||||
|
||||
TEST_P(Test_Caffe_layers, LRN)
|
||||
{
|
||||
double l1 = 0.0, lInf = 0.0;
|
||||
// The OpenCL kernels use the native_ math functions which have
|
||||
// implementation defined accuracy, so we use relaxed thresholds. See
|
||||
// https://github.com/opencv/opencv/issues/9821 for more details.
|
||||
if (target == DNN_TARGET_OPENCL)
|
||||
{
|
||||
l1 = 0.01;
|
||||
lInf = 0.01;
|
||||
}
|
||||
testLayerUsingCaffeModels("layer_lrn_spatial", false, true, l1, lInf);
|
||||
testLayerUsingCaffeModels("layer_lrn_channels", false, true, l1, lInf);
|
||||
}
|
||||
|
||||
TEST_P(Test_Caffe_layers, Convolution)
|
||||
{
|
||||
testLayerUsingCaffeModels("layer_convolution", true);
|
||||
}
|
||||
|
||||
TEST_P(Test_Caffe_layers, DeConvolution)
|
||||
{
|
||||
if(target == DNN_TARGET_CUDA_FP16)
|
||||
applyTestTag(CV_TEST_TAG_DNN_SKIP_CUDA_FP16);
|
||||
testLayerUsingCaffeModels("layer_deconvolution", true, false);
|
||||
}
|
||||
|
||||
TEST_P(Test_Caffe_layers, InnerProduct)
|
||||
{
|
||||
#if defined(INF_ENGINE_RELEASE) && INF_ENGINE_VER_MAJOR_LT(2021040000)
|
||||
if (backend == DNN_BACKEND_INFERENCE_ENGINE_NN_BUILDER_2019)
|
||||
applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_NN_BUILDER);
|
||||
if (backend == DNN_BACKEND_INFERENCE_ENGINE_NGRAPH)
|
||||
applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_NGRAPH);
|
||||
#endif
|
||||
#if defined(INF_ENGINE_RELEASE) && INF_ENGINE_VER_MAJOR_EQ(2021040000)
|
||||
// IE exception: Ngraph operation Reshape with name Reshape_4219609 has dynamic output shape on 0 port, but CPU plug-in supports only static shape
|
||||
if (backend == DNN_BACKEND_INFERENCE_ENGINE_NGRAPH && (target == DNN_TARGET_OPENCL || target == DNN_TARGET_OPENCL_FP16))
|
||||
applyTestTag(target == DNN_TARGET_OPENCL ? CV_TEST_TAG_DNN_SKIP_IE_OPENCL : CV_TEST_TAG_DNN_SKIP_IE_OPENCL_FP16,
|
||||
CV_TEST_TAG_DNN_SKIP_IE_NGRAPH, CV_TEST_TAG_DNN_SKIP_IE_VERSION
|
||||
);
|
||||
#endif
|
||||
|
||||
if (backend == DNN_BACKEND_OPENCV && target == DNN_TARGET_OPENCL_FP16)
|
||||
applyTestTag(CV_TEST_TAG_DNN_SKIP_OPENCL_FP16);
|
||||
if (backend == DNN_BACKEND_OPENCV && target == DNN_TARGET_CPU_FP16)
|
||||
applyTestTag(CV_TEST_TAG_DNN_SKIP_CPU_FP16);
|
||||
|
||||
double l1 = 0.0, lInf = 0.0;
|
||||
if (backend == DNN_BACKEND_INFERENCE_ENGINE_NGRAPH && (target == DNN_TARGET_OPENCL || target == DNN_TARGET_OPENCL_FP16))
|
||||
{
|
||||
l1 = 5e-3;
|
||||
lInf = 2e-2;
|
||||
}
|
||||
testLayerUsingCaffeModels("layer_inner_product", true, true, l1, lInf);
|
||||
}
|
||||
|
||||
TEST_P(Test_Caffe_layers, Pooling_max)
|
||||
{
|
||||
testLayerUsingCaffeModels("layer_pooling_max");
|
||||
}
|
||||
|
||||
TEST_P(Test_Caffe_layers, Pooling_ave)
|
||||
{
|
||||
testLayerUsingCaffeModels("layer_pooling_ave");
|
||||
}
|
||||
|
||||
TEST_P(Test_Caffe_layers, MVN)
|
||||
{
|
||||
if(backend == DNN_BACKEND_CUDA)
|
||||
applyTestTag(CV_TEST_TAG_DNN_SKIP_CUDA); /* MVN is unsupported */
|
||||
|
||||
testLayerUsingCaffeModels("layer_mvn");
|
||||
}
|
||||
|
||||
void testReshape(const MatShape& inputShape, const MatShape& targetShape,
|
||||
int axis = 0, int num_axes = -1,
|
||||
MatShape mask = MatShape())
|
||||
@@ -259,192 +110,6 @@ TEST(Layer_Test_Reshape, Accuracy)
|
||||
}
|
||||
}
|
||||
|
||||
TEST_P(Test_Caffe_layers, BatchNorm)
|
||||
{
|
||||
testLayerUsingCaffeModels("layer_batch_norm", true);
|
||||
testLayerUsingCaffeModels("layer_batch_norm_local_stats", true, false);
|
||||
}
|
||||
|
||||
TEST_P(Test_Caffe_layers, ReLU)
|
||||
{
|
||||
testLayerUsingCaffeModels("layer_relu");
|
||||
}
|
||||
|
||||
TEST_P(Test_Caffe_layers, Dropout)
|
||||
{
|
||||
testLayerUsingCaffeModels("layer_dropout");
|
||||
}
|
||||
|
||||
TEST_P(Test_Caffe_layers, Concat)
|
||||
{
|
||||
if (cvtest::skipUnstableTests && (backend == DNN_BACKEND_VKCOM))
|
||||
{
|
||||
throw SkipTestException("Test_Caffe_layers.Concat test produces unstable result with Vulkan");
|
||||
}
|
||||
|
||||
#if defined(INF_ENGINE_RELEASE)
|
||||
#if INF_ENGINE_VER_MAJOR_GE(2019010000) && INF_ENGINE_VER_MAJOR_LT(2019020000)
|
||||
if (backend == DNN_BACKEND_INFERENCE_ENGINE_NN_BUILDER_2019 && target == DNN_TARGET_MYRIAD)
|
||||
applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_MYRIAD, CV_TEST_TAG_DNN_SKIP_IE_NN_BUILDER, CV_TEST_TAG_DNN_SKIP_IE_VERSION);
|
||||
#elif INF_ENGINE_VER_MAJOR_EQ(2019020000)
|
||||
if (backend == DNN_BACKEND_INFERENCE_ENGINE_NN_BUILDER_2019 &&
|
||||
(target == DNN_TARGET_OPENCL || target == DNN_TARGET_OPENCL_FP16))
|
||||
applyTestTag(target == DNN_TARGET_OPENCL ? CV_TEST_TAG_DNN_SKIP_IE_OPENCL : CV_TEST_TAG_DNN_SKIP_IE_OPENCL_FP16,
|
||||
CV_TEST_TAG_DNN_SKIP_IE_NN_BUILDER, CV_TEST_TAG_DNN_SKIP_IE_VERSION);
|
||||
#endif
|
||||
|
||||
#if INF_ENGINE_VER_MAJOR_LT(2021040000)
|
||||
if (backend == DNN_BACKEND_INFERENCE_ENGINE_NGRAPH &&
|
||||
(target == DNN_TARGET_OPENCL || target == DNN_TARGET_OPENCL_FP16))
|
||||
applyTestTag(target == DNN_TARGET_OPENCL ? CV_TEST_TAG_DNN_SKIP_IE_OPENCL : CV_TEST_TAG_DNN_SKIP_IE_OPENCL_FP16,
|
||||
CV_TEST_TAG_DNN_SKIP_IE_NGRAPH, CV_TEST_TAG_DNN_SKIP_IE_VERSION);
|
||||
#endif
|
||||
|
||||
#endif
|
||||
testLayerUsingCaffeModels("layer_concat");
|
||||
testLayerUsingCaffeModels("layer_concat_optim", true, false);
|
||||
testLayerUsingCaffeModels("layer_concat_shared_input", true, false);
|
||||
}
|
||||
|
||||
TEST_P(Test_Caffe_layers, Fused_Concat)
|
||||
{
|
||||
if (backend == DNN_BACKEND_INFERENCE_ENGINE_NN_BUILDER_2019 && (target == DNN_TARGET_OPENCL || target == DNN_TARGET_OPENCL_FP16))
|
||||
applyTestTag(target == DNN_TARGET_OPENCL ? CV_TEST_TAG_DNN_SKIP_IE_OPENCL : CV_TEST_TAG_DNN_SKIP_IE_OPENCL_FP16,
|
||||
CV_TEST_TAG_DNN_SKIP_IE_NN_BUILDER, CV_TEST_TAG_DNN_SKIP_IE_VERSION);
|
||||
|
||||
checkBackend();
|
||||
|
||||
// Test case
|
||||
// input
|
||||
// |
|
||||
// v
|
||||
// some_layer
|
||||
// | |
|
||||
// v v
|
||||
// concat
|
||||
Net net;
|
||||
int interLayer;
|
||||
{
|
||||
LayerParams lp;
|
||||
lp.type = "AbsVal";
|
||||
lp.name = "someLayer";
|
||||
interLayer = net.addLayerToPrev(lp.name, lp.type, lp);
|
||||
}
|
||||
{
|
||||
LayerParams lp;
|
||||
lp.set("axis", 1);
|
||||
lp.type = "Concat";
|
||||
lp.name = "testConcat";
|
||||
int id = net.addLayer(lp.name, lp.type, lp);
|
||||
net.connect(interLayer, 0, id, 0);
|
||||
net.connect(interLayer, 0, id, 1);
|
||||
}
|
||||
int shape[] = {1, 2, 3, 4};
|
||||
Mat input(4, shape, CV_32F);
|
||||
randu(input, 0.0f, 1.0f); // [0, 1] to make AbsVal an identity transformation.
|
||||
|
||||
net.setInput(input);
|
||||
net.setPreferableBackend(backend);
|
||||
net.setPreferableTarget(target);
|
||||
Mat out = net.forward();
|
||||
|
||||
normAssert(slice(out, Range::all(), Range(0, 2), Range::all(), Range::all()), input, "", default_l1, default_lInf);
|
||||
normAssert(slice(out, Range::all(), Range(2, 4), Range::all(), Range::all()), input, "", default_l1, default_lInf);
|
||||
}
|
||||
|
||||
TEST_P(Test_Caffe_layers, Eltwise)
|
||||
{
|
||||
if (backend == DNN_BACKEND_INFERENCE_ENGINE_NN_BUILDER_2019 && target == DNN_TARGET_MYRIAD)
|
||||
applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_MYRIAD);
|
||||
testLayerUsingCaffeModels("layer_eltwise");
|
||||
}
|
||||
|
||||
TEST_P(Test_Caffe_layers, PReLU)
|
||||
{
|
||||
double lInf = (target == DNN_TARGET_MYRIAD || target == DNN_TARGET_OPENCL_FP16 || target == DNN_TARGET_CPU_FP16) ? 0.021 : 0.0;
|
||||
testLayerUsingCaffeModels("layer_prelu", true, true, 0.0, lInf);
|
||||
}
|
||||
|
||||
// TODO: fix an unstable test case
|
||||
TEST_P(Test_Caffe_layers, layer_prelu_fc)
|
||||
{
|
||||
if (backend == DNN_BACKEND_INFERENCE_ENGINE_NGRAPH)
|
||||
applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_NGRAPH); // TODO: fix this test for OpenVINO
|
||||
|
||||
if (backend == DNN_BACKEND_OPENCV && target == DNN_TARGET_OPENCL_FP16)
|
||||
applyTestTag(CV_TEST_TAG_DNN_SKIP_OPENCL_FP16);
|
||||
// Reference output values are in range [-0.0001, 10.3906]
|
||||
double l1 = (target == DNN_TARGET_MYRIAD) ? 0.005 : 0.0;
|
||||
double lInf = (target == DNN_TARGET_MYRIAD) ? 0.021 : 0.0;
|
||||
#if defined(INF_ENGINE_RELEASE) && INF_ENGINE_VER_MAJOR_GE(2020040000)
|
||||
if (backend == DNN_BACKEND_INFERENCE_ENGINE_NGRAPH && target == DNN_TARGET_OPENCL)
|
||||
{
|
||||
l1 = 0.006f; lInf = 0.05f;
|
||||
}
|
||||
if (backend == DNN_BACKEND_INFERENCE_ENGINE_NGRAPH && target == DNN_TARGET_OPENCL_FP16)
|
||||
{
|
||||
l1 = 0.01f; lInf = 0.05f;
|
||||
}
|
||||
#endif
|
||||
testLayerUsingCaffeModels("layer_prelu_fc", true, false, l1, lInf);
|
||||
}
|
||||
|
||||
TEST_P(Test_Caffe_layers, Reshape_Split_Slice)
|
||||
{
|
||||
#if defined(INF_ENGINE_RELEASE) && INF_ENGINE_VER_MAJOR_LT(2023000000)
|
||||
if (backend == DNN_BACKEND_INFERENCE_ENGINE_NN_BUILDER_2019)
|
||||
applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_NN_BUILDER);
|
||||
if (backend == DNN_BACKEND_INFERENCE_ENGINE_NGRAPH)
|
||||
applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_NGRAPH);
|
||||
#endif
|
||||
|
||||
Net net = readNetFromCaffe(_tf("reshape_and_slice_routines.prototxt"));
|
||||
ASSERT_FALSE(net.empty());
|
||||
|
||||
net.setPreferableBackend(backend);
|
||||
net.setPreferableTarget(target);
|
||||
|
||||
Mat input(6, 12, CV_32F);
|
||||
RNG rng(0);
|
||||
rng.fill(input, RNG::UNIFORM, -1, 1);
|
||||
|
||||
net.setInput(input, "input");
|
||||
Mat output;
|
||||
if (net.getMainGraph())
|
||||
output = net.forward();
|
||||
else
|
||||
output = net.forward("output");
|
||||
|
||||
normAssert(input, output, "", default_l1, default_lInf);
|
||||
}
|
||||
|
||||
TEST_P(Test_Caffe_layers, Conv_Elu)
|
||||
{
|
||||
#if defined(INF_ENGINE_RELEASE) && INF_ENGINE_RELEASE <= 2018050000
|
||||
if (backend == DNN_BACKEND_INFERENCE_ENGINE_NN_BUILDER_2019 && target == DNN_TARGET_MYRIAD)
|
||||
applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_MYRIAD, CV_TEST_TAG_DNN_SKIP_IE_VERSION);
|
||||
#endif
|
||||
|
||||
Net net = readNetFromTensorflow(_tf("layer_elu_model.pb"));
|
||||
ASSERT_FALSE(net.empty());
|
||||
|
||||
Mat inp = blobFromNPY(_tf("layer_elu_in.npy"));
|
||||
Mat ref = blobFromNPY(_tf("layer_elu_out.npy"));
|
||||
|
||||
net.setInput(inp, "input");
|
||||
net.setPreferableBackend(backend);
|
||||
net.setPreferableTarget(target);
|
||||
Mat out = net.forward();
|
||||
|
||||
double l1 = default_l1, lInf = default_lInf;
|
||||
if (target == DNN_TARGET_CUDA_FP16)
|
||||
{
|
||||
l1 = 0.0002;
|
||||
lInf = 0.0005;
|
||||
}
|
||||
normAssert(ref, out, "", l1, lInf);
|
||||
}
|
||||
|
||||
class Layer_LSTM_Test : public ::testing::Test
|
||||
{
|
||||
public:
|
||||
@@ -768,148 +433,6 @@ TEST(Layer_MHARoPe_Test_Accuracy_with_, Pytorch)
|
||||
normAssert(h_t_reference, outputs[0]);
|
||||
}
|
||||
|
||||
TEST_P(Test_Caffe_layers, Accum)
|
||||
{
|
||||
#ifdef OPENCV_DNN_EXTERNAL_PROTOBUF
|
||||
throw SkipTestException("Requires patched protobuf");
|
||||
#else
|
||||
if (backend == DNN_BACKEND_OPENCV && target != DNN_TARGET_CPU)
|
||||
applyTestTag(CV_TEST_TAG_DNN_SKIP_OPENCL, CV_TEST_TAG_DNN_SKIP_OPENCL_FP16);
|
||||
|
||||
testLayerUsingCaffeModels("accum", false, false, 0.0, 0.0, 2);
|
||||
testLayerUsingCaffeModels("accum_ref", false, false, 0.0, 0.0, 2);
|
||||
#endif
|
||||
}
|
||||
|
||||
TEST_P(Test_Caffe_layers, FlowWarp)
|
||||
{
|
||||
if (backend == DNN_BACKEND_OPENCV && target == DNN_TARGET_OPENCL_FP16)
|
||||
applyTestTag(CV_TEST_TAG_DNN_SKIP_OPENCL_FP16);
|
||||
|
||||
testLayerUsingCaffeModels("flow_warp", false, false, 0.0, 0.0, 2);
|
||||
}
|
||||
|
||||
TEST_P(Test_Caffe_layers, ChannelNorm)
|
||||
{
|
||||
if (backend == DNN_BACKEND_OPENCV && target == DNN_TARGET_OPENCL_FP16)
|
||||
applyTestTag(CV_TEST_TAG_DNN_SKIP_OPENCL_FP16);
|
||||
testLayerUsingCaffeModels("channel_norm", false, false);
|
||||
}
|
||||
|
||||
TEST_P(Test_Caffe_layers, DataAugmentation)
|
||||
{
|
||||
#ifdef OPENCV_DNN_EXTERNAL_PROTOBUF
|
||||
throw SkipTestException("Requires patched protobuf");
|
||||
#else
|
||||
if (backend == DNN_BACKEND_OPENCV && target == DNN_TARGET_OPENCL_FP16)
|
||||
applyTestTag(CV_TEST_TAG_DNN_SKIP_OPENCL_FP16);
|
||||
testLayerUsingCaffeModels("data_augmentation", true, false);
|
||||
testLayerUsingCaffeModels("data_augmentation_2x1", true, false);
|
||||
testLayerUsingCaffeModels("data_augmentation_8x6", true, false);
|
||||
#endif
|
||||
}
|
||||
|
||||
TEST_P(Test_Caffe_layers, Resample)
|
||||
{
|
||||
#ifdef OPENCV_DNN_EXTERNAL_PROTOBUF
|
||||
throw SkipTestException("Requires patched protobuf");
|
||||
#else
|
||||
#if defined(INF_ENGINE_RELEASE) && INF_ENGINE_VER_MAJOR_LT(2023000000)
|
||||
if (backend != DNN_BACKEND_OPENCV)
|
||||
applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_NN_BUILDER, CV_TEST_TAG_DNN_SKIP_IE_NGRAPH);
|
||||
#endif
|
||||
testLayerUsingCaffeModels("nearest_2inps", false, false, 0.0, 0.0, 2);
|
||||
testLayerUsingCaffeModels("nearest", false, false);
|
||||
#endif
|
||||
}
|
||||
|
||||
TEST_P(Test_Caffe_layers, Correlation)
|
||||
{
|
||||
#ifdef OPENCV_DNN_EXTERNAL_PROTOBUF
|
||||
throw SkipTestException("Requires patched protobuf");
|
||||
#else
|
||||
if (backend == DNN_BACKEND_OPENCV && target == DNN_TARGET_OPENCL_FP16)
|
||||
applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_NGRAPH, CV_TEST_TAG_DNN_SKIP_IE_NN_BUILDER,
|
||||
CV_TEST_TAG_DNN_SKIP_OPENCL, CV_TEST_TAG_DNN_SKIP_OPENCL_FP16);
|
||||
testLayerUsingCaffeModels("correlation", false, false, 0.0, 0.0, 2);
|
||||
#endif
|
||||
}
|
||||
|
||||
TEST_P(Test_Caffe_layers, Convolution2Inputs)
|
||||
{
|
||||
testLayerUsingCaffeModels("conv_2_inps", true, false, 0.0, 0.0, 2);
|
||||
}
|
||||
|
||||
TEST_P(Test_Caffe_layers, ROIPooling_Accuracy)
|
||||
{
|
||||
Net net = readNetFromCaffe(_tf("net_roi_pooling.prototxt"));
|
||||
ASSERT_FALSE(net.empty());
|
||||
|
||||
Mat inp = blobFromNPY(_tf("net_roi_pooling.input.npy"));
|
||||
Mat rois = blobFromNPY(_tf("net_roi_pooling.rois.npy"));
|
||||
Mat ref = blobFromNPY(_tf("net_roi_pooling.npy"));
|
||||
|
||||
checkBackend(&inp, &ref);
|
||||
|
||||
net.setPreferableBackend(backend);
|
||||
net.setPreferableTarget(target);
|
||||
|
||||
net.setInput(inp, "input");
|
||||
net.setInput(rois, "rois");
|
||||
|
||||
Mat out = net.forward();
|
||||
|
||||
double l1 = (target == DNN_TARGET_OPENCL_FP16 || target == DNN_TARGET_MYRIAD) ? 1e-3 : 1e-5;
|
||||
double lInf = (target == DNN_TARGET_OPENCL_FP16 || target == DNN_TARGET_MYRIAD) ? 1e-3 : 1e-4;
|
||||
if (target == DNN_TARGET_CUDA_FP16)
|
||||
{
|
||||
l1 = 2e-4;
|
||||
lInf = 9e-4;
|
||||
}
|
||||
normAssert(out, ref, "", l1, lInf);
|
||||
}
|
||||
|
||||
TEST_P(Test_Caffe_layers, FasterRCNN_Proposal)
|
||||
{
|
||||
if (backend == DNN_BACKEND_OPENCV && target == DNN_TARGET_OPENCL_FP16)
|
||||
applyTestTag(CV_TEST_TAG_DNN_SKIP_OPENCL_FP16);
|
||||
if (backend == DNN_BACKEND_INFERENCE_ENGINE_NN_BUILDER_2019)
|
||||
applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_NN_BUILDER);
|
||||
if (backend == DNN_BACKEND_INFERENCE_ENGINE_NGRAPH)
|
||||
applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_NGRAPH);
|
||||
if(backend == DNN_BACKEND_CUDA)
|
||||
applyTestTag(CV_TEST_TAG_DNN_SKIP_CUDA); /* Proposal layer is unsupported */
|
||||
|
||||
Net net = readNetFromCaffe(_tf("net_faster_rcnn_proposal.prototxt"));
|
||||
|
||||
Mat scores = blobFromNPY(_tf("net_faster_rcnn_proposal.scores.npy"));
|
||||
Mat deltas = blobFromNPY(_tf("net_faster_rcnn_proposal.deltas.npy"));
|
||||
Mat imInfo = (Mat_<float>(1, 3) << 600, 800, 1.6f);
|
||||
|
||||
net.setInput(scores, "rpn_cls_prob_reshape");
|
||||
net.setInput(deltas, "rpn_bbox_pred");
|
||||
net.setInput(imInfo, "im_info");
|
||||
|
||||
std::vector<Mat> outs;
|
||||
net.setPreferableBackend(backend);
|
||||
net.setPreferableTarget(target);
|
||||
net.forward(outs);
|
||||
|
||||
for (int i = 0; i < 2; ++i)
|
||||
{
|
||||
Mat ref = blobFromNPY(_tf(i == 0 ? "net_faster_rcnn_proposal.out_rois.npy" :
|
||||
"net_faster_rcnn_proposal.out_scores.npy"));
|
||||
const int numDets = ref.size[0];
|
||||
EXPECT_LE(numDets, outs[i].size[0]);
|
||||
normAssert(outs[i].rowRange(0, numDets), ref);
|
||||
|
||||
if (numDets < outs[i].size[0])
|
||||
{
|
||||
EXPECT_EQ(countNonZero(outs[i].rowRange(numDets, outs[i].size[0])), 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
typedef testing::TestWithParam<tuple<Vec4i, Vec2i, bool> > Scale_untrainable;
|
||||
TEST_P(Scale_untrainable, Accuracy)
|
||||
{
|
||||
@@ -1072,6 +595,8 @@ INSTANTIATE_TEST_CASE_P(Layer_Test, Crop, Combine(
|
||||
/*offset value*/ Values(3, 4)
|
||||
));
|
||||
|
||||
class Test_Caffe_layers : public DNNTestLayer {};
|
||||
|
||||
// Check that by default average pooling layer should not count zero padded values
|
||||
// into the normalization area.
|
||||
TEST_P(Test_Caffe_layers, Average_pooling_kernel_area)
|
||||
@@ -1099,32 +624,6 @@ TEST_P(Test_Caffe_layers, Average_pooling_kernel_area)
|
||||
normAssert(out, blobFromImage(ref));
|
||||
}
|
||||
|
||||
TEST_P(Test_Caffe_layers, PriorBox_repeated)
|
||||
{
|
||||
Net net = readNet(_tf("prior_box.prototxt"));
|
||||
int inp_size[] = {1, 3, 10, 10};
|
||||
int shape_size[] = {1, 2, 3, 4};
|
||||
Mat inp(4, inp_size, CV_32F);
|
||||
randu(inp, -1.0f, 1.0f);
|
||||
Mat shape(4, shape_size, CV_32F);
|
||||
randu(shape, -1.0f, 1.0f);
|
||||
net.setInput(inp, "data");
|
||||
net.setInput(shape, "shape");
|
||||
net.setPreferableBackend(backend);
|
||||
net.setPreferableTarget(target);
|
||||
Mat out = net.forward();
|
||||
Mat ref = blobFromNPY(_tf("priorbox_output.npy"));
|
||||
|
||||
double l1 = (target == DNN_TARGET_OPENCL_FP16 || target == DNN_TARGET_MYRIAD) ? 1e-3 : 1e-5;
|
||||
double lInf = (target == DNN_TARGET_OPENCL_FP16 || target == DNN_TARGET_MYRIAD) ? 1e-3 : 1e-4;
|
||||
if (target == DNN_TARGET_CUDA_FP16)
|
||||
{
|
||||
l1 = 7e-5;
|
||||
lInf = 0.0005;
|
||||
}
|
||||
normAssert(out, ref, "", l1, lInf);
|
||||
}
|
||||
|
||||
// Test PriorBoxLayer in case of no aspect ratios (just squared proposals).
|
||||
TEST_P(Test_Caffe_layers, PriorBox_squares)
|
||||
{
|
||||
@@ -1289,46 +788,6 @@ INSTANTIATE_TEST_CASE_P(/**/, Layer_Test_DWconv_Prelu, Combine(Values(3, 6), Val
|
||||
// ./ModelOptimizer -w /path/to/caffemodel -d /path/to/prototxt \
|
||||
// -p FP32 -i -b ${batch_size} -o /path/to/output/folder
|
||||
typedef testing::TestWithParam<tuple<Backend, Target> > Layer_Test_Convolution_DLDT;
|
||||
TEST_P(Layer_Test_Convolution_DLDT, Accuracy)
|
||||
{
|
||||
const Backend backendId = get<0>(GetParam());
|
||||
const Target targetId = get<1>(GetParam());
|
||||
|
||||
if (backendId == DNN_BACKEND_INFERENCE_ENGINE_NN_BUILDER_2019 && targetId == DNN_TARGET_MYRIAD)
|
||||
applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_MYRIAD, CV_TEST_TAG_DNN_SKIP_IE_NN_BUILDER);
|
||||
|
||||
if (backendId != DNN_BACKEND_INFERENCE_ENGINE_NN_BUILDER_2019 && backendId != DNN_BACKEND_INFERENCE_ENGINE_NGRAPH)
|
||||
throw SkipTestException("No support for async forward");
|
||||
|
||||
ASSERT_EQ(DNN_BACKEND_INFERENCE_ENGINE_NGRAPH, backendId);
|
||||
|
||||
Net netDefault = readNet(_tf("layer_convolution.caffemodel"), _tf("layer_convolution.prototxt"));
|
||||
Net net = readNet(_tf("layer_convolution.xml"), _tf("layer_convolution.bin"));
|
||||
|
||||
Mat inp = blobFromNPY(_tf("blob.npy"));
|
||||
|
||||
netDefault.setInput(inp);
|
||||
netDefault.setPreferableBackend(DNN_BACKEND_OPENCV);
|
||||
Mat outDefault = netDefault.forward();
|
||||
|
||||
net.setInput(inp);
|
||||
net.setPreferableBackend(backendId);
|
||||
net.setPreferableTarget(targetId);
|
||||
|
||||
Mat out = net.forward();
|
||||
|
||||
double l1 = (targetId == DNN_TARGET_OPENCL_FP16 || targetId == DNN_TARGET_MYRIAD) ? 1.5e-3 : 1e-5;
|
||||
double lInf = (targetId == DNN_TARGET_OPENCL_FP16 || targetId == DNN_TARGET_MYRIAD) ? 1.8e-2 : 1e-4;
|
||||
normAssert(outDefault, out, "", l1, lInf);
|
||||
|
||||
std::vector<int> outLayers = net.getUnconnectedOutLayers();
|
||||
ASSERT_EQ(net.getLayer(outLayers[0])->name, "output");
|
||||
if (backendId == DNN_BACKEND_INFERENCE_ENGINE_NN_BUILDER_2019)
|
||||
ASSERT_EQ(net.getLayer(outLayers[0])->type, "Convolution");
|
||||
else
|
||||
ASSERT_EQ(net.getLayer(outLayers[0])->type, "Result");
|
||||
}
|
||||
|
||||
TEST_P(Layer_Test_Convolution_DLDT, multithreading)
|
||||
{
|
||||
const Backend backendId = get<0>(GetParam());
|
||||
@@ -1640,43 +1099,6 @@ private:
|
||||
int outWidth, outHeight, zoomFactor;
|
||||
};
|
||||
|
||||
// BUG: https://github.com/opencv/opencv/issues/26194
|
||||
// After unregistration of the custom 'Interp' the model uses the standard Resize layer.
|
||||
// According to the graph, the model must produce 2 x 3 x 18 x 16 tensor with Resize layer,
|
||||
// but the result is compared with 2 x 3 x 17 x 15 tensor, just like the custom 'Interp' layer produced,
|
||||
// so we get the test failure. It looks like the test needs to be fixed.
|
||||
TEST_P(Test_Caffe_layers, DISABLED_Interp)
|
||||
{
|
||||
#ifdef OPENCV_DNN_EXTERNAL_PROTOBUF
|
||||
throw SkipTestException("Requires patched protobuf");
|
||||
#else
|
||||
#if defined(INF_ENGINE_RELEASE) && INF_ENGINE_VER_MAJOR_EQ(2021030000)
|
||||
if (backend == DNN_BACKEND_INFERENCE_ENGINE_NGRAPH && target == DNN_TARGET_MYRIAD)
|
||||
applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_MYRIAD, CV_TEST_TAG_DNN_SKIP_IE_NGRAPH); // exception
|
||||
#endif
|
||||
|
||||
if (backend == DNN_BACKEND_INFERENCE_ENGINE_NN_BUILDER_2019 && target == DNN_TARGET_MYRIAD)
|
||||
applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_MYRIAD);
|
||||
|
||||
// Test a custom layer.
|
||||
CV_DNN_REGISTER_LAYER_CLASS(Interp, CustomInterpLayer);
|
||||
try
|
||||
{
|
||||
testLayerUsingCaffeModels("layer_interp", false, false);
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
LayerFactory::unregisterLayer("Interp");
|
||||
throw;
|
||||
}
|
||||
LayerFactory::unregisterLayer("Interp");
|
||||
|
||||
// Test an implemented layer.
|
||||
|
||||
testLayerUsingCaffeModels("layer_interp", false, false);
|
||||
#endif
|
||||
}
|
||||
|
||||
INSTANTIATE_TEST_CASE_P(/*nothing*/, Test_Caffe_layers, dnnBackendsAndTargets());
|
||||
|
||||
TEST(Layer_Test_PoolingIndices, Accuracy)
|
||||
|
||||
Reference in New Issue
Block a user