From a8f04359e8d1ffb115637a5dc50e8d6fb185c114 Mon Sep 17 00:00:00 2001 From: Jan Lebert Date: Thu, 18 Jun 2020 13:30:36 +0200 Subject: [PATCH 1/7] docs: linkfix in bibliography The [current link](https://arxiv.org/pdf/1808.01752) goes to a random unrelated paper. --- doc/opencv.bib | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/doc/opencv.bib b/doc/opencv.bib index 901fbe86ee..73c4668ff8 100644 --- a/doc/opencv.bib +++ b/doc/opencv.bib @@ -346,7 +346,8 @@ year = {2003}, pages = {363--370}, publisher = {Springer}, - url = {https://arxiv.org/pdf/1808.01752} + url = {https://doi.org/10.1007/3-540-45103-X_50}, + doi = {10.1007/3-540-45103-X_50} } @inproceedings{Farsiu03, author = {Farsiu, Sina and Robinson, Dirk and Elad, Michael and Milanfar, Peyman}, From 85c0c8c7ed9c94911d1afb0d5a46c4fd83e83b9f Mon Sep 17 00:00:00 2001 From: Liubov Batanina Date: Fri, 19 Jun 2020 14:34:13 +0300 Subject: [PATCH 2/7] Disabling dafault NMS in yolo layer --- modules/dnn/src/darknet/darknet_io.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/dnn/src/darknet/darknet_io.cpp b/modules/dnn/src/darknet/darknet_io.cpp index 699b7447ef..664a1d617b 100644 --- a/modules/dnn/src/darknet/darknet_io.cpp +++ b/modules/dnn/src/darknet/darknet_io.cpp @@ -797,7 +797,7 @@ namespace cv { int classes = getParam(layer_params, "classes", -1); int num_of_anchors = getParam(layer_params, "num", -1); float thresh = getParam(layer_params, "thresh", 0.2); - float nms_threshold = getParam(layer_params, "nms_threshold", 0.4); + float nms_threshold = getParam(layer_params, "nms_threshold", 0.0); float scale_x_y = getParam(layer_params, "scale_x_y", 1.0); std::string anchors_values = getParam(layer_params, "anchors", std::string()); From 52844614c466a37f64347aca0698157e9bb2e41e Mon Sep 17 00:00:00 2001 From: Tomoaki Teshima Date: Fri, 19 Jun 2020 20:46:18 +0900 Subject: [PATCH 3/7] add Ampere CC * Ampere has CC 8.0 * Arm64 server support has been added in CUDA 11 (only V100 for now) --- cmake/OpenCVDetectCUDA.cmake | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/cmake/OpenCVDetectCUDA.cmake b/cmake/OpenCVDetectCUDA.cmake index a0fa19224b..b63a55c974 100644 --- a/cmake/OpenCVDetectCUDA.cmake +++ b/cmake/OpenCVDetectCUDA.cmake @@ -72,13 +72,14 @@ if(CUDA_FOUND) message(STATUS "CUDA detected: " ${CUDA_VERSION}) - set(_generations "Fermi" "Kepler" "Maxwell" "Pascal" "Volta" "Turing") + set(_generations "Fermi" "Kepler" "Maxwell" "Pascal" "Volta" "Turing" "Ampere") set(_arch_fermi "2.0") set(_arch_kepler "3.0;3.5;3.7") set(_arch_maxwell "5.0;5.2") set(_arch_pascal "6.0;6.1") set(_arch_volta "7.0") set(_arch_turing "7.5") + set(_arch_ampere "8.0") if(NOT CMAKE_CROSSCOMPILING) list(APPEND _generations "Auto") endif() @@ -141,6 +142,8 @@ if(CUDA_FOUND) set(__cuda_arch_bin ${_arch_volta}) elseif(CUDA_GENERATION STREQUAL "Turing") set(__cuda_arch_bin ${_arch_turing}) + elseif(CUDA_GENERATION STREQUAL "Ampere") + set(__cuda_arch_bin ${_arch_ampere}) elseif(CUDA_GENERATION STREQUAL "Auto") ocv_detect_native_cuda_arch(_nvcc_res _nvcc_out) if(NOT _nvcc_res EQUAL 0) @@ -158,7 +161,8 @@ if(CUDA_FOUND) ocv_detect_native_cuda_arch(_nvcc_res _nvcc_out) if(NOT _nvcc_res EQUAL 0) message(STATUS "Automatic detection of CUDA generation failed. Going to build for all known architectures.") - set(__cuda_arch_bin "5.3 6.2 7.2") + # TX1 (5.3) TX2 (6.2) Xavier (7.2) V100 (7.0) + set(__cuda_arch_bin "5.3 6.2 7.2 7.0") else() set(__cuda_arch_bin "${_nvcc_out}") endif() @@ -171,6 +175,7 @@ if(CUDA_FOUND) ${_arch_pascal} ${_arch_volta} ${_arch_turing} + ${_arch_ampere} ) endif() endif() From 95ac650af657b9655352e5a42891c0de86b0d609 Mon Sep 17 00:00:00 2001 From: Tomoaki Teshima Date: Sun, 21 Jun 2020 07:20:47 +0900 Subject: [PATCH 4/7] make the fail safe path actually safe * use only supported CC in the list * workaround of #17526 --- cmake/OpenCVDetectCUDA.cmake | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/cmake/OpenCVDetectCUDA.cmake b/cmake/OpenCVDetectCUDA.cmake index b63a55c974..a32977e260 100644 --- a/cmake/OpenCVDetectCUDA.cmake +++ b/cmake/OpenCVDetectCUDA.cmake @@ -162,7 +162,12 @@ if(CUDA_FOUND) if(NOT _nvcc_res EQUAL 0) message(STATUS "Automatic detection of CUDA generation failed. Going to build for all known architectures.") # TX1 (5.3) TX2 (6.2) Xavier (7.2) V100 (7.0) - set(__cuda_arch_bin "5.3 6.2 7.2 7.0") + ocv_filter_available_architecture(__cuda_arch_bin + 5.3 + 6.2 + 7.2 + 7.0 + ) else() set(__cuda_arch_bin "${_nvcc_out}") endif() From 1491934d17e582378272dfdbdee00dc0ea5faa86 Mon Sep 17 00:00:00 2001 From: Dmitry Kurtaev Date: Mon, 22 Jun 2020 23:22:21 +0300 Subject: [PATCH 5/7] Optimize Mish for CPU backend --- modules/dnn/src/layers/elementwise_layers.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/modules/dnn/src/layers/elementwise_layers.cpp b/modules/dnn/src/layers/elementwise_layers.cpp index 776053e2b0..1bd8abef87 100644 --- a/modules/dnn/src/layers/elementwise_layers.cpp +++ b/modules/dnn/src/layers/elementwise_layers.cpp @@ -667,8 +667,11 @@ struct MishFunctor : public BaseFunctor { for( int i = 0; i < len; i++ ) { + // Use fast approximation introduced in https://github.com/opencv/opencv/pull/17200 float x = srcptr[i]; - dstptr[i] = x * tanh(log(1.0f + exp(x))); + float eX = exp(std::min(x, 20.f)); + float n = (eX + 2) * eX; + dstptr[i] = (x * n) / (n + 2); } } } From 8e3f5fb209f4040a7454d0352fa1c4b9bc640055 Mon Sep 17 00:00:00 2001 From: Dmitry Kurtaev Date: Mon, 22 Jun 2020 21:35:52 +0300 Subject: [PATCH 6/7] Remove deprecated Inference Engine CPU extensions --- modules/dnn/src/ie_ngraph.cpp | 67 +++++++++++++++++++++++++++++++---- 1 file changed, 60 insertions(+), 7 deletions(-) diff --git a/modules/dnn/src/ie_ngraph.cpp b/modules/dnn/src/ie_ngraph.cpp index 7cac0c3593..f02ef45ef1 100644 --- a/modules/dnn/src/ie_ngraph.cpp +++ b/modules/dnn/src/ie_ngraph.cpp @@ -128,7 +128,6 @@ public: return true; } -private: std::map params; }; @@ -136,15 +135,28 @@ private: class InfEngineNgraphCustomLayer : public InferenceEngine::ILayerExecImpl { public: +#if INF_ENGINE_VER_MAJOR_GE(INF_ENGINE_RELEASE_2020_2) + explicit InfEngineNgraphCustomLayer(const std::shared_ptr& _node) + { + node = std::dynamic_pointer_cast(_node); + CV_Assert(node); + std::string implStr = node->params["impl"]; + std::istringstream iss(implStr); +#else explicit InfEngineNgraphCustomLayer(const InferenceEngine::CNNLayer& layer) : cnnLayer(layer) { std::istringstream iss(layer.GetParamAsString("impl")); +#endif size_t ptr; iss >> ptr; cvLayer = (Layer*)ptr; std::vector > shapes; +#if INF_ENGINE_VER_MAJOR_GE(INF_ENGINE_RELEASE_2020_2) + strToShapes(node->params["internals"], shapes); +#else strToShapes(layer.GetParamAsString("internals"), shapes); +#endif internals.resize(shapes.size()); for (int i = 0; i < shapes.size(); ++i) internals[i].create(std::vector(shapes[i].begin(), shapes[i].end()), CV_32F); @@ -180,6 +192,29 @@ public: { std::vector inDataConfig; std::vector outDataConfig; +#if INF_ENGINE_VER_MAJOR_GE(INF_ENGINE_RELEASE_2020_2) + InferenceEngine::SizeVector order; + size_t offset = std::numeric_limits::max(); + for (int i = 0; i < node->get_input_size(); ++i) + { + InferenceEngine::DataConfig conf; + auto shape = node->input_value(i).get_shape(); + order.resize(shape.size()); + std::iota(order.begin(), order.end(), 0); + conf.desc = InferenceEngine::TensorDesc(InferenceEngine::Precision::FP32, shape, {shape, order, offset}); + inDataConfig.push_back(conf); + } + + for (int i = 0; i < node->get_output_size(); ++i) + { + InferenceEngine::DataConfig conf; + auto shape = node->output(i).get_shape(); + order.resize(shape.size()); + std::iota(order.begin(), order.end(), 0); + conf.desc = InferenceEngine::TensorDesc(InferenceEngine::Precision::FP32, shape, {shape, order, offset}); + outDataConfig.push_back(conf); + } +#else for (auto& it : cnnLayer.insData) { InferenceEngine::DataConfig conf; @@ -193,6 +228,7 @@ public: conf.desc = it->getTensorDesc(); outDataConfig.push_back(conf); } +#endif InferenceEngine::LayerConfig layerConfig; layerConfig.inConfs = inDataConfig; @@ -209,12 +245,16 @@ public: } private: +#if INF_ENGINE_VER_MAJOR_GE(INF_ENGINE_RELEASE_2020_2) + std::shared_ptr node; +#else InferenceEngine::CNNLayer cnnLayer; +#endif dnn::Layer* cvLayer; std::vector internals; }; - +#if INF_ENGINE_VER_MAJOR_LT(INF_ENGINE_RELEASE_2020_2) class InfEngineNgraphCustomLayerFactory : public InferenceEngine::ILayerImplFactory { public: explicit InfEngineNgraphCustomLayerFactory(const InferenceEngine::CNNLayer* layer) : cnnLayer(*layer) @@ -233,17 +273,29 @@ public: private: InferenceEngine::CNNLayer cnnLayer; }; +#endif class InfEngineNgraphExtension : public InferenceEngine::IExtension { public: -#if INF_ENGINE_VER_MAJOR_LT(INF_ENGINE_RELEASE_2020_2) + void Unload() noexcept override {} + void Release() noexcept override { delete this; } + void GetVersion(const InferenceEngine::Version*&) const noexcept override {} + +#if INF_ENGINE_VER_MAJOR_GE(INF_ENGINE_RELEASE_2020_2) + std::vector getImplTypes(const std::shared_ptr& node) override { + return {"CPU"}; + } + + InferenceEngine::ILayerImpl::Ptr getImplementation(const std::shared_ptr& node, const std::string& implType) override { + if (std::dynamic_pointer_cast(node) && implType == "CPU") { + return std::make_shared(node); + } + return nullptr; + } +#else virtual void SetLogCallback(InferenceEngine::IErrorListener&) noexcept {} -#endif - virtual void Unload() noexcept {} - virtual void Release() noexcept {} - virtual void GetVersion(const InferenceEngine::Version*&) const noexcept {} virtual InferenceEngine::StatusCode getPrimitiveTypes(char**&, unsigned int&, InferenceEngine::ResponseDesc*) noexcept @@ -260,6 +312,7 @@ public: factory = new InfEngineNgraphCustomLayerFactory(cnnLayer); return InferenceEngine::StatusCode::OK; } +#endif }; From ad5e70f94e81ce2614365abf57af3964ec2bb33e Mon Sep 17 00:00:00 2001 From: Ilya Lavrenov Date: Mon, 22 Jun 2020 11:45:56 +0300 Subject: [PATCH 7/7] Conditional compilation for network reader origibal commit: 63e92cccf2c38c3c7a041d7968063a9a2445d40c --- modules/dnn/test/test_ie_models.cpp | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/modules/dnn/test/test_ie_models.cpp b/modules/dnn/test/test_ie_models.cpp index 74edf0295e..f6685676f9 100644 --- a/modules/dnn/test/test_ie_models.cpp +++ b/modules/dnn/test/test_ie_models.cpp @@ -136,12 +136,6 @@ void runIE(Target target, const std::string& xmlPath, const std::string& binPath { SCOPED_TRACE("runIE"); - CNNNetReader reader; - reader.ReadNetwork(xmlPath); - reader.ReadWeights(binPath); - - CNNNetwork net = reader.getNetwork(); - std::string device_name; #if defined(INF_ENGINE_RELEASE) && INF_ENGINE_VER_MAJOR_GT(2019010000) @@ -150,6 +144,17 @@ void runIE(Target target, const std::string& xmlPath, const std::string& binPath InferenceEnginePluginPtr enginePtr; InferencePlugin plugin; #endif + +#if defined(INF_ENGINE_RELEASE) && INF_ENGINE_VER_MAJOR_GT(2019030000) + CNNNetwork net = ie.ReadNetwork(xmlPath, binPath); +#else + CNNNetReader reader; + reader.ReadNetwork(xmlPath); + reader.ReadWeights(binPath); + + CNNNetwork net = reader.getNetwork(); +#endif + ExecutableNetwork netExec; InferRequest infRequest;