Skip to content

Commit 524a2ff

Browse files
committed
Merge remote-tracking branch 'upstream/3.4' into merge-3.4
2 parents 6781ca7 + 3f13339 commit 524a2ff

28 files changed

+268
-89
lines changed

CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1617,6 +1617,10 @@ if(ENABLE_CONFIG_VERIFICATION)
16171617
ocv_verify_config()
16181618
endif()
16191619

1620+
if(HAVE_CUDA AND COMMAND CUDA_BUILD_CLEAN_TARGET)
1621+
CUDA_BUILD_CLEAN_TARGET()
1622+
endif()
1623+
16201624
ocv_cmake_hook(POST_FINALIZE)
16211625

16221626
# ----------------------------------------------------------------------------

cmake/OpenCVCompilerOptions.cmake

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,14 +191,16 @@ if(CV_GCC OR CV_CLANG)
191191

192192
# Profiling?
193193
if(ENABLE_PROFILING)
194-
add_extra_compiler_option("-pg -g")
195194
# turn off incompatible options
196195
foreach(flags CMAKE_CXX_FLAGS CMAKE_C_FLAGS CMAKE_CXX_FLAGS_RELEASE CMAKE_C_FLAGS_RELEASE CMAKE_CXX_FLAGS_DEBUG CMAKE_C_FLAGS_DEBUG
197196
OPENCV_EXTRA_FLAGS_RELEASE OPENCV_EXTRA_FLAGS_DEBUG OPENCV_EXTRA_C_FLAGS OPENCV_EXTRA_CXX_FLAGS)
198197
string(REPLACE "-fomit-frame-pointer" "" ${flags} "${${flags}}")
199198
string(REPLACE "-ffunction-sections" "" ${flags} "${${flags}}")
200199
string(REPLACE "-fdata-sections" "" ${flags} "${${flags}}")
201200
endforeach()
201+
# -pg should be placed both in the linker and in the compiler settings
202+
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -pg")
203+
add_extra_compiler_option("-pg -g")
202204
else()
203205
if(MSVC)
204206
# TODO: Clang/C2 is not supported

cmake/OpenCVDetectCUDA.cmake

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -417,6 +417,13 @@ if(HAVE_CUDA)
417417
set(CUDA_cufft_LIBRARY_ABS ${CUDA_cufft_LIBRARY})
418418
ocv_convert_to_lib_name(CUDA_cufft_LIBRARY ${CUDA_cufft_LIBRARY})
419419
endif()
420+
421+
if(CMAKE_GENERATOR MATCHES "Visual Studio"
422+
AND NOT OPENCV_SKIP_CUDA_CMAKE_SUPPRESS_REGENERATION
423+
)
424+
message(WARNING "CUDA with MSVS generator is detected. Disabling CMake re-run checks (CMAKE_SUPPRESS_REGENERATION=ON). You need to run CMake manually if updates are required.")
425+
set(CMAKE_SUPPRESS_REGENERATION ON)
426+
endif()
420427
endif()
421428

422429

cmake/OpenCVFindOpenBLAS.cmake

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
SET(Open_BLAS_INCLUDE_SEARCH_PATHS
4747
$ENV{OpenBLAS_HOME}
4848
$ENV{OpenBLAS_HOME}/include
49+
$ENV{OpenBLAS_HOME}/include/openblas
4950
/opt/OpenBLAS/include
5051
/usr/local/include/openblas
5152
/usr/include/openblas
@@ -103,4 +104,4 @@ MARK_AS_ADVANCED(
103104
OpenBLAS_INCLUDE_DIR
104105
OpenBLAS_LIB
105106
OpenBLAS
106-
)
107+
)

modules/core/include/opencv2/core/cuda_types.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,8 +106,8 @@ namespace cv
106106

107107
size_t step;
108108

109-
__CV_CUDA_HOST_DEVICE__ T* ptr(int y = 0) { return ( T*)( ( char*)DevPtr<T>::data + y * step); }
110-
__CV_CUDA_HOST_DEVICE__ const T* ptr(int y = 0) const { return (const T*)( (const char*)DevPtr<T>::data + y * step); }
109+
__CV_CUDA_HOST_DEVICE__ T* ptr(int y = 0) { return ( T*)( ( char*)(((DevPtr<T>*)this)->data) + y * step); }
110+
__CV_CUDA_HOST_DEVICE__ const T* ptr(int y = 0) const { return (const T*)( (const char*)(((DevPtr<T>*)this)->data) + y * step); }
111111

