1
0
mirror of https://github.com/opencv/opencv.git synced 2026-07-30 07:43:03 +04:00

Merge remote-tracking branch 'upstream/3.4' into merge-3.4

This commit is contained in:
Alexander Alekhin
2020-12-11 19:27:20 +00:00
24 changed files with 983 additions and 224 deletions
+19 -10
View File
@@ -71,6 +71,14 @@ using std::min;
using namespace cv::dnn::ocl4dnn;
#endif
#ifdef HAVE_HALIDE
#if 0 // size_t is not well supported in Halide operations
typedef size_t HALIDE_DIFF_T;
#else
typedef int HALIDE_DIFF_T;
#endif
#endif
#ifdef HAVE_CUDA
#include "../cuda4dnn/primitives/pooling.hpp"
#include "../cuda4dnn/primitives/roi_pooling.hpp"
@@ -78,6 +86,7 @@ using namespace cv::dnn::ocl4dnn;
using namespace cv::dnn::cuda4dnn;
#endif
namespace cv
{
namespace dnn
@@ -1097,12 +1106,12 @@ public:
Halide::Buffer<float> inputBuffer = halideBuffer(inputs[0]);
const int inWidth = inputBuffer.width();
const int inHeight = inputBuffer.height();
const size_t kernelHeight = kernel_size[0];
const size_t kernelWidth = kernel_size[1];
const size_t strideHeight = strides[0];
const size_t strideWidth = strides[1];
const size_t paddingTop = pads_begin[0];
const size_t paddingLeft = pads_begin[1];
const HALIDE_DIFF_T kernelHeight = (HALIDE_DIFF_T)kernel_size[0];
const HALIDE_DIFF_T kernelWidth = (HALIDE_DIFF_T)kernel_size[1];
const HALIDE_DIFF_T strideHeight = (HALIDE_DIFF_T)strides[0];
const HALIDE_DIFF_T strideWidth = (HALIDE_DIFF_T)strides[1];
const HALIDE_DIFF_T paddingTop = (HALIDE_DIFF_T)pads_begin[0];
const HALIDE_DIFF_T paddingLeft = (HALIDE_DIFF_T)pads_begin[1];
Halide::Var x("x"), y("y"), c("c"), n("n");
Halide::Func top = (name.empty() ? Halide::Func() : Halide::Func(name));
@@ -1148,10 +1157,10 @@ public:
Halide::Buffer<float> inputBuffer = halideBuffer(inputs[0]);
const int inW = inputBuffer.width(), inH = inputBuffer.height();
const size_t kernelHeight = kernel_size[0];
const size_t kernelWidth = kernel_size[1];
const size_t strideHeight = strides[0];
const size_t strideWidth = strides[1];
const HALIDE_DIFF_T kernelHeight = (HALIDE_DIFF_T)kernel_size[0];
const HALIDE_DIFF_T kernelWidth = (HALIDE_DIFF_T)kernel_size[1];
const HALIDE_DIFF_T strideHeight = (HALIDE_DIFF_T)strides[0];
const HALIDE_DIFF_T strideWidth = (HALIDE_DIFF_T)strides[1];
if ((inW - kernelWidth) % strideWidth || (inH - kernelHeight) % strideHeight)
{
CV_Error(cv::Error::StsNotImplemented,
+49 -1
View File
@@ -124,7 +124,7 @@ public:
Mat& inp = inputs[0];
Mat& out = outputs[0];
if (interpolation == "nearest" || interpolation == "opencv_linear" || (interpolation == "bilinear" && halfPixelCenters))
if ((interpolation == "nearest" && !alignCorners && !halfPixelCenters) || interpolation == "opencv_linear" || (interpolation == "bilinear" && halfPixelCenters))
{
InterpolationFlags mode = interpolation == "nearest" ? INTER_NEAREST : INTER_LINEAR;
for (size_t n = 0; n < inputs[0].size[0]; ++n)
@@ -136,6 +136,54 @@ public:
}
}
}
else if (interpolation == "nearest")
{
const int inpHeight = inp.size[2];
const int inpWidth = inp.size[3];
const int inpSpatialSize = inpHeight * inpWidth;
const int outSpatialSize = outHeight * outWidth;
const int numPlanes = inp.size[0] * inp.size[1];
CV_Assert_N(inp.isContinuous(), out.isContinuous());
Mat inpPlanes = inp.reshape(1, numPlanes * inpHeight);
Mat outPlanes = out.reshape(1, numPlanes * outHeight);
float heightOffset = 0.0f;
float widthOffset = 0.0f;
if (halfPixelCenters)
{
heightOffset = 0.5f * scaleHeight;
widthOffset = 0.5f * scaleWidth;
}
for (int y = 0; y < outHeight; ++y)
{
float input_y = y * scaleHeight + heightOffset;
int y0 = halfPixelCenters ? std::floor(input_y) : lroundf(input_y);
y0 = std::min(y0, inpHeight - 1);
const float* inpData_row = inpPlanes.ptr<float>(y0);
for (int x = 0; x < outWidth; ++x)
{
float input_x = x * scaleWidth + widthOffset;
int x0 = halfPixelCenters ? std::floor(input_x) : lroundf(input_x);
x0 = std::min(x0, inpWidth - 1);
float* outData = outPlanes.ptr<float>(y, x);
const float* inpData_row_c = inpData_row;
for (int c = 0; c < numPlanes; ++c)
{
*outData = inpData_row_c[x0];
inpData_row_c += inpSpatialSize;
outData += outSpatialSize;
}
}
}
}
else if (interpolation == "bilinear")
{
const int inpHeight = inp.size[2];
+18
View File
@@ -101,6 +101,9 @@ public:
TEST_P(DNNTestNetwork, AlexNet)
{
applyTestTag(CV_TEST_TAG_MEMORY_1GB);
if (backend == DNN_BACKEND_HALIDE) // Realization contains wrong number of Images (1) for realizing pipeline with 2 outputs
applyTestTag(CV_TEST_TAG_DNN_SKIP_HALIDE);
processNet("dnn/bvlc_alexnet.caffemodel", "dnn/bvlc_alexnet.prototxt",
Size(227, 227), "prob",
target == DNN_TARGET_OPENCL ? "dnn/halide_scheduler_opencl_alexnet.yml" :
@@ -115,6 +118,9 @@ TEST_P(DNNTestNetwork, ResNet_50)
(target == DNN_TARGET_CPU ? CV_TEST_TAG_MEMORY_512MB : CV_TEST_TAG_MEMORY_1GB),
CV_TEST_TAG_DEBUG_LONG
);
if (backend == DNN_BACKEND_HALIDE) // Realization contains wrong number of Images (1) for realizing pipeline with 2 outputs
applyTestTag(CV_TEST_TAG_DNN_SKIP_HALIDE);
processNet("dnn/ResNet-50-model.caffemodel", "dnn/ResNet-50-deploy.prototxt",
Size(224, 224), "prob",
target == DNN_TARGET_OPENCL ? "dnn/halide_scheduler_opencl_resnet_50.yml" :
@@ -125,6 +131,9 @@ TEST_P(DNNTestNetwork, ResNet_50)
TEST_P(DNNTestNetwork, SqueezeNet_v1_1)
{
if (backend == DNN_BACKEND_HALIDE) // Realization contains wrong number of Images (1) for realizing pipeline with 2 outputs
applyTestTag(CV_TEST_TAG_DNN_SKIP_HALIDE);
processNet("dnn/squeezenet_v1.1.caffemodel", "dnn/squeezenet_v1.1.prototxt",
Size(227, 227), "prob",
target == DNN_TARGET_OPENCL ? "dnn/halide_scheduler_opencl_squeezenet_v1_1.yml" :
@@ -136,6 +145,9 @@ TEST_P(DNNTestNetwork, SqueezeNet_v1_1)
TEST_P(DNNTestNetwork, GoogLeNet)
{
applyTestTag(target == DNN_TARGET_CPU ? "" : CV_TEST_TAG_MEMORY_512MB);
if (backend == DNN_BACKEND_HALIDE) // Realization contains wrong number of Images (1) for realizing pipeline with 2 outputs
applyTestTag(CV_TEST_TAG_DNN_SKIP_HALIDE);
processNet("dnn/bvlc_googlenet.caffemodel", "dnn/bvlc_googlenet.prototxt",
Size(224, 224), "prob");
expectNoFallbacksFromIE(net);
@@ -145,6 +157,9 @@ TEST_P(DNNTestNetwork, GoogLeNet)
TEST_P(DNNTestNetwork, Inception_5h)
{
applyTestTag(CV_TEST_TAG_MEMORY_512MB);
if (backend == DNN_BACKEND_HALIDE) // Realization contains wrong number of Images (1) for realizing pipeline with 2 outputs
applyTestTag(CV_TEST_TAG_DNN_SKIP_HALIDE);
double l1 = default_l1, lInf = default_lInf;
if (backend == DNN_BACKEND_INFERENCE_ENGINE_NN_BUILDER_2019 && (target == DNN_TARGET_CPU || target == DNN_TARGET_OPENCL))
{
@@ -162,6 +177,9 @@ TEST_P(DNNTestNetwork, Inception_5h)
TEST_P(DNNTestNetwork, ENet)
{
applyTestTag(target == DNN_TARGET_CPU ? "" : CV_TEST_TAG_MEMORY_512MB);
if (backend == DNN_BACKEND_HALIDE) // Realization contains wrong number of Images (1) for realizing pipeline with 2 outputs
applyTestTag(CV_TEST_TAG_DNN_SKIP_HALIDE);
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)
+13
View File
@@ -1001,6 +1001,19 @@ TEST_P(Test_TensorFlow_layers, resize_nearest_neighbor)
runTensorFlowNet("keras_upsampling2d");
}
TEST_P(Test_TensorFlow_layers, resize_nearest_neighbor_align_corners)
{
runTensorFlowNet("resize_nearest_neighbor", false, 0.0, 0.0, false, "_align_corners");
}
TEST_P(Test_TensorFlow_layers, resize_nearest_neighbor_half_pixel)
{
if (backend == DNN_BACKEND_INFERENCE_ENGINE_NGRAPH)
applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_NGRAPH);
runTensorFlowNet("resize_nearest_neighbor", false, 0.0, 0.0, false, "_half_pixel");
}
TEST_P(Test_TensorFlow_layers, fused_resize_conv)
{
runTensorFlowNet("fused_resize_conv");