Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/3.4' into merge-3.4
Browse files Browse the repository at this point in the history
  • Loading branch information
alalek committed Dec 15, 2021
2 parents 498f152 + 6a889ed commit 299f983
Show file tree
Hide file tree
Showing 26 changed files with 4,405 additions and 18 deletions.
4 changes: 2 additions & 2 deletions cmake/OpenCVDetectInferenceEngine.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,8 @@ if(DEFINED InferenceEngine_VERSION)
endif()
endif()
if(NOT INF_ENGINE_RELEASE AND NOT INF_ENGINE_RELEASE_INIT)
message(STATUS "WARNING: InferenceEngine version has not been set, 2021.4.1 will be used by default. Set INF_ENGINE_RELEASE variable if you experience build errors.")
set(INF_ENGINE_RELEASE_INIT "2021040100")
message(STATUS "WARNING: InferenceEngine version has not been set, 2021.4.2 will be used by default. Set INF_ENGINE_RELEASE variable if you experience build errors.")
set(INF_ENGINE_RELEASE_INIT "2021040200")
elseif(DEFINED INF_ENGINE_RELEASE)
set(INF_ENGINE_RELEASE_INIT "${INF_ENGINE_RELEASE}")
endif()
Expand Down
2 changes: 1 addition & 1 deletion doc/tutorials/imgproc/pyramids/pyramids.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ Theory
- To produce layer \f$(i+1)\f$ in the Gaussian pyramid, we do the following:
- Convolve \f$G_{i}\f$ with a Gaussian kernel:

\f[\frac{1}{16} \begin{bmatrix} 1 & 4 & 6 & 4 & 1 \\ 4 & 16 & 24 & 16 & 4 \\ 6 & 24 & 36 & 24 & 6 \\ 4 & 16 & 24 & 16 & 4 \\ 1 & 4 & 6 & 4 & 1 \end{bmatrix}\f]
\f[\frac{1}{256} \begin{bmatrix} 1 & 4 & 6 & 4 & 1 \\ 4 & 16 & 24 & 16 & 4 \\ 6 & 24 & 36 & 24 & 6 \\ 4 & 16 & 24 & 16 & 4 \\ 1 & 4 & 6 & 4 & 1 \end{bmatrix}\f]

- Remove every even-numbered row and column.

Expand Down
9 changes: 5 additions & 4 deletions modules/dnn/src/layers/padding_layer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -140,12 +140,13 @@ class PaddingLayerImpl CV_FINAL : public PaddingLayer
outputs[0].setTo(paddingValue);
inputs[0].copyTo(outputs[0](dstRanges));
}
else if (paddingType == "reflect")
else if (paddingType == "reflect" || paddingType == "edge")
{
CV_Assert(inputs.size() == 1);
CV_Assert(outputs.size() == 1);
CV_Assert(inputs[0].dims == 4);
CV_Assert(outputs[0].dims == 4);
int borderType = paddingType == "reflect" ? BORDER_REFLECT_101 : BORDER_REPLICATE;

if (inputs[0].size[0] != outputs[0].size[0] || inputs[0].size[1] != outputs[0].size[1])
CV_Error(Error::StsNotImplemented, "Only spatial reflection padding is supported.");
Expand All @@ -158,8 +159,8 @@ class PaddingLayerImpl CV_FINAL : public PaddingLayer
const int padBottom = outHeight - dstRanges[2].end;
const int padLeft = dstRanges[3].start;
const int padRight = outWidth - dstRanges[3].end;
CV_CheckLT(padTop, inpHeight, ""); CV_CheckLT(padBottom, inpHeight, "");
CV_CheckLT(padLeft, inpWidth, ""); CV_CheckLT(padRight, inpWidth, "");
CV_CheckLE(padTop, inpHeight, ""); CV_CheckLE(padBottom, inpHeight, "");
CV_CheckLE(padLeft, inpWidth, ""); CV_CheckLE(padRight, inpWidth, "");

for (size_t n = 0; n < inputs[0].size[0]; ++n)
{
Expand All @@ -168,7 +169,7 @@ class PaddingLayerImpl CV_FINAL : public PaddingLayer
copyMakeBorder(getPlane(inputs[0], n, ch),
getPlane(outputs[0], n, ch),
padTop, padBottom, padLeft, padRight,
BORDER_REFLECT_101);
borderType);
}
}
}
Expand Down
49 changes: 45 additions & 4 deletions modules/dnn/src/onnx/onnx_importer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ class ONNXImporter
static const DispatchMap buildDispatchMap();