112112
__CV_CUDA_HOST_DEVICE__ T& operator ()(int y, int x) { return ptr(y)[x]; }
113113
__CV_CUDA_HOST_DEVICE__ const T& operator ()(int y, int x) const { return ptr(y)[x]; }

modules/dnn/perf/perf_net.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,19 @@ PERF_TEST_P_(DNNTestNetwork, YOLOv4)
216216
processNet("dnn/yolov4.weights", "dnn/yolov4.cfg", "", inp);
217217
}
218218

219+
PERF_TEST_P_(DNNTestNetwork, YOLOv4_tiny)
220+
{
221+
if (backend == DNN_BACKEND_HALIDE)
222+
throw SkipTestException("");
223+
if (target == DNN_TARGET_MYRIAD)
224+
throw SkipTestException("");
225+
Mat sample = imread(findDataFile("dnn/dog416.png"));
226+
cvtColor(sample, sample, COLOR_BGR2RGB);
227+
Mat inp;
228+
sample.convertTo(inp, CV_32FC3, 1.0f / 255, 0);
229+
processNet("dnn/yolov4-tiny.weights", "dnn/yolov4-tiny.cfg", "", inp);
230+
}
231+
219232
PERF_TEST_P_(DNNTestNetwork, EAST_text_detection)
220233
{
221234
if (backend == DNN_BACKEND_HALIDE)

modules/dnn/src/darknet/darknet_io.cpp

Lines changed: 47 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -363,6 +363,28 @@ namespace cv {
363363
fused_layer_names.push_back(last_layer);
364364
}
365365

366+
void setSlice(int input_index, int split_size, int group_id)
367+
{
368+
int begin[] = {0, split_size * group_id, 0, 0};
369+
cv::dnn::DictValue paramBegin = cv::dnn::DictValue::arrayInt(begin, 4);
370+
371+
int end[] = {-1, begin[1] + split_size, -1, -1};
372+
cv::dnn::DictValue paramEnd = cv::dnn::DictValue::arrayInt(end, 4);
373+
374+
darknet::LayerParameter lp;
375+
lp.layer_name = cv::format("slice_%d", layer_id);
376+
lp.layer_type = "Slice";
377+
lp.layerParams.set("begin", paramBegin);
378+
lp.layerParams.set("end", paramEnd);
379+
380+
lp.bottom_indexes.push_back(fused_layer_names.at(input_index));
381+
net->layers.push_back(lp);
382+
383+
layer_id++;
384+
last_layer = lp.layer_name;
385+
fused_layer_names.push_back(last_layer);
386+
}
387+
366388
void setReorg(int stride)
367389
{
368390
cv::dnn::LayerParams reorg_params;
@@ -717,6 +739,7 @@ namespace cv {
717739
{
718740
std::string bottom_layers = getParam<std::string>(layer_params, "layers", "");
719741
CV_Assert(!bottom_layers.empty());
742+
int groups = getParam<int>(layer_params, "groups", 1);
720743
std::vector<int> layers_vec = getNumbers<int>(bottom_layers);
721744

722745
tensor_shape[0] = 0;
@@ -725,10 +748,31 @@ namespace cv {
725748
tensor_shape[0] += net->out_channels_vec[layers_vec[k]];
726749
}
727750

728-
if (layers_vec.size() == 1)
729-
setParams.setIdentity(layers_vec.at(0));
751+
if (groups > 1)
752+
{
753+
int group_id = getParam<int>(layer_params, "group_id", 0);
754+
tensor_shape[0] /= groups;
755+
int split_size = tensor_shape[0] / layers_vec.size();
756+
for (size_t k = 0; k < layers_vec.size(); ++k)
757+
setParams.setSlice(layers_vec[k], split_size, group_id);
758+
759+
if (layers_vec.size() > 1)
760+
{
761+
// layer ids in layers_vec - inputs of Slice layers
762+
// after adding offset to layers_vec: layer ids - ouputs of Slice layers
763+
for (size_t k = 0; k < layers_vec.size(); ++k)
764+
layers_vec[k] += layers_vec.size();
765+
766+
setParams.setConcat(layers_vec.size(), layers_vec.data());
767+
}
768+
}
730769
else
731-
setParams.setConcat(layers_vec.size(), layers_vec.data());
770+
{
771+
if (layers_vec.size() == 1)
772+
setParams.setIdentity(layers_vec.at(0));
773+
else
774+
setParams.setConcat(layers_vec.size(), layers_vec.data());
775+
}
732776
}
733777
else if (layer_type == "dropout" || layer_type == "cost")
734778
{

modules/dnn/src/layers/reorg_layer.cpp

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,15 @@
4141
//M*/
4242

4343
#include "../precomp.hpp"
44-
#include "../op_cuda.hpp"
45-
#include "../op_inf_engine.hpp"
4644

45+
#include <opencv2/dnn/shape_utils.hpp>
46+
#include <opencv2/dnn/all_layers.hpp>
47+
48+
#ifdef HAVE_OPENCL
49+
#include "opencl_kernels_dnn.hpp"
50+
#endif
51+
52+
#include "../op_inf_engine.hpp"
4753
#ifdef HAVE_DNN_NGRAPH
4854
#include "../ie_ngraph.hpp"
4955
#if INF_ENGINE_VER_MAJOR_GT(INF_ENGINE_RELEASE_2020_4)
@@ -53,13 +59,7 @@
5359
#endif
5460
#endif
5561

56-
#include <opencv2/dnn/shape_utils.hpp>
57-
#include <opencv2/dnn/all_layers.hpp>
58-
59-
#ifdef HAVE_OPENCL
60-
#include "opencl_kernels_dnn.hpp"
61-
#endif
62-
62+
#include "../op_cuda.hpp"
6363
#ifdef HAVE_CUDA
6464
#include "../cuda4dnn/primitives/reorg.hpp"
6565
using namespace cv::dnn::cuda4dnn;

modules/dnn/src/layers/slice_layer.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,10 @@ class SliceLayerImpl : public SliceLayer
209209
#ifdef HAVE_OPENCL
210210
bool forward_ocl(InputArrayOfArrays inputs_, OutputArrayOfArrays outputs_, OutputArrayOfArrays internals_)
211211
{
212+
#if 1
213+
// TODO fix that (brokes YOLOv4-tiny)
214+
return false;
215+
#else
212216
std::vector<UMat> inputs;
213217
std::vector<UMat> outputs;
214218
@@ -251,7 +255,8 @@ class SliceLayerImpl : public SliceLayer
251255
}
252256
253257
return true;
254-
}
258+
#endif
259+
}
255260
#endif
256261

257262
void forward(InputArrayOfArrays inputs_arr, OutputArrayOfArrays outputs_arr, OutputArrayOfArrays internals_arr) CV_OVERRIDE

modules/dnn/test/test_common.impl.hpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,9 +100,12 @@ void normAssertDetections(
100100
const char *comment /*= ""*/, double confThreshold /*= 0.0*/,
101101
double scores_diff /*= 1e-5*/, double boxes_iou_diff /*= 1e-4*/)
102102
{
103+
ASSERT_FALSE(testClassIds.empty()) << "No detections";
103104
std::vector<bool> matchedRefBoxes(refBoxes.size(), false);
105+
std::vector<double> refBoxesIoUDiff(refBoxes.size(), 1.0);
104106
for (int i = 0; i < testBoxes.size(); ++i)
105107
{
108+
//cout << "Test[i=" << i << "]: score=" << testScores[i] << " id=" << testClassIds[i] << " box " << testBoxes[i] << endl;
106109
double testScore = testScores[i];
107110
if (testScore < confThreshold)
108111
continue;
@@ -119,6 +122,7 @@ void normAssertDetections(
119122
double interArea = (testBox & refBoxes[j]).area();
120123
double iou = interArea / (testBox.area() + refBoxes[j].area() - interArea);
121124
topIoU = std::max(topIoU, iou);
125+
refBoxesIoUDiff[j] = std::min(refBoxesIoUDiff[j], 1.0f - iou);
122126
if (1.0 - iou < boxes_iou_diff)
123127
{
124128
matched = true;
@@ -141,7 +145,9 @@ void normAssertDetections(
141145
if (!matchedRefBoxes[i] && refScores[i] > confThreshold)
142146
{
143147
std::cout << cv::format("Unmatched reference: class %d score %f box ",
144-
refClassIds[i], refScores[i]) << refBoxes[i] << std::endl;
148+
refClassIds[i], refScores[i]) << refBoxes[i]
149+
<< " IoU diff: " << refBoxesIoUDiff[i]
150+
<< std::endl;
145151
EXPECT_LE(refScores[i], confThreshold) << comment;
146152
}
147153
}

0 commit comments

Comments
 (0)