vendor: OpenCV 5.0.0 snapshot at 40738fb16ceddb5fb3fea747585f7ce6abb0605b

This commit is contained in:
Gitea Mirror Bot
2026-08-22 00:10:33 +08:00
commit f7f077da11
6933 changed files with 2335208 additions and 0 deletions
+6
View File
@@ -0,0 +1,6 @@
// This file is part of OpenCV project.
// It is subject to the license terms in the LICENSE file found in the top-level directory
// of this distribution and at http://opencv.org/license.html.
#include "perf_precomp.hpp"
#include "../test/test_common.impl.hpp" // shared with accuracy tests
File diff suppressed because it is too large Load Diff
+171
View File
@@ -0,0 +1,171 @@
// This file is part of OpenCV project.
// It is subject to the license terms in the LICENSE file found in the top-level directory
// of this distribution and at http://opencv.org/license.html.
#include "perf_precomp.hpp"
#include <opencv2/dnn/shape_utils.hpp>
namespace opencv_test {
struct Conv1DParam_t {
int kernel;
struct BlobShape { int dims[3]; } shapeIn;
int outCN;
int groups;
int stride;
int dilation;
int pad[2];
const char* padMode;
bool hasBias;
double declared_flops;
};
// Details: #12142
static const Conv1DParam_t testConvolution1DConfigs[] = {
{3, {{1, 6, 10}}, 6, 1, 1, 1, {0, 0}, "VALID", true, 1776.},
{3, {{1, 2, 19}}, 2, 2, 2, 1, {1, 1}, "", true, 260.},
{3, {{1, 2, 25}}, 2, 2, 1, 1, {2, 2}, "SAME", false, 650.},
};
struct Conv1DParamID
{
enum {
CONV_0 = 0,
CONV_LAST = sizeof(testConvolution1DConfigs) / sizeof(testConvolution1DConfigs[0])
};
int val_;
Conv1DParamID(int val = 0) : val_(val) {}
operator int() const { return val_; }
static ::testing::internal::ParamGenerator<Conv1DParamID> all()
{
enum { NUM = (int)CONV_LAST };
Conv1DParamID v_[NUM]; for (int i = 0; i < NUM; ++i) { v_[i] = Conv1DParamID(i); } // reduce generated code size
return ::testing::ValuesIn(v_, v_ + NUM);
}
};
static inline void PrintTo(const Conv1DParamID& v, std::ostream* os)
{
CV_Assert((int)v >= 0); CV_Assert((int)v < Conv1DParamID::CONV_LAST);
const Conv1DParam_t& p = testConvolution1DConfigs[(int)v];
*os << "GFLOPS=" << cv::format("%.3f", p.declared_flops * 1e-9)
<< ", K=[" << p.kernel << "]"
<< ", IN={" << p.shapeIn.dims[0] << ", " << p.shapeIn.dims[1] << ", " << p.shapeIn.dims[2] << "}"
<< ", OCN=" << p.outCN;
if (p.groups > 1)
*os << ", G=" << p.groups;
if (p.stride != 1)
*os << ", S=" << p.stride;
if (p.dilation != 1)
*os << ", D=" << p.dilation;
if (p.pad[0] != 0 && p.pad[1] != 0 )
*os << ", P=(" << p.pad[0] << ", " << p.pad[1] << ")";
if (!((std::string)p.padMode).empty())
*os << ", PM=" << ((std::string)p.padMode);
if (p.hasBias)
*os << ", BIAS";
}
typedef tuple<Conv1DParamID, tuple<Backend, Target> > Conv1DTestParam_t;
typedef TestBaseWithParam<Conv1DTestParam_t> Conv1D;
PERF_TEST_P_(Conv1D, conv1d)
{
int test_id = (int)get<0>(GetParam());
ASSERT_GE(test_id, 0); ASSERT_LT(test_id, Conv1DParamID::CONV_LAST);
const Conv1DParam_t& params = testConvolution1DConfigs[test_id];
double declared_flops = params.declared_flops;
DictValue kernel = DictValue::arrayInt(&params.kernel, 1);
DictValue stride = DictValue::arrayInt(&params.stride, 1);
DictValue pad = DictValue::arrayInt(&params.pad[0], 2);
DictValue dilation = DictValue::arrayInt(&params.dilation, 1);
MatShape inputShape = MatShape(params.shapeIn.dims, params.shapeIn.dims + 3);
int outChannels = params.outCN;
int groups = params.groups;
std::string padMode(params.padMode);
bool hasBias = params.hasBias;
Backend backendId = get<0>(get<1>(GetParam()));
Target targetId = get<1>(get<1>(GetParam()));
if (targetId != DNN_TARGET_CPU)
throw SkipTestException("Only CPU is supported");
int inChannels = inputShape[1];
int sz[] = {outChannels, inChannels / groups, params.kernel};
Mat weights(3, &sz[0], CV_32F);
randu(weights, -1.0f, 1.0f);
LayerParams lp;
lp.set("kernel_size", kernel);
lp.set("pad", pad);
if (!padMode.empty())
lp.set("pad_mode", padMode);
lp.set("stride", stride);
lp.set("dilation", dilation);
lp.set("num_output", outChannels);
lp.set("group", groups);
lp.set("bias_term", hasBias);
lp.type = "Convolution";
lp.name = "testLayer";
lp.blobs.push_back(weights);
if (hasBias)
{
Mat bias(1, outChannels, CV_32F);
randu(bias, -1.0f, 1.0f);
lp.blobs.push_back(bias);
}
int inpSz[] = {1, inChannels, inputShape[2]};
Mat input(3, &inpSz[0], CV_32F);
randu(input, -1.0f, 1.0f);
Net net;
net.addLayerToPrev(lp.name, lp.type, lp);
net.setInput(input);
net.setPreferableBackend(backendId);
net.setPreferableTarget(targetId);
// warmup
Mat output = net.forward();
MatShape netInputShape = shape(input);
cv::dnn::MatType netInputType = input.depth();
bool fp16 = false;
#ifdef HAVE_OPENCL
fp16 = ocl::Device::getDefault().isExtensionSupported("cl_khr_fp16");
#endif
if (netInputType == CV_32F && fp16 && targetId == DNN_TARGET_OPENCL_FP16)
netInputType = CV_16F;
size_t weightsMemory = 0, blobsMemory = 0;
net.getMemoryConsumption(netInputShape, netInputType, weightsMemory, blobsMemory);
int64 flops = net.getFLOPS(netInputShape, netInputType);
CV_Assert(flops > 0);
std::cout
<< "IN=" << divUp(input.total() * input.elemSize(), 1u<<10) << " Kb " << netInputShape
<< " OUT=" << divUp(output.total() * output.elemSize(), 1u<<10) << " Kb " << shape(output)
<< " Weights(parameters): " << divUp(weightsMemory, 1u<<10) << " Kb"
<< " MFLOPS=" << flops * 1e-6 << std::endl;
TEST_CYCLE()
{
Mat res = net.forward();
}
EXPECT_NEAR(flops, declared_flops, declared_flops * 1e-6);
SANITY_CHECK_NOTHING();
}
INSTANTIATE_TEST_CASE_P(/**/, Conv1D, Combine(
Conv1DParamID::all(),
dnnBackendsAndTargets(/* withInferenceEngine = */false, /* obsolete_withHalide = */false) // defined in ../test/test_common.hpp
));
} // namespace
+190
View File
@@ -0,0 +1,190 @@
// This file is part of OpenCV project.
// It is subject to the license terms in the LICENSE file found in the top-level directory
// of this distribution and at http://opencv.org/license.html.
#include "perf_precomp.hpp"
#include <opencv2/dnn/shape_utils.hpp>
namespace opencv_test {
struct Conv3DParam_t {
int kernel[3];
struct BlobShape { int dims[5]; } shapeIn;
int outCN;
int groups;
int stride[3];
int dilation[3];
int pad[6];
const char* padMode;
bool hasBias;
double declared_flops;
};
// Details: #12142
static const Conv3DParam_t testConvolution3DConfigs[] = {
{{3, 3, 3}, {{1, 6, 10, 38, 50}}, 6, 1, {1, 1, 1}, {1, 1, 1}, {0, 0, 0, 0, 0, 0}, "VALID", true, 26956800.},
{{3, 3, 3}, {{1, 2, 19, 19, 19}}, 2, 2, {2, 2, 2}, {1, 1, 1}, {1, 1, 1, 1, 1, 1}, "", true, 218000.},
{{3, 3, 3}, {{1, 2, 25, 19, 19}}, 2, 2, {1, 2, 2}, {1, 1, 1}, {2, 2, 2, 2, 2, 2}, "SAME", false, 545000.},
{{3, 3, 3}, {{1, 11, 9, 150, 200}}, 11, 1, {1, 1, 1}, {1, 1, 1}, {0, 0, 0, 0, 0, 0}, "VALID", true, 1342562760.},
{{3, 3, 3}, {{1, 10, 98, 10, 10}}, 10, 1, {1, 1, 1}, {1, 1, 1}, {1, 0, 1, 1, 0,1}, "SAME", false, 53018000.},
{{5, 5, 5}, {{1, 6, 19, 19, 19}}, 6, 2, {1, 1, 1}, {1, 1, 1}, {0, 0, 0, 0, 0, 0}, "", false, 30395250.},
{{5, 5, 5}, {{1, 4, 50, 19, 19}}, 4, 1, {2, 2, 2}, {1, 1, 1}, {1, 1, 1, 1, 1, 1}, "VALID", false, 5893888.},
{{5, 5, 5}, {{1, 3, 75, 75, 100}}, 3, 1, {1, 1, 1}, {1, 1, 1}, {0, 0, 0, 0, 0, 0}, "SAME", true, 1267312500.},
{{5, 5, 5}, {{1, 2, 21, 75, 100}}, 2, 1, {1, 1, 1}, {1, 1, 1}, {0, 0, 0, 0, 0, 0}, "", true, 116103744.},
{{5, 5, 5}, {{1, 4, 40, 75, 75}}, 4, 1, {2, 2, 2}, {1, 1, 1}, {0, 0, 0, 0, 0, 0}, "", false, 93405312.},
{{7, 7, 7}, {{1, 6, 15, 19, 19}}, 6, 1, {2, 1, 1}, {1, 1, 1}, {3, 3, 3, 3, 3, 3}, "SAME", true, 71339376.},
{{7, 7, 7}, {{1, 2, 38, 38, 38}}, 2, 1, {1, 2, 1}, {1, 1, 1}, {0, 0, 0, 0, 0, 0}, "", false, 44990464.},
{{1, 1, 1}, {{1, 4, 9, 10, 10}}, 4, 1, {1, 1, 2}, {1, 1, 1}, {1, 1, 1, 1, 1, 1}, "VALID", false, 16200.},
{{3, 1, 4}, {{1, 14, 5, 10, 10}}, 14, 1, {1, 1, 1}, {1, 1, 1}, {0, 0, 0, 0, 0, 0}, "SAME", false, 2359000.},
{{1, 1, 1}, {{1, 8, 1, 10, 10}}, 8, 8, {1, 1, 1}, {1, 1, 1}, {1, 1, 1, 1, 1, 1}, "", true, 58752.},
{{3, 4, 2}, {{1, 4, 8, 10, 10}}, 4, 4, {1, 2, 1}, {1, 1, 1}, {0, 0, 0, 0, 0, 0}, "", true, 166752.}
};
struct Conv3DParamID
{
enum {
CONV_0 = 0,
CONV_100 = 16,
CONV_LAST = sizeof(testConvolution3DConfigs) / sizeof(testConvolution3DConfigs[0])
};
int val_;
Conv3DParamID(int val = 0) : val_(val) {}
operator int() const { return val_; }
static ::testing::internal::ParamGenerator<Conv3DParamID> all()
{
#if 0
enum { NUM = (int)CONV_LAST };
#else
enum { NUM = (int)CONV_100 };
#endif
Conv3DParamID v_[NUM]; for (int i = 0; i < NUM; ++i) { v_[i] = Conv3DParamID(i); } // reduce generated code size
return ::testing::ValuesIn(v_, v_ + NUM);
}
};
static inline void PrintTo(const Conv3DParamID& v, std::ostream* os)
{
CV_Assert((int)v >= 0); CV_Assert((int)v < Conv3DParamID::CONV_LAST);
const Conv3DParam_t& p = testConvolution3DConfigs[(int)v];
*os << "GFLOPS=" << cv::format("%.3f", p.declared_flops * 1e-9)
<< ", K=[" << p.kernel[0] << " x " << p.kernel[1] << " x " << p.kernel[2] << "]"
<< ", IN={" << p.shapeIn.dims[0] << ", " << p.shapeIn.dims[1] << ", " << p.shapeIn.dims[2] << ", " << p.shapeIn.dims[3] << ", " << p.shapeIn.dims[4] << "}"
<< ", OCN=" << p.outCN;
if (p.groups > 1)
*os << ", G=" << p.groups;
if (p.stride[0] * p.stride[1] * p.stride[2] != 1)
*os << ", S=[" << p.stride[0] << " x " << p.stride[1] << " x " << p.stride[2] << "]";
if (p.dilation[0] * p.dilation[1] * p.dilation[2] != 1)
*os << ", D=[" << p.dilation[0] << " x " << p.dilation[1] << " x " << p.dilation[2] << "]";
if (p.pad[0] != 0 && p.pad[1] != 0 && p.pad[2] != 0 &&
p.pad[3] != 0 && p.pad[4] != 0 && p.pad[5] != 0)
*os << ", P=(" << p.pad[0] << ", " << p.pad[3] << ") x ("
<< p.pad[1] << ", " << p.pad[4] << ") x ("
<< p.pad[2] << ", " << p.pad[5] << ")";
if (!((std::string)p.padMode).empty())
*os << ", PM=" << ((std::string)p.padMode);
if (p.hasBias)
*os << ", BIAS";
}
typedef tuple<Conv3DParamID, tuple<Backend, Target> > Conv3DTestParam_t;
typedef TestBaseWithParam<Conv3DTestParam_t> Conv3D;
PERF_TEST_P_(Conv3D, conv3d)
{
int test_id = (int)get<0>(GetParam());
ASSERT_GE(test_id, 0); ASSERT_LT(test_id, Conv3DParamID::CONV_LAST);
const Conv3DParam_t& params = testConvolution3DConfigs[test_id];
double declared_flops = params.declared_flops;
DictValue kernel = DictValue::arrayInt(&params.kernel[0], 3);
DictValue stride = DictValue::arrayInt(&params.stride[0], 3);
DictValue pad = DictValue::arrayInt(&params.pad[0], 6);
DictValue dilation = DictValue::arrayInt(&params.dilation[0], 3);
MatShape inputShape = MatShape(params.shapeIn.dims, params.shapeIn.dims + 5);
int outChannels = params.outCN;
int groups = params.groups;
std::string padMode(params.padMode);
bool hasBias = params.hasBias;
Backend backendId = get<0>(get<1>(GetParam()));
Target targetId = get<1>(get<1>(GetParam()));
if (targetId != DNN_TARGET_CPU && backendId != DNN_BACKEND_CUDA)
throw SkipTestException("Only CPU and CUDA is supported");
int inChannels = inputShape[1];
int sz[] = {outChannels, inChannels / groups, params.kernel[0], params.kernel[1], params.kernel[2]};
Mat weights(5, &sz[0], CV_32F);
randu(weights, -1.0f, 1.0f);
LayerParams lp;
lp.set("kernel_size", kernel);
lp.set("pad", pad);
if (!padMode.empty())
lp.set("pad_mode", padMode);
lp.set("stride", stride);
lp.set("dilation", dilation);
lp.set("num_output", outChannels);
lp.set("group", groups);
lp.set("bias_term", hasBias);
lp.type = "Convolution";
lp.name = "testLayer";
lp.blobs.push_back(weights);
if (hasBias)
{
Mat bias(1, outChannels, CV_32F);
randu(bias, -1.0f, 1.0f);
lp.blobs.push_back(bias);
}
int inpSz[] = {1, inChannels, inputShape[2], inputShape[3], inputShape[4]};
Mat input(5, &inpSz[0], CV_32F);
randu(input, -1.0f, 1.0f);
Net net;
net.addLayerToPrev(lp.name, lp.type, lp);
net.setInput(input);
net.setPreferableBackend(backendId);
net.setPreferableTarget(targetId);
Mat output = net.forward();
MatShape netInputShape = shape(input);
cv::dnn::MatType netInputType = input.depth();
bool fp16 = false;
#ifdef HAVE_OPENCL
fp16 = ocl::Device::getDefault().isExtensionSupported("cl_khr_fp16");
#endif
if (netInputType == CV_32F && fp16 && targetId == DNN_TARGET_OPENCL_FP16)
netInputType = CV_16F;
size_t weightsMemory = 0, blobsMemory = 0;
net.getMemoryConsumption(netInputShape, netInputType, weightsMemory, blobsMemory);
int64 flops = net.getFLOPS(netInputShape, netInputType);
CV_Assert(flops > 0);
std::cout
<< "IN=" << divUp(input.total() * input.elemSize(), 1u<<10) << " Kb " << netInputShape
<< " OUT=" << divUp(output.total() * output.elemSize(), 1u<<10) << " Kb " << shape(output)
<< " Weights(parameters): " << divUp(weightsMemory, 1u<<10) << " Kb"
<< " MFLOPS=" << flops * 1e-6 << std::endl;
TEST_CYCLE()
{
Mat res = net.forward();
}
EXPECT_NEAR(flops, declared_flops, declared_flops * 1e-6);
SANITY_CHECK_NOTHING();
}
INSTANTIATE_TEST_CASE_P(/**/, Conv3D, Combine(
Conv3DParamID::all(),
dnnBackendsAndTargets(/* withInferenceEngine = */false, /* obsolete_withHalide = */false) // defined in ../test/test_common.hpp
));
} // namespace
+109
View File
@@ -0,0 +1,109 @@
// This file is part of OpenCV project.
// It is subject to the license terms in the LICENSE file found in the top-level directory
// of this distribution and at http://opencv.org/license.html.
#include "perf_precomp.hpp"
namespace opencv_test {
struct EinsumParams {
int inputSize;
int outputSize;
std::string equation;
std::vector<std::vector<int> > einsumInpShapes;
EinsumParams(std::string equation_, std::vector<std::vector<int> > einsumInpShapes_ = std::vector<std::vector<int> >())
{
inputSize = einsumInpShapes_.size();
equation = equation_;
einsumInpShapes = einsumInpShapes_;
}
};
static inline void PrintTo(const EinsumParams& params, ::std::ostream* os) {
(*os) << "Equation=" << params.equation << " ";
(*os) << "InputShape={";
for(int i = 0; i < params.einsumInpShapes.size(); i++)
{
(*os) << "{";
for(int j = 0; j < params.einsumInpShapes[i].size(); j++)
{
(*os) << params.einsumInpShapes[i][j] << ((j < params.einsumInpShapes[i].size() - 1) ? ", " : "");
}
(*os) << ((i < params.einsumInpShapes.size() - 1) ? "}, " : "}");
}
(*os) << "}";
}
// test cases
static const EinsumParams testEinsumConfigs[] = {
// TODO: Add tests with one input after ellips merge
{"ij, jk -> ik", {{2, 3}, {3, 2}}},
{"ij, jk -> ik", {{20, 30}, {30, 20}}},
{"ij, jk -> ik", {{113, 127}, {127, 113}}},
{"imkj, injs -> imnks", {{1, 4, 7, 9}, {1, 5, 9, 8}}},
{"imkj, injs -> imnks", {{1, 4, 70, 90}, {1, 5, 90, 80}}},
{"imkj, injs -> imnks", {{1, 4, 73, 91}, {1, 5, 91, 57}}},
{"ij -> i", {{30, 40}}},
{"ij -> i", {{113, 374}}},
{"...ij -> ...i", {{30, 40}}},
{"...ij -> ...i", {{113, 374}}},
{"...ij, ...jk -> ...ik", {{40, 50}, {50, 80}}},
{"...ij, ...jk -> ...ik", {{47, 51}, {51, 83}}},
};
class Layer_Einsum: public TestBaseWithParam<EinsumParams> {};
PERF_TEST_P_(Layer_Einsum, einsum) {
const EinsumParams& params = GetParam();
LayerParams lp;
lp.type = "Einsum";
lp.name = "testEinsum";
lp.set("equation", params.equation);
lp.set("inputSize", params.inputSize);
lp.set("outputSize", 1);
CV_CheckFalse(params.einsumInpShapes.empty(), "ERROR no inputs shapes provided");
for (int i = 0; i < params.einsumInpShapes.size(); i++) {
lp.set("inputShapes" + cv::format("%d", i), DictValue::arrayInt(params.einsumInpShapes[i].begin(), params.einsumInpShapes[i].size()));
}
Net net;
std::vector<Mat> inputs;
std::vector<std::string> input_names;
int id = net.addLayer(lp.name, lp.type, lp);
for (int i = 0; i < params.inputSize; ++i) {
// create inputs
inputs.emplace_back(Mat(params.einsumInpShapes[i], CV_32FC1));
// connect each input to the layer
net.connect(0, i, id, i);
// create input names dynamically, assuming input naming follows a consistent pattern
input_names.emplace_back("input" + std::to_string(i + 1));
}
//warm up
std::vector<Mat> outputs;
net.setInputsNames(input_names);
for (int i = 0; i < input_names.size(); i++){
net.setInput(inputs[i], input_names[i]);
}
net.forward(outputs, "testEinsum");
TEST_CYCLE()
{
net.forward(outputs, "testEinsum");
}
SANITY_CHECK_NOTHING();
}
INSTANTIATE_TEST_CASE_P(/**/, Layer_Einsum, testing::ValuesIn(testEinsumConfigs));
}; //namespace
+415
View File
@@ -0,0 +1,415 @@
// This file is part of OpenCV project.
// It is subject to the license terms in the LICENSE file found in the top-level directory
// of this distribution and at http://opencv.org/license.html.
#include "perf_precomp.hpp"
#include <opencv2/dnn/shape_utils.hpp>
#include <numeric>
namespace opencv_test {
struct GemmParam_t {
std::vector<int> a_shape;
std::vector<int> b_shape;
std::vector<int> c_shape;
bool trans_a;
bool trans_b;
GemmParam_t(std::vector<int> a_shape_, std::vector<int> b_shape_, std::vector<int> c_shape_ = {}, bool trans_a_ = false, bool trans_b_ = false)
: a_shape(a_shape_), b_shape(b_shape_), c_shape(c_shape_), trans_a(trans_a_), trans_b(trans_b_) {}
};
// TODO: Dsiable most of the test cases except vision transformers to save time
static const GemmParam_t test_gemm_configs[] = {
// vision transformers cases
{ { 768, 768 }, { 768, 768 }, { 768 } },
{ { 1024, 1024 }, { 1024, 1024 }, { 1024 } },
{ { 50, 768 }, { 768, 2304 } },
{ { 197, 768 }, { 768, 2304 } },
{ { 50, 1024 }, { 1024, 3072 } },
{ { 197, 1024 }, { 1024, 3072 } },
// these cases are commented to save testing time
/*
// square mat
{ { 64, 64 }, { 64, 64 } },
{ { 128, 128 }, { 128, 128 } },
{ { 256, 256 }, { 256, 256 } },
{ { 512, 512 }, { 512, 512 } },
{ { 1024, 1024 }, { 1024, 1024 } },
{ { 4096, 4096 }, { 4096, 4096 } },
// retangular mat
{ { 256, 256 }, { 256, 1024 } },
{ { 256, 1024 }, { 1024, 256 } },
{ { 256, 1024 }, { 1024, 1024 } },
{ { 1024, 1024 }, { 1024, 256 } },
{ { 1024, 256 }, { 256, 1024 } },
{ { 1024, 256 }, { 256, 256 } },
// with C
{ { 256, 256 }, { 256, 256 }, { 256 } },
{ { 256, 256 }, { 256, 1024 }, { 1024 } },
{ { 256, 1024 }, { 1024, 256 }, { 256 } },
{ { 256, 1024 }, { 1024, 1024 }, { 1024 } },
{ { 1024, 1024 }, { 1024, 256 }, { 256 } },
{ { 1024, 256 }, { 256, 1024 }, { 1024 } },
{ { 1024, 256 }, { 256, 256 }, { 256 } },
// with C and trans_b
{ { 256, 256 }, { 256, 256 }, { 256 } , false, true},
{ { 256, 1024 }, { 256, 1024 }, { 256 } , false, true},
{ { 256, 1024 }, { 1024, 1024 }, { 1024 } , false, true},
{ { 1024, 1024 }, { 1024, 1024 }, { 1024 } , false, true},
{ { 1024, 256 }, { 1024, 256 }, { 1024 } , false, true},
{ { 1024, 256 }, { 256, 256 }, { 256 } , false, true},
// with C and trans_b and trans_a
{ { 256, 256 }, { 256, 256 }, { 256 } , true, true},
{ { 1024, 256 }, { 256, 1024 }, { 256 } , true, true},
{ { 256, 1024 }, { 1024, 256 }, { 1024 } , true, true},
{ { 1024, 1024 }, { 1024, 1024 }, { 1024 } , true, true},
*/
};
static const GemmParam_t test_matmul_configs[] = {
// vision transformer cases
{ {12, 197, 197}, {12, 197, 64} },
{ {12, 197, 64 }, {12, 64, 197} },
{ {12, 50, 64}, {12, 64, 50} },
{ {12, 50, 50}, {12, 50, 64} },
{ {16, 197, 197}, {16, 197, 64} },
{ {16, 197, 64 }, {16, 64, 197} },
{ {16, 50, 64}, {16, 64, 50} },
{ {16, 50, 50}, {16, 50, 64} },
};
struct GemmParamId
{
enum {
GEMM_0 = 0,
GEMM_LAST = sizeof(test_gemm_configs) / sizeof(test_gemm_configs[0])
};
int val_;
GemmParamId(int val = 0) : val_(val) {}
operator int() const { return val_; }
static ::testing::internal::ParamGenerator<GemmParamId> all()
{
enum { NUM = (int)GEMM_LAST };
GemmParamId v_[NUM]; for (int i = 0; i < NUM; ++i) { v_[i] = GemmParamId(i); } // reduce generated code size
return ::testing::ValuesIn(v_, v_ + NUM);
}
};
struct MatMulParamId {
enum {
MATMUL_0 = 0,
MATMUL_LAST = sizeof(test_matmul_configs) / sizeof(test_matmul_configs[0])
};
int val_;
MatMulParamId(int val = 0) : val_(val) {}
operator int() const { return val_; }
static ::testing::internal::ParamGenerator<MatMulParamId> all() {
enum { NUM = (int)MATMUL_LAST };
MatMulParamId v_[NUM]; for (int i = 0; i < NUM; i++) { v_[i] = MatMulParamId(i); }
return ::testing::ValuesIn(v_, v_ + NUM);
}
};
static inline void PrintTo(const GemmParamId& v, std::ostream* os)
{
CV_Assert((int)v >= 0); CV_Assert((int)v < GemmParamId::GEMM_LAST);
const GemmParam_t& p = test_gemm_configs[(int)v];
auto print_shape = [os](const std::vector<int>& shape, const std::string tag) {
if (shape.empty()) {
return ;
}
*os << tag << "=[";
for (size_t i = 0; i < shape.size(); ++i) {
if (i == shape.size() - 1) {
*os << shape[i] << "]";
break;
}
*os << shape[i] << ", ";
}
};
print_shape(p.a_shape, "A");
print_shape(p.b_shape, ", B");
print_shape(p.c_shape, ", C");
*os << ", trans_a=" << p.trans_a << ", trans_b=" << p.trans_b;
}
typedef tuple<GemmParamId, tuple<Backend, Target> > GemmTestParam_t;
typedef TestBaseWithParam<GemmTestParam_t> Gemm;
PERF_TEST_P_(Gemm, gemm)
{
int test_id = (int)get<0>(GetParam());
ASSERT_GE(test_id, 0); ASSERT_LT(test_id, GemmParamId::GEMM_LAST);
const GemmParam_t& params = test_gemm_configs[test_id];
auto a_shape = params.a_shape;
auto b_shape = params.b_shape;
auto c_shape = params.c_shape;
auto trans_a = params.trans_a;
auto trans_b = params.trans_b;
float alpha = 1.f;
float beta = 1.f;
Backend backend_id = get<0>(get<1>(GetParam()));
Target target_id = get<1>(get<1>(GetParam()));
bool have_bias = c_shape.empty() ? false : true;
Mat A(static_cast<int>(a_shape.size()), a_shape.data(), CV_32F);
randu(A, -1.0f, 1.0f);
Mat B(static_cast<int>(b_shape.size()), b_shape.data(), CV_32F);
randu(B, -1.0f, 1.0f);
LayerParams lp;
lp.type = "Gemm";
lp.name = "testLayer";
lp.set("transA", trans_a);
lp.set("transB", trans_b);
lp.set("alpha", alpha);
lp.set("beta", beta);
lp.set("real_ndims_C", static_cast<int>(c_shape.size()));
lp.set("constB", true);
lp.blobs.push_back(B);
if (have_bias) {
Mat C(static_cast<int>(c_shape.size()), c_shape.data(), CV_32F);
randu(C, -1.0f, 1.0f);
lp.set("have_bias", true);
lp.set("constC", true);
lp.blobs.push_back(C);
}
Net net;
net.addLayerToPrev(lp.name, lp.type, lp);
net.setPreferableBackend(backend_id);
net.setPreferableTarget(target_id);
// warmup
{
net.setInput(A);
Mat out = net.forward();
}
TEST_CYCLE()
{
Mat res = net.forward();
}
SANITY_CHECK_NOTHING();
}
PERF_TEST_P_(Gemm, innerproduct)
{
int test_id = (int)get<0>(GetParam());
ASSERT_GE(test_id, 0); ASSERT_LT(test_id, GemmParamId::GEMM_LAST);
const GemmParam_t& params = test_gemm_configs[test_id];
auto a_shape = params.a_shape;
auto b_shape = params.b_shape;
auto c_shape = params.c_shape;
auto trans_a = params.trans_a;
auto trans_b = params.trans_b;
Backend backend_id = get<0>(get<1>(GetParam()));
Target target_id = get<1>(get<1>(GetParam()));
bool have_bias = c_shape.empty() ? false : true;
Mat A(static_cast<int>(a_shape.size()), a_shape.data(), CV_32F);
randu(A, -1.0f, 1.0f);
Mat B(static_cast<int>(b_shape.size()), b_shape.data(), CV_32F);
randu(B, -1.0f, 1.0f);
LayerParams lp;
lp.type = "InnerProduct";
lp.name = "testLayer";
if (trans_a) {
cv::transpose(A, A);
}
if (!trans_b) {
cv::transpose(B, B);
}
lp.blobs.push_back(B);
lp.set("num_output", B.size[0]);
if (have_bias) {
Mat C(static_cast<int>(c_shape.size()), c_shape.data(), CV_32F);
randu(C, -1.0f, 1.0f);
lp.blobs.push_back(C);
lp.set("bias_term", true);
} else {
lp.set("bias_term", false);
}
Net net;
net.addLayerToPrev(lp.name, lp.type, lp);
net.setPreferableBackend(backend_id);
net.setPreferableTarget(target_id);
// warmup
{
std::vector<std::string> input_names(1);
input_names[0] = "A";
net.setInputsNames(input_names);
net.setInput(A, input_names[0]);
Mat out = net.forward();
}
TEST_CYCLE()
{
Mat res = net.forward();
}
SANITY_CHECK_NOTHING();
}
static inline void PrintTo(const MatMulParamId& v, std::ostream* os)
{
CV_Assert((int)v >= 0); CV_Assert((int)v < MatMulParamId::MATMUL_LAST);
const GemmParam_t& p = test_matmul_configs[(int)v];
auto print_shape = [os](const std::vector<int>& shape, const std::string tag) {
if (shape.empty()) {
return ;
}
*os << tag << "=[";
for (size_t i = 0; i < shape.size(); ++i) {
if (i == shape.size() - 1) {
*os << shape[i] << "]";
break;
}
*os << shape[i] << ", ";
}
};
print_shape(p.a_shape, "A");
print_shape(p.b_shape, ", B");
print_shape(p.c_shape, ", C");
*os << ", trans_a=" << p.trans_a << ", trans_b=" << p.trans_b;
}
using MatMulTestParam_t = tuple<MatMulParamId, tuple<Backend, Target>>;
using MatMul = TestBaseWithParam<MatMulTestParam_t>;
PERF_TEST_P_(MatMul, matmul)
{
int test_id = (int)get<0>(GetParam());
ASSERT_GE(test_id, 0); ASSERT_LT(test_id, MatMulParamId::MATMUL_LAST);
const GemmParam_t& params = test_matmul_configs[test_id];
auto a_shape = params.a_shape;
auto b_shape = params.b_shape;
auto trans_a = params.trans_a;
auto trans_b = params.trans_b;
float alpha = 1.f;
float beta = 1.f;
Backend backend_id = get<0>(get<1>(GetParam()));
Target target_id = get<1>(get<1>(GetParam()));
Mat A(a_shape, CV_32F);
randu(A, -1.0f, 1.0f);
Mat B(b_shape, CV_32F);
randu(B, -1.0f, 1.0f);
LayerParams lp;
lp.type = "MatMul";
lp.name = "testLayer";
lp.set("transA", trans_a);
lp.set("transB", trans_b);
lp.set("alpha", alpha);
lp.set("beta", beta);
lp.blobs.push_back(B);
Net net;
net.addLayerToPrev(lp.name, lp.type, lp);
net.setPreferableBackend(backend_id);
net.setPreferableTarget(target_id);
// warmup
{
std::vector<std::string> input_names{"A"};
net.setInputsNames(input_names);
net.setInput(A, input_names[0]);
Mat out = net.forward();
}
TEST_CYCLE()
{
Mat res = net.forward();
}
SANITY_CHECK_NOTHING();
}
PERF_TEST_P_(MatMul, innerproduct)
{
int test_id = (int)get<0>(GetParam());
ASSERT_GE(test_id, 0); ASSERT_LT(test_id, MatMulParamId::MATMUL_LAST);
const GemmParam_t& params = test_matmul_configs[test_id];
auto a_shape = params.a_shape;
auto b_shape = params.b_shape;
Backend backend_id = get<0>(get<1>(GetParam()));
Target target_id = get<1>(get<1>(GetParam()));
Mat A(a_shape, CV_32F);
randu(A, -1.0f, 1.0f);
Mat B(b_shape, CV_32F);
randu(B, -1.0f, 1.0f);
LayerParams lp;
lp.type = "InnerProduct";
lp.name = "testLayer";
lp.set("axis", (int)(a_shape.size() - 1));
lp.set("bias_term", false);
// pre-transpose
std::vector<int> order(b_shape.size());
std::iota(order.begin(), order.end(), 0);
std::swap(order.back(), order[b_shape.size() - 2]);
Mat B_transposed;
transposeND(B, order, B_transposed);
lp.blobs.push_back(B_transposed);
lp.set("num_output", int(B_transposed.total(0, b_shape.size() - 1)));
lp.set("is_matmul", true);
Net net;
net.addLayerToPrev(lp.name, lp.type, lp);
net.setPreferableBackend(backend_id);
net.setPreferableTarget(target_id);
// warmup
{
std::vector<std::string> input_names{"A"};
net.setInputsNames(input_names);
net.setInput(A, input_names[0]);
Mat out = net.forward();
}
TEST_CYCLE()
{
Mat res = net.forward();
}
SANITY_CHECK_NOTHING();
}
INSTANTIATE_TEST_CASE_P(/**/, Gemm, Combine(
GemmParamId::all(),
dnnBackendsAndTargets(false, false) // defined in ../test/test_common.hpp
));
INSTANTIATE_TEST_CASE_P(/**/, MatMul, Combine(
MatMulParamId::all(),
dnnBackendsAndTargets(false, false) // defined in ../test/test_common.hpp
));
} // namespace
File diff suppressed because it is too large Load Diff
+7
View File
@@ -0,0 +1,7 @@
#include "perf_precomp.hpp"
#if defined(HAVE_HPX)
#include <hpx/hpx_main.hpp>
#endif
CV_PERF_TEST_MAIN(dnn, cvtest::addDataSearchEnv("OPENCV_DNN_TEST_DATA_PATH"))
+770
View File
@@ -0,0 +1,770 @@
// This file is part of OpenCV project.
// It is subject to the license terms in the LICENSE file found in the top-level directory
// of this distribution and at http://opencv.org/license.html.
//
// Copyright (C) 2017, Intel Corporation, all rights reserved.
// Third party copyrights are property of their respective owners.
#include "perf_precomp.hpp"
#include "opencv2/core/ocl.hpp"
#include "opencv2/dnn/shape_utils.hpp"
#include <opencv2/core/utils/configuration.private.hpp>
#include "../test/test_common.hpp"
namespace opencv_test {
class DNNTestNetwork : public ::perf::TestBaseWithParam< tuple<Backend, Target> >
{
public:
dnn::Backend backend;
dnn::Target target;
dnn::Net net;
DNNTestNetwork()
{
backend = (dnn::Backend)(int)get<0>(GetParam());
target = (dnn::Target)(int)get<1>(GetParam());
}
void processNet(std::string weights, std::string proto,
const std::vector<std::tuple<Mat, std::string>>& inputs, const std::string& outputLayer = ""){
weights = findDataFile(weights, false);
if (!proto.empty())
proto = findDataFile(proto);
net = readNet(weights, proto);
// Set multiple inputs
for(auto &inp: inputs){
net.setInput(std::get<0>(inp), std::get<1>(inp));
}
net.setPreferableBackend(backend);
net.setPreferableTarget(target);
// Calculate multiple inputs memory consumption
std::vector<MatShape> netMatShapes;
for(auto &inp: inputs){
netMatShapes.push_back(shape(std::get<0>(inp)));
}
bool fp16 = false;
#ifdef HAVE_OPENCL
fp16 = ocl::Device::getDefault().isExtensionSupported("cl_khr_fp16");
#endif
std::vector<cv::dnn::MatType> netMatTypes;
for (auto& inp : inputs) {
cv::dnn::MatType t = std::get<0>(inp).depth();
if (t == CV_32F && fp16 && target == DNN_TARGET_OPENCL_FP16)
t = CV_16F;
netMatTypes.push_back(t);
}
net.forward(outputLayer); // warmup
size_t weightsMemory = 0, blobsMemory = 0;
net.getMemoryConsumption(netMatShapes, netMatTypes, weightsMemory, blobsMemory);
int64 flops = net.getFLOPS(netMatShapes, netMatTypes);
CV_Assert(flops > 0);
std::cout << "Memory consumption:" << std::endl;
std::cout << " Weights(parameters): " << divUp(weightsMemory, 1u<<20) << " Mb" << std::endl;
std::cout << " Blobs: " << divUp(blobsMemory, 1u<<20) << " Mb" << std::endl;
std::cout << "Calculation complexity: " << flops * 1e-9 << " GFlops" << std::endl;
PERF_SAMPLE_BEGIN()
net.forward();
PERF_SAMPLE_END()
SANITY_CHECK_NOTHING();
}
void processNet(std::string weights, std::string proto,
Mat &input, const std::string& outputLayer = "")
{
processNet(weights, proto, {std::make_tuple(input, "")}, outputLayer);
}
void processNet(std::string weights, std::string proto,
Size inpSize, const std::string& outputLayer = "")
{
Mat input_data(inpSize, CV_32FC3);
randu(input_data, 0.0f, 1.0f);
Mat input = blobFromImage(input_data, 1.0, Size(), Scalar(), false);
processNet(weights, proto, input, outputLayer);
}
};
PERF_TEST_P_(DNNTestNetwork, AlexNet)
{
processNet("dnn/onnx/models/alexnet.onnx", "", cv::Size(227, 227));
}
PERF_TEST_P_(DNNTestNetwork, GoogLeNet)
{
processNet("dnn/onnx/models/googlenet.onnx", "", cv::Size(224, 224));
}
PERF_TEST_P_(DNNTestNetwork, ResNet_50)
{
processNet("dnn/onnx/models/resnet50v1.onnx", "", cv::Size(224, 224));
}
PERF_TEST_P_(DNNTestNetwork, ResNet_18_v1_ONNX)
{
processNet("dnn/onnx/models/resnet18v1.onnx", "", cv::Size(224, 224));
}
PERF_TEST_P_(DNNTestNetwork, ResNet_50_v1_ONNX)
{
processNet("dnn/onnx/models/resnet50v1.onnx", "", cv::Size(224, 224));
}
PERF_TEST_P_(DNNTestNetwork, MobileNetv2_ONNX)
{
processNet("dnn/onnx/models/mobilenetv2.onnx", "", cv::Size(224, 224));
}
PERF_TEST_P_(DNNTestNetwork, ResNet50_QDQ_ONNX)
{
processNet("dnn/onnx/models/resnet50-v1-12-qdq.onnx", "", cv::Size(224, 224));
}
PERF_TEST_P_(DNNTestNetwork, SqueezeNet_v1_1)
{
processNet("dnn/onnx/models/squeezenet.onnx", "", cv::Size(227, 227));
}
PERF_TEST_P_(DNNTestNetwork, Inception_5h)
{
if (backend == DNN_BACKEND_INFERENCE_ENGINE_NN_BUILDER_2019) throw SkipTestException("");
processNet("dnn/tensorflow_inception_graph.pb", "", cv::Size(224, 224));
}
PERF_TEST_P_(DNNTestNetwork, SSD)
{
applyTestTag(CV_TEST_TAG_DEBUG_VERYLONG);
// SSD_VGG16's specialized preprocessing is handled by the new engine importer only.
auto engine_forced = static_cast<dnn::EngineType>(
utils::getConfigurationParameterSizeT("OPENCV_FORCE_DNN_ENGINE", dnn::ENGINE_AUTO));
if (engine_forced == dnn::ENGINE_CLASSIC)
throw SkipTestException("SSD_VGG16 is supported on the new DNN engine only");
processNet("dnn/onnx/models/ssd_vgg16.onnx", "", cv::Size(300, 300));
}
PERF_TEST_P_(DNNTestNetwork, MobileNet_SSD_v1_ONNX)
{
// Dynamic-shape preprocessing in this model needs the new engine; OpenVINO uses the classic one.
if (backend == DNN_BACKEND_INFERENCE_ENGINE_NGRAPH)
applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_NGRAPH);
// This model expects a uint8 NHWC image as input.
Mat image(cv::Size(300, 300), CV_8UC3);
randu(image, 0, 255);
int imsize[] = {1, image.rows, image.cols, 3};
Mat input(4, imsize, CV_8U, image.data);
processNet("dnn/onnx/models/ssd_mobilenet_v1_12.onnx", "", input);
}
PERF_TEST_P_(DNNTestNetwork, MobileNet_SSD_v1_TensorFlow)
{
processNet("dnn/ssd_mobilenet_v1_coco_2017_11_17.pb", "ssd_mobilenet_v1_coco_2017_11_17.pbtxt", cv::Size(300, 300));
}
PERF_TEST_P_(DNNTestNetwork, MobileNet_SSD_v2_TensorFlow)
{
processNet("dnn/ssd_mobilenet_v2_coco_2018_03_29.pb", "ssd_mobilenet_v2_coco_2018_03_29.pbtxt", cv::Size(300, 300));
}
PERF_TEST_P_(DNNTestNetwork, DenseNet_121)
{
processNet("dnn/onnx/models/densenet121.onnx", "", cv::Size(224, 224));
}
PERF_TEST_P_(DNNTestNetwork, OpenPose_pose_mpi_faster_4_stages)
{
applyTestTag(CV_TEST_TAG_DEBUG_VERYLONG);
if (backend == DNN_BACKEND_INFERENCE_ENGINE_NN_BUILDER_2019 && (target == DNN_TARGET_MYRIAD || target == DNN_TARGET_HDDL))
throw SkipTestException("");
// See https://github.com/CMU-Perceptual-Computing-Lab/openpose/blob/master/src/openpose/pose/poseParameters.cpp
processNet("dnn/onnx/models/openpose_pose_mpi.onnx", "", cv::Size(368, 368));
}
PERF_TEST_P_(DNNTestNetwork, Inception_v2_SSD_TensorFlow)
{
applyTestTag(CV_TEST_TAG_DEBUG_VERYLONG);
processNet("dnn/ssd_inception_v2_coco_2017_11_17.pb", "ssd_inception_v2_coco_2017_11_17.pbtxt", cv::Size(300, 300));
}
PERF_TEST_P_(DNNTestNetwork, YOLOv3)
{
applyTestTag(
CV_TEST_TAG_MEMORY_2GB,
CV_TEST_TAG_DEBUG_VERYLONG
);
#if defined(INF_ENGINE_RELEASE) && INF_ENGINE_VER_MAJOR_EQ(2020040000) // nGraph compilation failure
if (backend == DNN_BACKEND_INFERENCE_ENGINE_NGRAPH && target == DNN_TARGET_OPENCL)
throw SkipTestException("Test is disabled in OpenVINO 2020.4");
if (backend == DNN_BACKEND_INFERENCE_ENGINE_NGRAPH && target == DNN_TARGET_OPENCL_FP16)
throw SkipTestException("Test is disabled in OpenVINO 2020.4");
#endif
#if defined(INF_ENGINE_RELEASE) && INF_ENGINE_VER_MAJOR_GE(2021010000) // nGraph compilation failure
if (target == DNN_TARGET_MYRIAD)
throw SkipTestException("");
#endif
Mat sample = imread(findDataFile("dnn/dog416.png"));
cv::resize(sample, sample, Size(640, 640));
Mat inp = blobFromImage(sample, 1.0 / 255.0, Size(), Scalar(), true);
processNet("dnn/yolov3.onnx", "", inp);
}
PERF_TEST_P_(DNNTestNetwork, YOLOv4)
{
applyTestTag(
CV_TEST_TAG_MEMORY_2GB,
CV_TEST_TAG_DEBUG_VERYLONG
);
if (target == DNN_TARGET_MYRIAD) // not enough resources
throw SkipTestException("");
#if defined(INF_ENGINE_RELEASE) && INF_ENGINE_VER_MAJOR_EQ(2020040000) // nGraph compilation failure
if (backend == DNN_BACKEND_INFERENCE_ENGINE_NGRAPH && target == DNN_TARGET_OPENCL)
throw SkipTestException("Test is disabled in OpenVINO 2020.4");
if (backend == DNN_BACKEND_INFERENCE_ENGINE_NGRAPH && target == DNN_TARGET_OPENCL_FP16)
throw SkipTestException("Test is disabled in OpenVINO 2020.4");
#endif
Mat sample = imread(findDataFile("dnn/dog416.png"));
cv::resize(sample, sample, Size(608, 608));
Mat inp = blobFromImage(sample, 1.0 / 255.0, Size(), Scalar(), true);
processNet("dnn/yolov4.onnx", "", inp);
}
PERF_TEST_P_(DNNTestNetwork, YOLOv4_tiny)
{
#if defined(INF_ENGINE_RELEASE) && INF_ENGINE_VER_MAJOR_GE(2021010000) // nGraph compilation failure
if (target == DNN_TARGET_MYRIAD)
throw SkipTestException("");
#endif
Mat sample = imread(findDataFile("dnn/dog416.png"));
Mat inp = blobFromImage(sample, 1.0 / 255.0, Size(), Scalar(), true);
processNet("dnn/yolov4-tiny.onnx", "", inp);
}
PERF_TEST_P_(DNNTestNetwork, YOLOv5) {
applyTestTag(CV_TEST_TAG_MEMORY_512MB);
Mat sample = imread(findDataFile("dnn/dog416.png"));
Mat inp = blobFromImage(sample, 1.0 / 255.0, Size(640, 640), Scalar(), true);
processNet("dnn/yolov5n.onnx", "", inp);
}
PERF_TEST_P_(DNNTestNetwork, YOLOv8)
{
applyTestTag(
CV_TEST_TAG_MEMORY_512MB,
CV_TEST_TAG_DEBUG_LONG
);
Mat sample = imread(findDataFile("dnn/dog416.png"));
Mat inp = blobFromImage(sample, 1.0 / 255.0, Size(640, 640), Scalar(), true);
processNet("dnn/yolov8n.onnx", "", inp);
}
PERF_TEST_P_(DNNTestNetwork, YOLOX) {
applyTestTag(
CV_TEST_TAG_MEMORY_512MB,
CV_TEST_TAG_DEBUG_VERYLONG
);
Mat sample = imread(findDataFile("dnn/dog416.png"));
Mat inp = blobFromImage(sample, 1.0 / 255.0, Size(640, 640), Scalar(), true);
processNet("dnn/yolox_s.onnx", "", inp);
}
PERF_TEST_P_(DNNTestNetwork, EAST_text_detection)
{
applyTestTag(CV_TEST_TAG_DEBUG_VERYLONG);
processNet("dnn/frozen_east_text_detection.pb", "", cv::Size(320, 320));
}
PERF_TEST_P_(DNNTestNetwork, FastNeuralStyle_eccv16)
{
applyTestTag(CV_TEST_TAG_DEBUG_VERYLONG);
processNet("dnn/mosaic-9.onnx", "", cv::Size(224, 224));
}
PERF_TEST_P_(DNNTestNetwork, Inception_v2_Faster_RCNN)
{
applyTestTag(CV_TEST_TAG_DEBUG_VERYLONG);
#if defined(INF_ENGINE_RELEASE) && INF_ENGINE_VER_MAJOR_EQ(2019010000)
if (backend == DNN_BACKEND_INFERENCE_ENGINE_NN_BUILDER_2019)
throw SkipTestException("Test is disabled in OpenVINO 2019R1");
#endif
#if defined(INF_ENGINE_RELEASE) && INF_ENGINE_VER_MAJOR_EQ(2019020000)
if (backend == DNN_BACKEND_INFERENCE_ENGINE_NN_BUILDER_2019)
throw SkipTestException("Test is disabled in OpenVINO 2019R2");
#endif
#if defined(INF_ENGINE_RELEASE) && INF_ENGINE_VER_MAJOR_GE(2021010000)
if (target == DNN_TARGET_MYRIAD)
throw SkipTestException("Test is disabled in OpenVINO 2021.1+ / MYRIAD");
#endif
if ((backend == DNN_BACKEND_INFERENCE_ENGINE_NN_BUILDER_2019 && target != DNN_TARGET_CPU) ||
(backend == DNN_BACKEND_OPENCV && target == DNN_TARGET_OPENCL_FP16))
throw SkipTestException("");
processNet("dnn/faster_rcnn_inception_v2_coco_2018_01_28.pb",
"dnn/faster_rcnn_inception_v2_coco_2018_01_28.pbtxt",
cv::Size(800, 600));
}
PERF_TEST_P_(DNNTestNetwork, EfficientDet)
{
if (target != DNN_TARGET_CPU)
throw SkipTestException("");
Mat sample = imread(findDataFile("dnn/dog416.png"));
Mat inp = blobFromImage(sample, 1.0 / 255.0, Size(512, 512), Scalar(), true);
processNet("dnn/efficientdet-d0.pb", "dnn/efficientdet-d0.pbtxt", inp);
}
PERF_TEST_P_(DNNTestNetwork, EfficientNet)
{
Mat sample = imread(findDataFile("dnn/dog416.png"));
Mat inp = blobFromImage(sample, 1.0 / 255.0, Size(224, 224), Scalar(), true);
transposeND(inp, {0, 2, 3, 1}, inp);
processNet("dnn/efficientnet-lite4.onnx", "", inp);
}
PERF_TEST_P_(DNNTestNetwork, YuNet_320) {
processNet("dnn/onnx/models/yunet-202605.onnx", "", cv::Size(320, 320));
}
PERF_TEST_P_(DNNTestNetwork, YuNet_640) {
processNet("dnn/onnx/models/yunet-202605.onnx", "", cv::Size(640, 640));
}
PERF_TEST_P_(DNNTestNetwork, YuNet_1280) {
processNet("dnn/onnx/models/yunet-202605.onnx", "", cv::Size(1280, 736));
}
PERF_TEST_P_(DNNTestNetwork, SFace) {
processNet("dnn/face_recognition_sface_2021dec.onnx", "", cv::Size(112, 112));
}
PERF_TEST_P_(DNNTestNetwork, MPPalm) {
Mat inp(cv::Size(192, 192), CV_32FC3);
randu(inp, 0.0f, 1.0f);
inp = blobFromImage(inp, 1.0, Size(), Scalar(), false);
transposeND(inp, {0, 2, 3, 1}, inp);
processNet("dnn/palm_detection_mediapipe_2023feb.onnx", "", inp);
}
PERF_TEST_P_(DNNTestNetwork, MPHand) {
Mat inp(cv::Size(224, 224), CV_32FC3);
randu(inp, 0.0f, 1.0f);
inp = blobFromImage(inp, 1.0, Size(), Scalar(), false);
transposeND(inp, {0, 2, 3, 1}, inp);
processNet("dnn/handpose_estimation_mediapipe_2023feb.onnx", "", inp);
}
PERF_TEST_P_(DNNTestNetwork, MPPose) {
Mat inp(cv::Size(256, 256), CV_32FC3);
randu(inp, 0.0f, 1.0f);
inp = blobFromImage(inp, 1.0, Size(), Scalar(), false);
transposeND(inp, {0, 2, 3, 1}, inp);
processNet("dnn/pose_estimation_mediapipe_2023mar.onnx", "", inp);
}
PERF_TEST_P_(DNNTestNetwork, PPOCRv3) {
applyTestTag(CV_TEST_TAG_MEMORY_512MB);
processNet("dnn/onnx/models/PP_OCRv3_DB_text_det.onnx", "", cv::Size(736, 736));
}
PERF_TEST_P_(DNNTestNetwork, PPHumanSeg) {
processNet("dnn/human_segmentation_pphumanseg_2023mar.onnx", "", cv::Size(192, 192));
}
PERF_TEST_P_(DNNTestNetwork, CRNN) {
Mat inp(cv::Size(100, 32), CV_32FC1);
randu(inp, 0.0f, 1.0f);
inp = blobFromImage(inp, 1.0, Size(), Scalar(), false);
processNet("dnn/text_recognition_CRNN_EN_2021sep.onnx", "", inp);
}
PERF_TEST_P_(DNNTestNetwork, VitTrack) {
Mat inp1(cv::Size(128, 128), CV_32FC3);
Mat inp2(cv::Size(256, 256), CV_32FC3);
randu(inp1, 0.0f, 1.0f);
randu(inp2, 0.0f, 1.0f);
inp1 = blobFromImage(inp1, 1.0, Size(), Scalar(), false);
inp2 = blobFromImage(inp2, 1.0, Size(), Scalar(), false);
processNet("dnn/onnx/models/object_tracking_vittrack_2023sep.onnx", "", {std::make_tuple(inp1, "template"), std::make_tuple(inp2, "search")});
}
PERF_TEST_P_(DNNTestNetwork, EfficientDet_int8)
{
if (target != DNN_TARGET_CPU || (backend != DNN_BACKEND_OPENCV &&
backend != DNN_BACKEND_TIMVX && backend != DNN_BACKEND_INFERENCE_ENGINE_NGRAPH)) {
throw SkipTestException("");
}
Mat inp = imread(findDataFile("dnn/dog416.png"));
inp = blobFromImage(inp, 1.0 / 255.0, Size(320, 320), Scalar(), true);
processNet("dnn/tflite/coco_efficientdet_lite0_v1_1.0_quant_2021_09_06.tflite", "", inp);
}
PERF_TEST_P_(DNNTestNetwork, VIT_B_32)
{
applyTestTag(CV_TEST_TAG_DEBUG_VERYLONG);
processNet("dnn/onnx/models/vit_b_32.onnx", "", cv::Size(224, 224));
}
PERF_TEST_P_(DNNTestNetwork, BERT)
{
const int seq_len = 9;
int64_t input_ids_data[seq_len] = {101, 1996, 103, 2938, 2006, 1996, 13523, 1012, 102};
int64_t attention_mask_data[seq_len] = {1, 1, 1, 1, 1, 1, 1, 1, 1};
int64_t token_type_ids_data[seq_len] = {0, 0, 0, 0, 0, 0, 0, 0, 0};
int shp[2] = {1, seq_len};
Mat input_ids(2, shp, CV_64S, input_ids_data);
Mat attention_mask(2, shp, CV_64S, attention_mask_data);
Mat token_type_ids(2, shp, CV_64S, token_type_ids_data);
processNet("dnn/onnx/models/bert.onnx", "",
{std::make_tuple(input_ids, "input_ids"),
std::make_tuple(attention_mask, "attention_mask"),
std::make_tuple(token_type_ids, "token_type_ids")});
}
PERF_TEST_P_(DNNTestNetwork, VIT_Base_Patch16_224)
{
applyTestTag(CV_TEST_TAG_MEMORY_512MB);
processNet("dnn/vit_base_patch16_224_Opset16.onnx", "", cv::Size(224, 224));
}
PERF_TEST_P_(DNNTestNetwork, DeiT_Tiny_Patch16_224)
{
processNet("dnn/deit_tiny_patch16_224_Opset16.onnx", "", cv::Size(224, 224));
}
PERF_TEST_P_(DNNTestNetwork, MobileViT_XS)
{
processNet("dnn/mobilevit_xs_Opset16.onnx", "", cv::Size(256, 256));
}
PERF_TEST_P_(DNNTestNetwork, MobileViTv2_100_ONNX)
{
processNet("dnn/mobilevitv2_100_Opset16.onnx", "", cv::Size(256, 256));
}
PERF_TEST_P_(DNNTestNetwork, BEiT_Base_Patch16_224)
{
applyTestTag(CV_TEST_TAG_MEMORY_512MB);
processNet("dnn/beit_base_patch16_224_Opset16.onnx", "", cv::Size(224, 224));
}
PERF_TEST_P_(DNNTestNetwork, BlazeFace)
{
Mat input(cv::Size(128, 128), CV_32FC3);
randu(input, 0.0f, 1.0f);
input = blobFromImage(input, 1.0 / 255.0, Size(128, 128));
const int oneDim[] = {1};
Mat conf(1, oneDim, CV_32F); conf.ptr<float>()[0] = 0.20f;
Mat iou(1, oneDim, CV_32F); iou.ptr<float>()[0] = 0.30f;
Mat maxDet(1, oneDim, CV_64S); maxDet.ptr<int64_t>()[0] = 25;
processNet("dnn/onnx/models/blazeface.onnx", "",
{std::make_tuple(input, "image"),
std::make_tuple(conf, "conf_threshold"),
std::make_tuple(iou, "iou_threshold"),
std::make_tuple(maxDet, "max_detections")});
}
PERF_TEST_P_(DNNTestNetwork, FacePaint)
{
processNet("dnn/onnx/models/face_paint_512_v2_0.onnx", "", cv::Size(512, 512));
}
// Model: https://huggingface.co/vietanhdev/segment-anything-2-onnx-models/blob/main/sam2_hiera_large.encoder.onnx
PERF_TEST_P_(DNNTestNetwork, SAM2_Encoder)
{
applyTestTag(CV_TEST_TAG_MEMORY_2GB, CV_TEST_TAG_VERYLONG);
Mat sample = imread(findDataFile("dnn/dog416.png"));
Mat inp = blobFromImage(sample, 1.0 / 255.0, Size(1024, 1024), Scalar(), true);
processNet("dnn/onnx/models/sam2_hiera_large.encoder.onnx", "", inp);
}
// Model: https://huggingface.co/vietanhdev/segment-anything-2-onnx-models/blob/main/sam2_hiera_large.decoder.onnx
PERF_TEST_P_(DNNTestNetwork, SAM2_Decoder)
{
applyTestTag(CV_TEST_TAG_MEMORY_1GB, CV_TEST_TAG_VERYLONG);
// Synthetic encoder outputs used as decoder inputs
int shp_embed[4] = {1, 256, 64, 64};
int shp_feat0[4] = {1, 32, 256, 256};
int shp_feat1[4] = {1, 64, 128, 128};
Mat image_embed(4, shp_embed, CV_32F);
Mat high_res_feats_0(4, shp_feat0, CV_32F);
Mat high_res_feats_1(4, shp_feat1, CV_32F);
randu(image_embed, 0.0f, 1.0f);
randu(high_res_feats_0, 0.0f, 1.0f);
randu(high_res_feats_1, 0.0f, 1.0f);
// Single point prompt at center of image, label=1 (foreground)
int shp_pts[3] = {1, 1, 2};
int shp_lbl[2] = {1, 1};
int shp_mask[4] = {1, 1, 256, 256};
int shp_hasmask[1] = {1};
float point_coords_data[2] = {512.0f, 512.0f};
float point_labels_data[1] = {1.0f};
float has_mask_input_data[1]= {0.0f};
Mat point_coords(3, shp_pts, CV_32F, point_coords_data);
Mat point_labels(2, shp_lbl, CV_32F, point_labels_data);
Mat mask_input(4, shp_mask, CV_32F, Scalar(0));
Mat has_mask_input(1, shp_hasmask, CV_32F, has_mask_input_data);
processNet("dnn/onnx/models/sam2_hiera_large.decoder.onnx", "",
{std::make_tuple(image_embed, "image_embed"),
std::make_tuple(high_res_feats_0, "high_res_feats_0"),
std::make_tuple(high_res_feats_1, "high_res_feats_1"),
std::make_tuple(point_coords, "point_coords"),
std::make_tuple(point_labels, "point_labels"),
std::make_tuple(mask_input, "mask_input"),
std::make_tuple(has_mask_input, "has_mask_input")});
}
// Model: https://github.com/opencv/opencv_zoo/tree/main/models/optical_flow_estimation_raft
PERF_TEST_P_(DNNTestNetwork, RAFT)
{
applyTestTag(CV_TEST_TAG_MEMORY_2GB, CV_TEST_TAG_VERYLONG);
// RAFT takes two consecutive frames to estimate optical flow between them
Mat frame0 = imread(findDataFile("gpu/opticalflow/frame0.png"));
Mat frame1 = imread(findDataFile("gpu/opticalflow/frame1.png"));
Mat blob0 = blobFromImage(frame0, 1.0, Size(480, 360), Scalar(), true);
Mat blob1 = blobFromImage(frame1, 1.0, Size(480, 360), Scalar(), true);
processNet("dnn/onnx/models/optical_flow_estimation_raft_2023aug.onnx", "",
{std::make_tuple(blob0, "0"),
std::make_tuple(blob1, "1")});
}
// Model: https://huggingface.co/onnx-community/owlv2-base-patch16-finetuned-ONNX
PERF_TEST_P_(DNNTestNetwork, OWLv2)
{
applyTestTag(CV_TEST_TAG_MEMORY_1GB, CV_TEST_TAG_VERYLONG);
// Image input: [1, 3, 960, 960] (60x60 patches x 16 = 960)
Mat sample = imread(findDataFile("dnn/dog416.png"));
Mat pixel_values = blobFromImage(sample, 1.0 / 255.0, Size(960, 960), Scalar(), true);
// Text query tokens: "a dog" with CLIP tokenizer, seq_len=16
// [BOS=49406, "a"=320, "dog"=1929, EOS=49407, pad=0, ...]
const int seq_len = 16;
int shp[2] = {1, seq_len};
int64_t input_ids_data[seq_len] = {49406, 320, 1929, 49407, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
int64_t attention_mask_data[seq_len]= {1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
Mat input_ids(2, shp, CV_64S, input_ids_data);
Mat attention_mask(2, shp, CV_64S, attention_mask_data);
processNet("dnn/onnx/models/owlv2_base_patch_16.onnx", "",
{std::make_tuple(input_ids, "input_ids"),
std::make_tuple(pixel_values, "pixel_values"),
std::make_tuple(attention_mask, "attention_mask")});
}
// Model: https://drive.google.com/file/d/1IU7iktOUbvNPFnDJb_ivl3LxYIdpEp3f/view?usp=drive_link
PERF_TEST_P_(DNNTestNetwork, YOLO26m_Seg)
{
applyTestTag(CV_TEST_TAG_MEMORY_512MB, CV_TEST_TAG_VERYLONG);
Mat sample = imread(findDataFile("dnn/dog416.png"));
Mat inp = blobFromImage(sample, 1.0 / 255.0, Size(640, 640), Scalar(), true);
processNet("dnn/onnx/models/yolo26m-seg.onnx", "", inp);
}
// Model: https://drive.google.com/file/d/17OWMXSiefFMmj46CT42Fd2q5kl_jHRBC/view?usp=drive_link
PERF_TEST_P_(DNNTestNetwork, YOLO26n)
{
applyTestTag(CV_TEST_TAG_MEMORY_512MB);
Mat sample = imread(findDataFile("dnn/dog416.png"));
Mat inp = blobFromImage(sample, 1.0 / 255.0, Size(640, 640), Scalar(), true);
processNet("dnn/onnx/models/yolo26n.onnx", "", inp);
}
// Model: https://huggingface.co/Xenova/segformer_b2_clothes/blob/main/onnx/model.onnx
PERF_TEST_P_(DNNTestNetwork, SegFormer_B2_Clothes)
{
applyTestTag(CV_TEST_TAG_MEMORY_512MB, CV_TEST_TAG_VERYLONG);
Mat sample = imread(findDataFile("dnn/dog416.png"));
Mat inp = blobFromImage(sample, 1.0 / 255.0, Size(512, 512), Scalar(), true);
processNet("dnn/onnx/models/segformer_b2_clothes.onnx", "", inp);
}
// Model: https://huggingface.co/Xenova/siglip-base-patch16-224/blob/main/onnx/model.onnx
PERF_TEST_P_(DNNTestNetwork, SigLIP)
{
applyTestTag(CV_TEST_TAG_MEMORY_512MB, CV_TEST_TAG_VERYLONG);
// Image input: [1, 3, 224, 224] normalized to [-1, 1]
Mat sample = imread(findDataFile("dnn/dog416.png"));
Mat pixel_values = blobFromImage(sample, 1.0 / 255.0, Size(224, 224), Scalar(0.5, 0.5, 0.5), true);
pixel_values = (pixel_values - 0.5f) / 0.5f;
// Text input: dummy token IDs for "a photo of a dog", seq_len=64
const int seq_len = 64;
int shp[2] = {1, seq_len};
Mat input_ids(2, shp, CV_64S, Scalar(0));
// BOS=1, "a photo of a dog"=some tokens, EOS=2
int64_t* ids = input_ids.ptr<int64_t>();
ids[0] = 1; ids[1] = 263; ids[2] = 2514; ids[3] = 275; ids[4] = 262; ids[5] = 3914; ids[6] = 2;
processNet("dnn/onnx/models/siglip_base_patch16_224.onnx", "",
{std::make_tuple(input_ids, "input_ids"),
std::make_tuple(pixel_values, "pixel_values")});
}
// Model: https://huggingface.co/onnx-community/depth-anything-v2-small/blob/main/onnx/model.onnx
PERF_TEST_P_(DNNTestNetwork, Depth_Anything_V2)
{
applyTestTag(CV_TEST_TAG_MEMORY_512MB, CV_TEST_TAG_VERYLONG);
Mat sample = imread(findDataFile("dnn/street.png"));
Mat inp = blobFromImage(sample, 1.0 / 255.0, Size(518, 518), Scalar(), true);
processNet("dnn/onnx/models/depth_anything_v2_small.onnx", "", inp);
}
// Model: https://drive.google.com/file/d/1G2begS7rrEmWnI-xj2K5UL3PQ7H_0svc/view?usp=drive_link
PERF_TEST_P_(DNNTestNetwork, RetinaFace)
{
applyTestTag(CV_TEST_TAG_MEMORY_512MB);
processNet("dnn/onnx/models/retinaface_10g.onnx", "", cv::Size(640, 640));
}
// Model: https://huggingface.co/onnx-community/grounding-dino-tiny-ONNX
PERF_TEST_P_(DNNTestNetwork, Grounding_DINO)
{
applyTestTag(CV_TEST_TAG_MEMORY_2GB, CV_TEST_TAG_VERYLONG);
// Image input: [1, 3, 800, 800]
Mat sample = imread(findDataFile("dnn/dog416.png"));
Mat pixel_values = blobFromImage(sample, 1.0 / 255.0, Size(800, 800), Scalar(), true);
// Text token inputs (dummy tokens for "dog ." as query text, seq_len=7)
const int seq_len = 7;
int64_t input_ids_data[seq_len] = {101, 3899, 1012, 102, 0, 0, 0};
int64_t attention_mask_data[seq_len] = {1, 1, 1, 1, 0, 0, 0};
int64_t token_type_ids_data[seq_len] = {0, 0, 0, 0, 0, 0, 0};
int shp[2] = {1, seq_len};
Mat input_ids(2, shp, CV_64S, input_ids_data);
Mat attention_mask(2, shp, CV_64S, attention_mask_data);
Mat token_type_ids(2, shp, CV_64S, token_type_ids_data);
// Image attention mask: [1, 800, 800] all ones (valid pixels)
int shp_mask[3] = {1, 800, 800};
Mat pixel_mask(3, shp_mask, CV_64S, Scalar(1));
processNet("dnn/onnx/models/grounding_dino_tiny.onnx", "",
{std::make_tuple(pixel_values, "pixel_values"),
std::make_tuple(input_ids, "input_ids"),
std::make_tuple(token_type_ids,"token_type_ids"),
std::make_tuple(attention_mask,"attention_mask"),
std::make_tuple(pixel_mask, "pixel_mask")});
}
// Model: https://drive.google.com/file/d/1P6a7oS_dV5y09FsCA4XDZK1-WcdZbWFh/view?usp=drive_link
PERF_TEST_P_(DNNTestNetwork, RF_DETR)
{
applyTestTag(CV_TEST_TAG_MEMORY_1GB, CV_TEST_TAG_VERYLONG);
Mat sample = imread(findDataFile("dnn/dog416.png"));
Mat inp = blobFromImage(sample, 1.0 / 255.0, Size(560, 560), Scalar(), true);
processNet("dnn/onnx/models/rfdetr.onnx", "", inp);
}
// Model: https://drive.google.com/file/d/1OrSmlXURayVQgW8nrrxjggzPMN7xPRGJ/view?usp=sharing
PERF_TEST_P_(DNNTestNetwork, RT_DETR_L)
{
applyTestTag(CV_TEST_TAG_MEMORY_1GB, CV_TEST_TAG_VERYLONG);
Mat sample = imread(findDataFile("dnn/dog416.png"));
Mat inp = blobFromImage(sample, 1.0 / 255.0, Size(640, 640), Scalar(), true);
processNet("dnn/onnx/models/rtdetr-l.onnx", "", inp);
}
// Model: https://drive.google.com/file/d/1HuR5jeGtgX6TKFlWR5JjwZ7be-JDwz57/view?usp=drive_link
PERF_TEST_P_(DNNTestNetwork, RTMPose_M)
{
applyTestTag(CV_TEST_TAG_MEMORY_512MB, CV_TEST_TAG_VERYLONG);
Mat sample = imread(findDataFile("dnn/dog416.png"));
Mat inp = blobFromImage(sample, 1.0 / 255.0, Size(192, 256), Scalar(), true);
processNet("dnn/onnx/models/rtmpose_m.onnx", "", inp);
}
// Model: https://huggingface.co/tomjackson2023/rembg/resolve/main/u2net.onnx
PERF_TEST_P_(DNNTestNetwork, U2Net)
{
applyTestTag(CV_TEST_TAG_MEMORY_512MB, CV_TEST_TAG_VERYLONG);
Mat sample = imread(findDataFile("dnn/dog416.png"));
Mat inp = blobFromImage(sample, 1.0 / 255.0, Size(320, 320), Scalar(), true);
processNet("dnn/onnx/models/u2net.onnx", "",
{std::make_tuple(inp, "input.1")});
}
// Model: https://huggingface.co/qualcomm/Real-ESRGAN-x4plus/resolve/01179a4da7bf5ac91faca650e6afbf282ac93933/Real-ESRGAN-x4plus.onnx
PERF_TEST_P_(DNNTestNetwork, RealESRGAN_x4plus)
{
applyTestTag(CV_TEST_TAG_MEMORY_512MB, CV_TEST_TAG_VERYLONG);
Mat sample = imread(findDataFile("dnn/dog416.png"));
Mat inp = blobFromImage(sample, 1.0 / 255.0, Size(128, 128), Scalar(), true);
processNet("dnn/onnx/models/realesrgan_x4plus.onnx", "",
{std::make_tuple(inp, "image")});
}
// Model: https://huggingface.co/rocca/swin-ir-onnx/resolve/main/003_realSR_BSRGAN_DFO_s64w8_SwinIR-M_x4_GAN.onnx
PERF_TEST_P_(DNNTestNetwork, SwinIR_x4)
{
applyTestTag(CV_TEST_TAG_MEMORY_512MB, CV_TEST_TAG_VERYLONG);
Mat sample = imread(findDataFile("dnn/dog416.png"));
Mat inp = blobFromImage(sample, 1.0 / 255.0, Size(128, 128), Scalar(), true);
processNet("dnn/onnx/models/swinir_x4_gan.onnx", "", inp);
}
// Model: https://huggingface.co/onnx-community/BiRefNet-ONNX/resolve/main/onnx/model.onnx
PERF_TEST_P_(DNNTestNetwork, BiRefNet)
{
applyTestTag(CV_TEST_TAG_MEMORY_2GB, CV_TEST_TAG_VERYLONG);
Mat sample = imread(findDataFile("dnn/dog416.png"));
Mat inp = blobFromImage(sample, 1.0 / 255.0, Size(1024, 1024), Scalar(), true);
processNet("dnn/onnx/models/birefnet.onnx", "",
{std::make_tuple(inp, "input_image")});
}
// Model: https://huggingface.co/onnx-community/dinov2-small/resolve/main/onnx/model.onnx
PERF_TEST_P_(DNNTestNetwork, DINOv2_Small)
{
applyTestTag(CV_TEST_TAG_MEMORY_512MB, CV_TEST_TAG_VERYLONG);
Mat sample = imread(findDataFile("dnn/dog416.png"));
Mat inp = blobFromImage(sample, 1.0 / 255.0, Size(224, 224), Scalar(), true);
processNet("dnn/onnx/models/dinov2_small.onnx", "",
{std::make_tuple(inp, "pixel_values")});
}
INSTANTIATE_TEST_CASE_P(/*nothing*/, DNNTestNetwork, dnnBackendsAndTargets());
} // namespace
+14
View File
@@ -0,0 +1,14 @@
#ifndef __OPENCV_PERF_PRECOMP_HPP__
#define __OPENCV_PERF_PRECOMP_HPP__
#include <opencv2/ts.hpp>
#include <opencv2/dnn.hpp>
#include "../test/test_common.hpp"
namespace opencv_test {
using namespace perf;
using namespace cv::dnn;
} // namespace
#endif
+90
View File
@@ -0,0 +1,90 @@
// This file is part of OpenCV project.
// It is subject to the license terms in the LICENSE file found in the top-level directory
// of this distribution and at http://opencv.org/license.html.
#include "perf_precomp.hpp"
namespace opencv_test {
struct LstmParams {
// Batch size
int nrSamples;
// Size of the input vector
int inputSize;
// Size of the internal state vector
int hiddenSize;
// Number of timesteps for the LSTM
int nrSteps;
};
static inline void PrintTo(const LstmParams& params, ::std::ostream* os) {
(*os) << "BATCH=" << params.nrSamples
<< ", IN=" << params.inputSize
<< ", HIDDEN=" << params.hiddenSize
<< ", TS=" << params.nrSteps;
}
static const LstmParams testLstmConfigs[] = {
{1, 192, 192, 100},
{1, 1024, 192, 100},
{1, 64, 192, 100},
{1, 192, 512, 100},
{64, 192, 192, 2},
{64, 1024, 192, 2},
{64, 64, 192, 2},
{64, 192, 512, 2},
{128, 192, 192, 2},
{128, 1024, 192, 2},
{128, 64, 192, 2},
{128, 192, 512, 2}
};
class Layer_LSTM : public TestBaseWithParam<LstmParams> {};
PERF_TEST_P_(Layer_LSTM, lstm) {
const LstmParams& params = GetParam();
LayerParams lp;
lp.type = "LSTM";
lp.name = "testLstm";
lp.set("produce_cell_output", false);
lp.set("use_timestamp_dim", true);
Mat weightH(params.hiddenSize * 4, params.hiddenSize, CV_32FC1, cv::Scalar(0));
Mat weightX(params.hiddenSize * 4, params.inputSize, CV_32FC1, cv::Scalar(0));
Mat bias(params.hiddenSize * 4, 1, CV_32FC1, cv::Scalar(0));
Mat hInternal(params.nrSteps, params.hiddenSize, CV_32FC1, cv::Scalar(0));
Mat cInternal(params.nrSteps, params.hiddenSize, CV_32FC1, cv::Scalar(0));
lp.blobs.push_back(weightH);
lp.blobs.push_back(weightX);
lp.blobs.push_back(bias);
lp.blobs.push_back(hInternal);
lp.blobs.push_back(cInternal);
std::vector<int> inputDims;
inputDims.push_back(params.nrSamples);
inputDims.push_back(params.nrSteps);
inputDims.push_back(params.inputSize);
Mat input(inputDims.size(), inputDims.data(), CV_32FC1);
input = cv::Scalar(0);
Net net;
net.addLayerToPrev(lp.name, lp.type, lp);
net.setInput(input);
// Warm up
std::vector<Mat> outputs(2);
net.forward(outputs, "testLstm");
TEST_CYCLE()
{
net.forward(outputs, "testLstm");
}
SANITY_CHECK_NOTHING();
}
INSTANTIATE_TEST_CASE_P(/**/, Layer_LSTM, testing::ValuesIn(testLstmConfigs));
} // namespace
+65
View File
@@ -0,0 +1,65 @@
// This file is part of OpenCV project.
// It is subject to the license terms in the LICENSE file found in the top-level directory
// of this distribution and at http://opencv.org/license.html.
#include "perf_precomp.hpp"
namespace opencv_test {
struct Layer_Resize : public TestBaseWithParam<tuple<Backend, Target>>
{
void test_layer(const std::vector<int>& inpShape, int outH, int outW, const String& interp)
{
int backendId = get<0>(GetParam());
int targetId = get<1>(GetParam());
Mat input(inpShape, CV_32FC1);
randu(input, 0.f, 1.f);
Net net;
LayerParams lp;
lp.type = "Resize";
lp.name = "testLayer";
lp.set("interpolation", interp);
lp.set("width", outW);
lp.set("height", outH);
int id = net.addLayerToPrev(lp.name, lp.type, lp);
net.connect(0, 0, id, 0);
// warmup
{
net.setInputsNames({"data"});
net.setInput(input, "data");
net.setPreferableBackend(backendId);
net.setPreferableTarget(targetId);
Mat out = net.forward();
}
TEST_CYCLE()
{
Mat res = net.forward();
}
SANITY_CHECK_NOTHING();
}
};
PERF_TEST_P_(Layer_Resize, Resize_Upsample_Linear)
{
// N=4, C=64, H=64, W=64 -> 128x128 (x2 upsample)
// Common in segmentation/detection heads
test_layer({4, 64, 64, 64}, 128, 128, "opencv_linear");
}
PERF_TEST_P_(Layer_Resize, Resize_Downsample_Nearest)
{
// N=4, C=128, H=128, W=128 -> 64x64 (x0.5 downsample)
test_layer({4, 128, 128, 128}, 64, 64, "nearest");
}
INSTANTIATE_TEST_CASE_P(/**/, Layer_Resize, dnnBackendsAndTargets());
} // namespace opencv_test
+93
View File
@@ -0,0 +1,93 @@
// This file is part of OpenCV project.
// It is subject to the license terms in the LICENSE file found in the top-level directory
// of this distribution and at http://opencv.org/license.html.
#include "perf_precomp.hpp"
namespace opencv_test {
struct Layer_Slice : public TestBaseWithParam<tuple<Backend, Target>>
{
void test_slice(const std::vector<int>& input_shape, int axis, int begin, int end, int step = 1)
{
int backendId = get<0>(GetParam());
int targetId = get<1>(GetParam());
Mat data(input_shape, CV_32FC1);
randu(data, 0.f, 1.f);
Net net;
LayerParams lp;
lp.type = "Slice";
lp.name = "testLayer";
lp.set("axis", axis);
std::vector<int> begins(input_shape.size(), 0);
std::vector<int> ends = input_shape;
std::vector<int> steps(input_shape.size(), 1);
begins[axis] = begin;
ends[axis] = end;
steps[axis] = step;
lp.set("begin", DictValue::arrayInt(&begins[0], begins.size()));
lp.set("end", DictValue::arrayInt(&ends[0], ends.size()));
if (step != 1) {
lp.set("steps", DictValue::arrayInt(&steps[0], steps.size()));
}
int id = net.addLayerToPrev(lp.name, lp.type, lp);
net.connect(0, 0, id, 0);
net.setInputsNames({"data"});
// warmup
{
net.setInput(data, "data");
net.setPreferableBackend(backendId);
net.setPreferableTarget(targetId);
Mat out = net.forward();
}
TEST_CYCLE()
{
Mat res = net.forward();
}
SANITY_CHECK_NOTHING();
}
};
PERF_TEST_P_(Layer_Slice, Slice_Contiguous_Axis0)
{
test_slice({64, 128, 128}, 0, 10, 54);
}
PERF_TEST_P_(Layer_Slice, Slice_Contiguous_Axis2)
{
test_slice({64, 128, 128}, 2, 10, 118);
}
PERF_TEST_P_(Layer_Slice, Slice_Small_Middle)
{
test_slice({32, 64, 32}, 1, 20, 40);
}
PERF_TEST_P_(Layer_Slice, Slice_Strided_Axis0_Step2)
{
// Strided slice on outer axis.
// [64, 128, 128] -> [0:64:2, ...]
test_slice({64, 128, 128}, 0, 0, 64, 2);
}
PERF_TEST_P_(Layer_Slice, Slice_Strided_Axis2_Step2)
{
// Strided slice on inner axis.
// [64, 128, 128] -> [..., 0:128:2]
test_slice({64, 128, 128}, 2, 0, 128, 2);
}
INSTANTIATE_TEST_CASE_P(/**/, Layer_Slice, dnnBackendsAndTargets(false, false, true, false, false, false, false, false));
} // namespace opencv_test
+72
View File
@@ -0,0 +1,72 @@
// This file is part of OpenCV project.
// It is subject to the license terms in the LICENSE file found in the top-level directory
// of this distribution and at http://opencv.org/license.html.
//
// Copyright (C) 2017, Intel Corporation, all rights reserved.
// Third party copyrights are property of their respective owners.
#include "perf_precomp.hpp"
namespace opencv_test {
using Utils_blobFromImage = TestBaseWithParam<std::vector<int>>;
PERF_TEST_P_(Utils_blobFromImage, HWC_TO_NCHW) {
std::vector<int> input_shape = GetParam();
Mat input(input_shape, CV_32FC3);
randu(input, -10.0f, 10.f);
TEST_CYCLE() {
Mat blob = blobFromImage(input);
}
SANITY_CHECK_NOTHING();
}
INSTANTIATE_TEST_CASE_P(/**/, Utils_blobFromImage,
Values(std::vector<int>{ 32, 32},
std::vector<int>{ 64, 64},
std::vector<int>{ 128, 128},
std::vector<int>{ 256, 256},
std::vector<int>{ 512, 512},
std::vector<int>{1024, 1024},
std::vector<int>{2048, 2048})
);
using Utils_blobFromImages = TestBaseWithParam<std::vector<int>>;
PERF_TEST_P_(Utils_blobFromImages, HWC_TO_NCHW) {
std::vector<int> input_shape = GetParam();
int batch = input_shape.front();
std::vector<int> input_shape_no_batch(input_shape.begin()+1, input_shape.end());
if (input_shape_no_batch[0]*input_shape_no_batch[1] >= 2048*2048)
{
applyTestTag( CV_TEST_TAG_MEMORY_2GB);
}
std::vector<Mat> inputs;
for (int i = 0; i < batch; i++) {
Mat input(input_shape_no_batch, CV_32FC3);
randu(input, -10.0f, 10.f);
inputs.push_back(input);
}
TEST_CYCLE() {
Mat blobs = blobFromImages(inputs);
}
SANITY_CHECK_NOTHING();
}
INSTANTIATE_TEST_CASE_P(/**/, Utils_blobFromImages,
Values(std::vector<int>{16, 32, 32},
std::vector<int>{16, 64, 64},
std::vector<int>{16, 128, 128},
std::vector<int>{16, 256, 256},
std::vector<int>{16, 512, 512},
std::vector<int>{16, 1024, 1024},
std::vector<int>{16, 2048, 2048})
);
}