void parseArg (LayerParams& layerParams, const opencv_onnx::NodeProto& node_proto);
void parseMaxUnpool (LayerParams& layerParams, const opencv_onnx::NodeProto& node_proto);
void parseMaxPool (LayerParams& layerParams, const opencv_onnx::NodeProto& node_proto);
void parseAveragePool (LayerParams& layerParams, const opencv_onnx::NodeProto& node_proto);
void parseReduce (LayerParams& layerParams, const opencv_onnx::NodeProto& node_proto);
Expand Down Expand Up @@ -790,6 +791,41 @@ void setCeilMode(LayerParams& layerParams)
}
}

void ONNXImporter::parseMaxUnpool(LayerParams& layerParams, const opencv_onnx::NodeProto& node_proto)
{
layerParams.type = "MaxUnpool";

DictValue kernel_shape = layerParams.get("kernel_size");
CV_Assert(kernel_shape.size() == 2);
layerParams.set("pool_k_w", kernel_shape.get<int>(0));
layerParams.set("pool_k_h", kernel_shape.get<int>(1));

int pool_pad_w = 0, pool_pad_h = 0;
if (layerParams.has("pad"))
{
DictValue pads = layerParams.get("pad");
CV_CheckEQ(pads.size(), 2, "");
pool_pad_w = pads.get<int>(0);
pool_pad_h = pads.get<int>(1);
}
layerParams.set("pool_pad_w", pool_pad_w);
layerParams.set("pool_pad_h", pool_pad_h);


int pool_stride_w = 1, pool_stride_h = 1;
if (layerParams.has("stride"))
{
DictValue strides = layerParams.get("stride");
CV_CheckEQ(strides.size(), 2, "");
pool_stride_w = strides.get<int>(0);
pool_stride_h = strides.get<int>(1);
}
layerParams.set("pool_stride_w", pool_stride_w);
layerParams.set("pool_stride_h", pool_stride_h);

addLayer(layerParams, node_proto);
}

