From ef7185ce43d3ace32443c6ea903320d3a333576d Mon Sep 17 00:00:00 2001
From: Pierre-Emmanuel Viel
Date: Wed, 1 Jul 2020 00:43:42 +0200
Subject: [PATCH 01/16] Fix genericity of computeNodeStatistics that couldn't
compute stats properly on sub-nodes
---
modules/flann/include/opencv2/flann/kmeans_index.h | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/modules/flann/include/opencv2/flann/kmeans_index.h b/modules/flann/include/opencv2/flann/kmeans_index.h
index f743d75224..695ef6e8b1 100644
--- a/modules/flann/include/opencv2/flann/kmeans_index.h
+++ b/modules/flann/include/opencv2/flann/kmeans_index.h
@@ -663,7 +663,7 @@ private:
memset(mean,0,veclen_*sizeof(DistanceType));
- for (size_t i=0; i<(size_t)indices_length; ++i) {
+ for (int i=0; i(), veclen_);
}
for (size_t j=0; j(), veclen_);
DistanceType tmp = 0;
From 93a6be836cba1dff3ebd3c7f1b3d3afbbafe1a47 Mon Sep 17 00:00:00 2001
From: Pierre-Emmanuel Viel
Date: Wed, 1 Jul 2020 18:15:01 +0200
Subject: [PATCH 02/16] Remove duplicate line
---
.../flann/include/opencv2/flann/hierarchical_clustering_index.h | 1 -
1 file changed, 1 deletion(-)
diff --git a/modules/flann/include/opencv2/flann/hierarchical_clustering_index.h b/modules/flann/include/opencv2/flann/hierarchical_clustering_index.h
index 20304ede73..d830bc6a00 100644
--- a/modules/flann/include/opencv2/flann/hierarchical_clustering_index.h
+++ b/modules/flann/include/opencv2/flann/hierarchical_clustering_index.h
@@ -386,7 +386,6 @@ public:
throw FLANNException("Unknown algorithm for choosing initial centers.");
}
- trees_ = get_param(params,"trees",4);
root = new NodePtr[trees_];
indices = new int*[trees_];
From 482cacd420ada7c0bd0fe46a500b62cb76439955 Mon Sep 17 00:00:00 2001
From: Pierre-Emmanuel Viel
Date: Wed, 1 Jul 2020 18:27:07 +0200
Subject: [PATCH 03/16] Mix of 32 and 64bits vector types prevents
vectorisation for distance computation. Argument "a" is of type ElementType*
that is either int* or float*, while b was double*. Mixing types prevents the
possibility to use SSE or AVX instructions. On implementation without SIMD
instructions, this doesn't show any impact on performance.
---
.../include/opencv2/flann/kmeans_index.h | 22 +++++++++----------
1 file changed, 11 insertions(+), 11 deletions(-)
diff --git a/modules/flann/include/opencv2/flann/kmeans_index.h b/modules/flann/include/opencv2/flann/kmeans_index.h
index f743d75224..b556b4ad8a 100644
--- a/modules/flann/include/opencv2/flann/kmeans_index.h
+++ b/modules/flann/include/opencv2/flann/kmeans_index.h
@@ -726,15 +726,6 @@ private:
}
- cv::AutoBuffer dcenters_buf(branching*veclen_);
- Matrix dcenters(dcenters_buf.data(), branching, veclen_);
- for (int i=0; i radiuses(branching);
cv::AutoBuffer count_buf(branching);
int* count = count_buf.data();
@@ -748,10 +739,10 @@ private:
int* belongs_to = belongs_to_buf.data();
for (int i=0; inew_sq_dist) {
belongs_to[i] = j;
sq_dist = new_sq_dist;
@@ -763,6 +754,15 @@ private:
count[belongs_to[i]]++;
}
+ cv::AutoBuffer dcenters_buf(branching*veclen_);
+ Matrix dcenters(dcenters_buf.data(), branching, veclen_);
+ for (int i=0; i
Date: Wed, 1 Jul 2020 18:52:05 +0200
Subject: [PATCH 04/16] Precompute the divisor to ensure that no kind of
compiler would process it on the fly at each call.
---
modules/flann/include/opencv2/flann/dist.h | 11 +++++++++--
1 file changed, 9 insertions(+), 2 deletions(-)
diff --git a/modules/flann/include/opencv2/flann/dist.h b/modules/flann/include/opencv2/flann/dist.h
index b092b531a1..4cf32d5987 100644
--- a/modules/flann/include/opencv2/flann/dist.h
+++ b/modules/flann/include/opencv2/flann/dist.h
@@ -506,7 +506,7 @@ struct Hamming2
const uint64_t* pa = reinterpret_cast(a);
const uint64_t* pb = reinterpret_cast(b);
ResultType result = 0;
- size /= (sizeof(uint64_t)/sizeof(unsigned char));
+ size /= long_word_size_;
for(size_t i = 0; i < size; ++i ) {
result += popcnt64(*pa ^ *pb);
++pa;
@@ -516,7 +516,7 @@ struct Hamming2
const uint32_t* pa = reinterpret_cast(a);
const uint32_t* pb = reinterpret_cast(b);
ResultType result = 0;
- size /= (sizeof(uint32_t)/sizeof(unsigned char));
+ size /= long_word_size_;
for(size_t i = 0; i < size; ++i ) {
result += popcnt32(*pa ^ *pb);
++pa;
@@ -525,6 +525,13 @@ struct Hamming2
#endif
return result;
}
+
+private:
+#ifdef FLANN_PLATFORM_64_BIT
+ static const size_t long_word_size_ = sizeof(uint64_t)/sizeof(unsigned char);
+#else
+ static const size_t long_word_size_ = sizeof(uint32_t)/sizeof(unsigned char);
+#endif
};
From 6a045fd67870af15d127cc4e78df0bc7f148318f Mon Sep 17 00:00:00 2001
From: Pierre-Emmanuel Viel
Date: Wed, 1 Jul 2020 18:20:02 +0200
Subject: [PATCH 05/16] Fix arguments list in loadindex for histogram
intersection
---
modules/flann/src/miniflann.cpp | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/modules/flann/src/miniflann.cpp b/modules/flann/src/miniflann.cpp
index 98baaa6a9a..1f698e7871 100644
--- a/modules/flann/src/miniflann.cpp
+++ b/modules/flann/src/miniflann.cpp
@@ -801,7 +801,7 @@ bool Index::load(InputArray _data, const String& filename)
loadIndex< ::cvflann::MaxDistance >(this, index, data, fin);
break;
case FLANN_DIST_HIST_INTERSECT:
- loadIndex< ::cvflann::HistIntersectionDistance >(index, data, fin);
+ loadIndex< ::cvflann::HistIntersectionDistance >(this, index, data, fin);
break;
case FLANN_DIST_HELLINGER:
loadIndex< ::cvflann::HellingerDistance >(this, index, data, fin);
From cb3a098b251882a8d42fe5849cd7cfb0a909ed46 Mon Sep 17 00:00:00 2001
From: Heritier Kinke
Date: Thu, 2 Jul 2020 03:27:34 +0200
Subject: [PATCH 06/16] forget to look in sub folder of include/openblas
---
cmake/OpenCVFindOpenBLAS.cmake | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/cmake/OpenCVFindOpenBLAS.cmake b/cmake/OpenCVFindOpenBLAS.cmake
index ae2daaa194..6cb486d95d 100644
--- a/cmake/OpenCVFindOpenBLAS.cmake
+++ b/cmake/OpenCVFindOpenBLAS.cmake
@@ -46,6 +46,7 @@
SET(Open_BLAS_INCLUDE_SEARCH_PATHS
$ENV{OpenBLAS_HOME}
$ENV{OpenBLAS_HOME}/include
+ $ENV{OpenBLAS_HOME}/include/openblas
/opt/OpenBLAS/include
/usr/local/include/openblas
/usr/include/openblas
@@ -103,4 +104,4 @@ MARK_AS_ADVANCED(
OpenBLAS_INCLUDE_DIR
OpenBLAS_LIB
OpenBLAS
-)
\ No newline at end of file
+)
From 00e1bc49c8c38c8d57deae4eb0841dea2d05558b Mon Sep 17 00:00:00 2001
From: Ken Shirriff
Date: Thu, 2 Jul 2020 03:58:53 -0700
Subject: [PATCH 07/16] Merge pull request #17708 from shirriff:patch-1
Clarify component statistics documentation
* Change ConnectedComponentsTypes documentation
Change from "algorithm output formats" to "statistics" because it specifies types of statistics, not formats.
* Documentation: clarify component statistics
Explain that ConnectedComponentTypes selects a statistic.
---
modules/imgproc/include/opencv2/imgproc.hpp | 14 +++++++-------
1 file changed, 7 insertions(+), 7 deletions(-)
diff --git a/modules/imgproc/include/opencv2/imgproc.hpp b/modules/imgproc/include/opencv2/imgproc.hpp
index f6b5339194..91c1ec52fc 100644
--- a/modules/imgproc/include/opencv2/imgproc.hpp
+++ b/modules/imgproc/include/opencv2/imgproc.hpp
@@ -387,7 +387,7 @@ enum FloodFillFlags {
//! @addtogroup imgproc_shape
//! @{
-//! connected components algorithm output formats
+//! connected components statistics
enum ConnectedComponentsTypes {
CC_STAT_LEFT = 0, //!< The leftmost (x) coordinate which is the inclusive start of the bounding
//!< box in the horizontal direction.
@@ -3881,9 +3881,9 @@ parallel framework is enabled and if the rows of the image are at least twice th
@param image the 8-bit single-channel image to be labeled
@param labels destination labeled image
-@param stats statistics output for each label, including the background label, see below for
-available statistics. Statistics are accessed via stats(label, COLUMN) where COLUMN is one of
-#ConnectedComponentsTypes. The data type is CV_32S.
+@param stats statistics output for each label, including the background label.
+Statistics are accessed via stats(label, COLUMN) where COLUMN is one of
+#ConnectedComponentsTypes, selecting the statistic. The data type is CV_32S.
@param centroids centroid output for each label, including the background label. Centroids are
accessed via centroids(label, 0) for x and centroids(label, 1) for y. The data type CV_64F.
@param connectivity 8 or 4 for 8-way or 4-way connectivity respectively
@@ -3897,9 +3897,9 @@ CV_EXPORTS_AS(connectedComponentsWithStatsWithAlgorithm) int connectedComponents
/** @overload
@param image the 8-bit single-channel image to be labeled
@param labels destination labeled image
-@param stats statistics output for each label, including the background label, see below for
-available statistics. Statistics are accessed via stats(label, COLUMN) where COLUMN is one of
-#ConnectedComponentsTypes. The data type is CV_32S.
+@param stats statistics output for each label, including the background label.
+Statistics are accessed via stats(label, COLUMN) where COLUMN is one of
+#ConnectedComponentsTypes, selecting the statistic. The data type is CV_32S.
@param centroids centroid output for each label, including the background label. Centroids are
accessed via centroids(label, 0) for x and centroids(label, 1) for y. The data type CV_64F.
@param connectivity 8 or 4 for 8-way or 4-way connectivity respectively
From 65dbbf712dbde71d9a7e77f0049e0162a0d99bd0 Mon Sep 17 00:00:00 2001
From: Liubov Batanina
Date: Fri, 3 Jul 2020 21:07:08 +0300
Subject: [PATCH 08/16] Merge pull request #17733 from l-bat:tiny_yolov4
* Supported yolov4-tiny
* Added comments
---
modules/dnn/src/darknet/darknet_io.cpp | 50 ++++++++++++++++++++--
modules/dnn/test/test_darknet_importer.cpp | 6 +++
2 files changed, 53 insertions(+), 3 deletions(-)
diff --git a/modules/dnn/src/darknet/darknet_io.cpp b/modules/dnn/src/darknet/darknet_io.cpp
index 664a1d617b..f6504b96c7 100644
--- a/modules/dnn/src/darknet/darknet_io.cpp
+++ b/modules/dnn/src/darknet/darknet_io.cpp
@@ -363,6 +363,28 @@ namespace cv {
fused_layer_names.push_back(last_layer);
}
+ void setSlice(int input_index, int split_size, int group_id)
+ {
+ int begin[] = {0, split_size * group_id, 0, 0};
+ cv::dnn::DictValue paramBegin = cv::dnn::DictValue::arrayInt(begin, 4);
+
+ int end[] = {-1, begin[1] + split_size, -1, -1};
+ cv::dnn::DictValue paramEnd = cv::dnn::DictValue::arrayInt(end, 4);
+
+ darknet::LayerParameter lp;
+ lp.layer_name = cv::format("slice_%d", layer_id);
+ lp.layer_type = "Slice";
+ lp.layerParams.set("begin", paramBegin);
+ lp.layerParams.set("end", paramEnd);
+
+ lp.bottom_indexes.push_back(fused_layer_names.at(input_index));
+ net->layers.push_back(lp);
+
+ layer_id++;
+ last_layer = lp.layer_name;
+ fused_layer_names.push_back(last_layer);
+ }
+
void setReorg(int stride)
{
cv::dnn::LayerParams reorg_params;
@@ -717,6 +739,7 @@ namespace cv {
{
std::string bottom_layers = getParam(layer_params, "layers", "");
CV_Assert(!bottom_layers.empty());
+ int groups = getParam(layer_params, "groups", 1);
std::vector layers_vec = getNumbers(bottom_layers);
tensor_shape[0] = 0;
@@ -725,10 +748,31 @@ namespace cv {
tensor_shape[0] += net->out_channels_vec[layers_vec[k]];
}
- if (layers_vec.size() == 1)
- setParams.setIdentity(layers_vec.at(0));
+ if (groups > 1)
+ {
+ int group_id = getParam(layer_params, "group_id", 0);
+ tensor_shape[0] /= groups;
+ int split_size = tensor_shape[0] / layers_vec.size();
+ for (size_t k = 0; k < layers_vec.size(); ++k)
+ setParams.setSlice(layers_vec[k], split_size, group_id);
+
+ if (layers_vec.size() > 1)
+ {
+ // layer ids in layers_vec - inputs of Slice layers
+ // after adding offset to layers_vec: layer ids - ouputs of Slice layers
+ for (size_t k = 0; k < layers_vec.size(); ++k)
+ layers_vec[k] += layers_vec.size();
+
+ setParams.setConcat(layers_vec.size(), layers_vec.data());
+ }
+ }
else
- setParams.setConcat(layers_vec.size(), layers_vec.data());
+ {
+ if (layers_vec.size() == 1)
+ setParams.setIdentity(layers_vec.at(0));
+ else
+ setParams.setConcat(layers_vec.size(), layers_vec.data());
+ }
}
else if (layer_type == "dropout" || layer_type == "cost")
{
diff --git a/modules/dnn/test/test_darknet_importer.cpp b/modules/dnn/test/test_darknet_importer.cpp
index 607761ed2f..fcc9088b00 100644
--- a/modules/dnn/test/test_darknet_importer.cpp
+++ b/modules/dnn/test/test_darknet_importer.cpp
@@ -627,6 +627,12 @@ TEST_P(Test_Darknet_layers, reorg)
testDarknetLayer("reorg");
}
+TEST_P(Test_Darknet_layers, route)
+{
+ testDarknetLayer("route");
+ testDarknetLayer("route_multi");
+}
+
TEST_P(Test_Darknet_layers, maxpool)
{
#if defined(INF_ENGINE_RELEASE) && INF_ENGINE_VER_MAJOR_GE(2020020000)
From 56b5a7d9772c75795d0b2d644c9ddcbcc42ef03d Mon Sep 17 00:00:00 2001
From: Alexander Alekhin
Date: Fri, 3 Jul 2020 19:31:41 +0000
Subject: [PATCH 09/16] cmake: fix ENABLE_PROFILING
---
cmake/OpenCVCompilerOptions.cmake | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/cmake/OpenCVCompilerOptions.cmake b/cmake/OpenCVCompilerOptions.cmake
index 476156f256..9ac671dd34 100644
--- a/cmake/OpenCVCompilerOptions.cmake
+++ b/cmake/OpenCVCompilerOptions.cmake
@@ -189,7 +189,6 @@ if(CV_GCC OR CV_CLANG)
# Profiling?
if(ENABLE_PROFILING)
- add_extra_compiler_option("-pg -g")
# turn off incompatible options
foreach(flags CMAKE_CXX_FLAGS CMAKE_C_FLAGS CMAKE_CXX_FLAGS_RELEASE CMAKE_C_FLAGS_RELEASE CMAKE_CXX_FLAGS_DEBUG CMAKE_C_FLAGS_DEBUG
OPENCV_EXTRA_FLAGS_RELEASE OPENCV_EXTRA_FLAGS_DEBUG OPENCV_EXTRA_C_FLAGS OPENCV_EXTRA_CXX_FLAGS)
@@ -197,6 +196,9 @@ if(CV_GCC OR CV_CLANG)
string(REPLACE "-ffunction-sections" "" ${flags} "${${flags}}")
string(REPLACE "-fdata-sections" "" ${flags} "${${flags}}")
endforeach()
+ # -pg should be placed both in the linker and in the compiler settings
+ set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -pg")
+ add_extra_compiler_option("-pg -g")
else()
if(MSVC)
# TODO: Clang/C2 is not supported
From 65f87b114b545b73a43232c15e0bd345406c4896 Mon Sep 17 00:00:00 2001
From: pemmanuelviel
Date: Sat, 4 Jul 2020 19:15:44 +0200
Subject: [PATCH 10/16] Merge pull request #17722 from
pemmanuelviel:pev--replace-asserts
* Clean: replace C style asserts by CV_Assert and CV_DbgAssert
* Try fixing warning on Windows compilation
* Another way trying to fix warnings on Win
* Fixing warnings with some compilers:
Some compilers warn on systematic exit preventing to execute the code that follows.
This is why assert(0) that exits only in debug was working, but not CV_Assert or CV_Error
that exit both in release and debug, even if with different behavior.
In addition, other compilers complain when return 0 is removed from getKey(),
even if before we have a statement leading to systematic exit.
* Disable "unreachable code" warnings for Win compilers so we can use proper CV_Error
---
.../include/opencv2/flann/autotuned_index.h | 2 +-
.../include/opencv2/flann/flann_base.hpp | 1 -
.../flann/hierarchical_clustering_index.h | 9 ++++-----
.../include/opencv2/flann/index_testing.h | 1 -
.../include/opencv2/flann/kdtree_index.h | 5 ++---
.../opencv2/flann/kdtree_single_index.h | 11 +++++-----
.../include/opencv2/flann/kmeans_index.h | 9 ++++-----
.../flann/include/opencv2/flann/lsh_index.h | 20 +++++++++++++------
.../flann/include/opencv2/flann/lsh_table.h | 16 +++++++++++----
.../flann/include/opencv2/flann/nn_index.h | 10 +++++-----
.../include/opencv2/flann/simplex_downhill.h | 2 +-
11 files changed, 48 insertions(+), 38 deletions(-)
diff --git a/modules/flann/include/opencv2/flann/autotuned_index.h b/modules/flann/include/opencv2/flann/autotuned_index.h
index eb4554f077..54a60a73d6 100644
--- a/modules/flann/include/opencv2/flann/autotuned_index.h
+++ b/modules/flann/include/opencv2/flann/autotuned_index.h
@@ -497,7 +497,7 @@ private:
const int nn = 1;
const size_t SAMPLE_COUNT = 1000;
- assert(bestIndex_ != NULL); // must have a valid index
+ CV_Assert(bestIndex_ != NULL && "Requires a valid index"); // must have a valid index
float speedup = 0;
diff --git a/modules/flann/include/opencv2/flann/flann_base.hpp b/modules/flann/include/opencv2/flann/flann_base.hpp
index 83606d232f..641fdb01e2 100644
--- a/modules/flann/include/opencv2/flann/flann_base.hpp
+++ b/modules/flann/include/opencv2/flann/flann_base.hpp
@@ -34,7 +34,6 @@
//! @cond IGNORED
#include
-#include
#include
#include "general.h"
diff --git a/modules/flann/include/opencv2/flann/hierarchical_clustering_index.h b/modules/flann/include/opencv2/flann/hierarchical_clustering_index.h
index d830bc6a00..a52166d3c4 100644
--- a/modules/flann/include/opencv2/flann/hierarchical_clustering_index.h
+++ b/modules/flann/include/opencv2/flann/hierarchical_clustering_index.h
@@ -35,7 +35,6 @@
#include
#include