void ONNXImporter::parseMaxPool(LayerParams& layerParams, const opencv_onnx::NodeProto& node_proto)
{
int depth = layerParams.get<int>("depth", CV_32F);
Expand Down Expand Up @@ -824,11 +860,11 @@ void ONNXImporter::parseReduce(LayerParams& layerParams, const opencv_onnx::Node
pool = "AVE";
layerParams.set("pool", pool);
layerParams.set("global_pooling", !layerParams.has("axes"));
bool keepdims = layerParams.get<int>("keepdims", 1) == 1;
if (layerParams.has("axes") && (layer_type == "ReduceMean" || layer_type == "ReduceSum" || layer_type == "ReduceMax"))
{
MatShape inpShape = outShapes[node_proto.input(0)];
DictValue axes = layerParams.get("axes");
bool keepdims = layerParams.get<int>("keepdims");
MatShape targetShape;
std::vector<bool> shouldDelete(inpShape.size(), false);
for (int i = 0; i < axes.size(); i++) {
Expand Down Expand Up @@ -936,7 +972,10 @@ void ONNXImporter::parseReduce(LayerParams& layerParams, const opencv_onnx::Node
}
else if (!layerParams.has("axes") && (layer_type == "ReduceMean" || layer_type == "ReduceSum" || layer_type == "ReduceMax"))
{
CV_CheckEQ(layerParams.get<int>("keepdims"), 0, "layer only supports keepdims = false");
IterShape_t shapeIt = outShapes.find(node_proto.input(0));
CV_Assert(shapeIt != outShapes.end());
const size_t dims = keepdims ? shapeIt->second.size() : 1;

LayerParams reshapeLp;
reshapeLp.name = layerParams.name + "/reshape";
reshapeLp.type = "Reshape";
Expand All @@ -958,8 +997,8 @@ void ONNXImporter::parseReduce(LayerParams& layerParams, const opencv_onnx::Node
addLayer(poolLp, node_proto);

layerParams.type = "Reshape";
int targetShape[] = {1};
layerParams.set("dim", DictValue::arrayInt(&targetShape[0], 1));
std::vector<int> targetShape(dims, 1);
layerParams.set("dim", DictValue::arrayInt(targetShape.data(), targetShape.size()));

node_proto.set_input(0, node_proto.output(0));
node_proto.set_output(0, layerParams.name);
Expand Down Expand Up @@ -1412,6 +1451,7 @@ void ONNXImporter::parseImageScaler(LayerParams& layerParams, const opencv_onnx:

void ONNXImporter::parseClip(LayerParams& layerParams, const opencv_onnx::NodeProto& node_proto)
{
CV_CheckEQ(node_proto.input_size(), 1, "");
layerParams.type = "ReLU6";
layerParams.set("min_value", layerParams.get<float>("min", -FLT_MAX));
layerParams.set("max_value", layerParams.get<float>("max", FLT_MAX));
Expand Down Expand Up @@ -2996,6 +3036,7 @@ const ONNXImporter::DispatchMap ONNXImporter::buildDispatchMap()
DispatchMap dispatch;

dispatch["ArgMax"] = dispatch["ArgMin"] = &ONNXImporter::parseArg;
dispatch["MaxUnpool"] = &ONNXImporter::parseMaxUnpool;
dispatch["MaxPool"] = &ONNXImporter::parseMaxPool;
dispatch["AveragePool"] = &ONNXImporter::parseAveragePool;
dispatch["GlobalAveragePool"] = dispatch["GlobalMaxPool"] = dispatch["ReduceMean"] = dispatch["ReduceSum"] =
Expand Down
6 changes: 5 additions & 1 deletion modules/dnn/test/test_common.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,9 @@
#define INF_ENGINE_VER_MAJOR_LE(ver) (((INF_ENGINE_RELEASE) / 10000) <= ((ver) / 10000))
#define INF_ENGINE_VER_MAJOR_EQ(ver) (((INF_ENGINE_RELEASE) / 10000) == ((ver) / 10000))


#define CV_TEST_TAG_DNN_SKIP_OPENCV_BACKEND "dnn_skip_opencv_backend"
#define CV_TEST_TAG_DNN_SKIP_HALIDE "dnn_skip_halide"
#define CV_TEST_TAG_DNN_SKIP_CPU "dnn_skip_cpu"
#define CV_TEST_TAG_DNN_SKIP_OPENCL "dnn_skip_ocl"
#define CV_TEST_TAG_DNN_SKIP_OPENCL_FP16 "dnn_skip_ocl_fp16"
#define CV_TEST_TAG_DNN_SKIP_IE_NN_BUILDER "dnn_skip_ie_nn_builder"
Expand All @@ -44,6 +45,9 @@
#define CV_TEST_TAG_DNN_SKIP_CUDA_FP16 "dnn_skip_cuda_fp16"
#define CV_TEST_TAG_DNN_SKIP_CUDA_FP32 "dnn_skip_cuda_fp32"

#define CV_TEST_TAG_DNN_SKIP_ONNX_CONFORMANCE "dnn_skip_onnx_conformance"
#define CV_TEST_TAG_DNN_SKIP_PARSER "dnn_skip_parser"


#ifdef HAVE_INF_ENGINE
#if INF_ENGINE_VER_MAJOR_EQ(2018050000)
Expand Down
13 changes: 11 additions & 2 deletions modules/dnn/test/test_common.impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -442,9 +442,15 @@ void initDNNTests()
cvtest::addDataSearchPath(extraTestDataPath);

registerGlobalSkipTag(
CV_TEST_TAG_DNN_SKIP_HALIDE,
CV_TEST_TAG_DNN_SKIP_OPENCV_BACKEND,
CV_TEST_TAG_DNN_SKIP_CPU,
CV_TEST_TAG_DNN_SKIP_OPENCL, CV_TEST_TAG_DNN_SKIP_OPENCL_FP16
);
#if defined(HAVE_HALIDE)
registerGlobalSkipTag(
CV_TEST_TAG_DNN_SKIP_HALIDE
);
#endif
#if defined(INF_ENGINE_RELEASE)
registerGlobalSkipTag(
CV_TEST_TAG_DNN_SKIP_IE,
Expand Down Expand Up @@ -478,12 +484,15 @@ void initDNNTests()
CV_TEST_TAG_DNN_SKIP_VULKAN
);
#endif

#ifdef HAVE_CUDA
registerGlobalSkipTag(
CV_TEST_TAG_DNN_SKIP_CUDA, CV_TEST_TAG_DNN_SKIP_CUDA_FP32, CV_TEST_TAG_DNN_SKIP_CUDA_FP16
);
#endif
registerGlobalSkipTag(
CV_TEST_TAG_DNN_SKIP_ONNX_CONFORMANCE,
CV_TEST_TAG_DNN_SKIP_PARSER
);
}

} // namespace
Loading

0 comments on commit 299f983

Please sign in to comment.