From 206b546e5a61c456c731747a447d4891e3d9fbcb Mon Sep 17 00:00:00 2001 From: gal0is Date: Sat, 15 Jun 2019 23:51:13 +0800 Subject: [PATCH 1/6] tensroflow support maxpoolgrad --- modules/dnn/src/layers/max_unpooling_layer.cpp | 16 +++++++++++----- modules/dnn/src/tensorflow/tf_importer.cpp | 18 ++++++++++++++++++ modules/dnn/test/test_tf_importer.cpp | 7 +++++++ 3 files changed, 36 insertions(+), 5 deletions(-) diff --git a/modules/dnn/src/layers/max_unpooling_layer.cpp b/modules/dnn/src/layers/max_unpooling_layer.cpp index b9c1f2da73..2978509d5c 100644 --- a/modules/dnn/src/layers/max_unpooling_layer.cpp +++ b/modules/dnn/src/layers/max_unpooling_layer.cpp @@ -43,12 +43,18 @@ public: std::vector &outputs, std::vector &internals) const CV_OVERRIDE { - CV_Assert(inputs.size() == 2); + CV_Assert(inputs.size() == 2 || inputs.size() == 3); CV_Assert(total(inputs[0]) == total(inputs[1])); - MatShape outShape = inputs[0]; - outShape[2] = (outShape[2] - 1) * poolStride.height + poolKernel.height - 2 * poolPad.height; - outShape[3] = (outShape[3] - 1) * poolStride.width + poolKernel.width - 2 * poolPad.width; + MatShape outShape; + if (inputs.size() == 2) + { + outShape = inputs[0]; + outShape[2] = (outShape[2] - 1) * poolStride.height + poolKernel.height - 2 * poolPad.height; + outShape[3] = (outShape[3] - 1) * poolStride.width + poolKernel.width - 2 * poolPad.width; + } + else + outShape = inputs[2]; outputs.clear(); outputs.push_back(outShape); @@ -71,7 +77,7 @@ public: inputs_arr.getMatVector(inputs); outputs_arr.getMatVector(outputs); - CV_Assert(inputs.size() == 2); + CV_Assert(inputs.size() == 2 || inputs.size() == 3); Mat& input = inputs[0]; Mat& indices = inputs[1]; diff --git a/modules/dnn/src/tensorflow/tf_importer.cpp b/modules/dnn/src/tensorflow/tf_importer.cpp index 3a5bd34fcb..c38b250c67 100644 --- a/modules/dnn/src/tensorflow/tf_importer.cpp +++ b/modules/dnn/src/tensorflow/tf_importer.cpp @@ -1370,6 +1370,24 @@ void TFImporter::populateNet(Net dstNet) connectToAllBlobs(layer_id, dstNet, parsePin(layer.input(0)), id, layer.input_size()); } + else if (type == "MaxPoolGrad") + { + CV_Assert(layer.input_size() == 3); + + layerParams.set("pool_k_h", 0); + layerParams.set("pool_k_w", 0); + layerParams.set("pool_stride_h", 0); + layerParams.set("pool_stride_w", 0); + layerParams.set("pool_pad_h", 0); + layerParams.set("pool_pad_w", 0); + + int id = dstNet.addLayer(name, "MaxUnpool", layerParams); + layer_id[name] = id; + + connect(layer_id, dstNet, parsePin(layer.input(2)), id, 0); + connect(layer_id, dstNet, parsePin(layer.input(1) + ":1"), id, 1); + connect(layer_id, dstNet, parsePin(layer.input(0)), id, 2); + } else if (type == "Placeholder") { if (!hasLayerAttr(layer, "dtype") || diff --git a/modules/dnn/test/test_tf_importer.cpp b/modules/dnn/test/test_tf_importer.cpp index dd5d871d71..0687c0ba68 100644 --- a/modules/dnn/test/test_tf_importer.cpp +++ b/modules/dnn/test/test_tf_importer.cpp @@ -218,6 +218,13 @@ TEST_P(Test_TensorFlow_layers, pooling) runTensorFlowNet("reduce_mean"); // an average pooling over all spatial dimensions. } +TEST_P(Test_TensorFlow_layers, max_pool_grad) +{ + if (backend == DNN_BACKEND_INFERENCE_ENGINE) + applyTestTag(CV_TEST_TAG_DNN_SKIP_IE); + runTensorFlowNet("max_pool_grad"); +} + // TODO: fix tests and replace to pooling TEST_P(Test_TensorFlow_layers, ave_pool_same) { From ca022fdb4c83acd4f47e92b1d36dafb0882537c6 Mon Sep 17 00:00:00 2001 From: Alexander Alekhin Date: Wed, 3 Jul 2019 18:06:59 +0300 Subject: [PATCH 2/6] 3rdparty(itt): support AARCH64 --- 3rdparty/ittnotify/src/ittnotify/ittnotify_config.h | 8 +++++++- CMakeLists.txt | 5 ++++- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/3rdparty/ittnotify/src/ittnotify/ittnotify_config.h b/3rdparty/ittnotify/src/ittnotify/ittnotify_config.h index ca86ab40e9..d68d0e152e 100644 --- a/3rdparty/ittnotify/src/ittnotify/ittnotify_config.h +++ b/3rdparty/ittnotify/src/ittnotify/ittnotify_config.h @@ -196,6 +196,10 @@ # define ITT_ARCH_PPC64 5 #endif /* ITT_ARCH_PPC64 */ +#ifndef ITT_ARCH_AARCH64 /* 64-bit ARM */ +# define ITT_ARCH_AARCH64 6 +#endif /* ITT_ARCH_AARCH64 */ + #ifndef ITT_ARCH # if defined _M_IX86 || defined __i386__ # define ITT_ARCH ITT_ARCH_IA32 @@ -205,6 +209,8 @@ # define ITT_ARCH ITT_ARCH_IA64 # elif defined _M_ARM || defined __arm__ # define ITT_ARCH ITT_ARCH_ARM +# elif defined __aarch64__ +# define ITT_ARCH ITT_ARCH_AARCH64 # elif defined __powerpc64__ # define ITT_ARCH ITT_ARCH_PPC64 # endif @@ -359,7 +365,7 @@ ITT_INLINE long __TBB_machine_fetchadd4(volatile void* ptr, long addend) : "memory"); return result; } -#elif ITT_ARCH==ITT_ARCH_ARM || ITT_ARCH==ITT_ARCH_PPC64 +#elif ITT_ARCH==ITT_ARCH_ARM || ITT_ARCH==ITT_ARCH_AARCH64 || ITT_ARCH==ITT_ARCH_PPC64 #define __TBB_machine_fetchadd4(addr, val) __sync_fetch_and_add(addr, val) #endif /* ITT_ARCH==ITT_ARCH_IA64 */ #ifndef ITT_SIMPLE_INIT diff --git a/CMakeLists.txt b/CMakeLists.txt index c66e98c8e0..c9a5c42965 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -222,7 +222,10 @@ OCV_OPTION(BUILD_OPENEXR "Build openexr from source" (((WIN3 OCV_OPTION(BUILD_WEBP "Build WebP from source" (((WIN32 OR ANDROID OR APPLE) AND NOT WINRT) OR OPENCV_FORCE_3RDPARTY_BUILD) ) OCV_OPTION(BUILD_TBB "Download and build TBB from source" (ANDROID OR OPENCV_FORCE_3RDPARTY_BUILD) ) OCV_OPTION(BUILD_IPP_IW "Build IPP IW from source" (NOT MINGW OR OPENCV_FORCE_3RDPARTY_BUILD) IF (X86_64 OR X86) AND NOT WINRT ) -OCV_OPTION(BUILD_ITT "Build Intel ITT from source" (NOT MINGW OR OPENCV_FORCE_3RDPARTY_BUILD) IF (X86_64 OR X86) AND NOT WINRT AND NOT APPLE_FRAMEWORK ) +OCV_OPTION(BUILD_ITT "Build Intel ITT from source" + (NOT MINGW OR OPENCV_FORCE_3RDPARTY_BUILD) + IF (X86_64 OR X86 OR ARM OR AARCH64 OR PPC64 OR PPC64LE) AND NOT WINRT AND NOT APPLE_FRAMEWORK +) # Optional 3rd party components # =================================================== From bc95c609ff458b6d24cecbbac3c608700049f7de Mon Sep 17 00:00:00 2001 From: Alexander Alekhin Date: Wed, 3 Jul 2019 19:01:03 +0300 Subject: [PATCH 3/6] ts: runtime check for misused 'optional' test data files --- modules/dnn/test/test_caffe_importer.cpp | 2 +- modules/ts/src/ts.cpp | 8 +++++--- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/modules/dnn/test/test_caffe_importer.cpp b/modules/dnn/test/test_caffe_importer.cpp index a5cae50621..9588015a1e 100644 --- a/modules/dnn/test/test_caffe_importer.cpp +++ b/modules/dnn/test/test_caffe_importer.cpp @@ -205,7 +205,7 @@ TEST(Reproducibility_FCN, Accuracy) Net net; { const string proto = findDataFile("dnn/fcn8s-heavy-pascal.prototxt"); - const string model = findDataFile("dnn/fcn8s-heavy-pascal.caffemodel"); + const string model = findDataFile("dnn/fcn8s-heavy-pascal.caffemodel", false); net = readNetFromCaffe(proto, model); ASSERT_FALSE(net.empty()); } diff --git a/modules/ts/src/ts.cpp b/modules/ts/src/ts.cpp index acb7459a48..13bf51ec59 100644 --- a/modules/ts/src/ts.cpp +++ b/modules/ts/src/ts.cpp @@ -968,13 +968,15 @@ static std::string findData(const std::string& relative_path, bool required, boo std::string prefix = path_join(datapath, subdir); std::string result_; CHECK_FILE_WITH_PREFIX(prefix, result_); -#if 1 // check for misused 'optional' mode if (!required && !result_.empty()) { std::cout << "TEST ERROR: Don't use 'optional' findData() for " << relative_path << std::endl; - CV_Assert(required || result_.empty()); + static bool checkOptionalFlag = cv::utils::getConfigurationParameterBool("OPENCV_TEST_CHECK_OPTIONAL_DATA", false); + if (checkOptionalFlag) + { + CV_Assert(required || result_.empty()); + } } -#endif if (!result_.empty()) return result_; } From 07fe1cd6b87d67158188f2a1f07e7e66656812e5 Mon Sep 17 00:00:00 2001 From: Alexander Alekhin Date: Wed, 3 Jul 2019 21:55:30 +0000 Subject: [PATCH 4/6] videoio: eliminate build warnings (clang) --- modules/videoio/src/cap_gstreamer.cpp | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/modules/videoio/src/cap_gstreamer.cpp b/modules/videoio/src/cap_gstreamer.cpp index af947a8e16..e24758d326 100644 --- a/modules/videoio/src/cap_gstreamer.cpp +++ b/modules/videoio/src/cap_gstreamer.cpp @@ -97,6 +97,11 @@ static void handleMessage(GstElement * pipeline); namespace { +#if defined __clang__ +# pragma clang diagnostic push +# pragma clang diagnostic ignored "-Wunused-function" +#endif + template static inline void GSafePtr_addref(T* ptr) { if (ptr) @@ -125,6 +130,10 @@ template<> inline void GSafePtr_release(GstEncoding template<> inline void GSafePtr_addref(char* pPtr); // declaration only. not defined. should not be used template<> inline void GSafePtr_release(char** pPtr) { if (pPtr) { g_free(*pPtr); *pPtr = NULL; } } +#if defined __clang__ +# pragma clang diagnostic pop +#endif + template class GSafePtr { From 6dfe2ddc21cfc3216a3f9483b56eace916eb679f Mon Sep 17 00:00:00 2001 From: Diego Date: Thu, 4 Jul 2019 07:56:00 +0200 Subject: [PATCH 5/6] Merge pull request #14959 from dvd42:onnx_clip * onnx clip operation --- modules/dnn/src/onnx/onnx_importer.cpp | 7 +++++++ modules/dnn/test/test_onnx_importer.cpp | 5 +++++ 2 files changed, 12 insertions(+) diff --git a/modules/dnn/src/onnx/onnx_importer.cpp b/modules/dnn/src/onnx/onnx_importer.cpp index 696588c83a..b9fb0be624 100644 --- a/modules/dnn/src/onnx/onnx_importer.cpp +++ b/modules/dnn/src/onnx/onnx_importer.cpp @@ -530,6 +530,13 @@ void ONNXImporter::populateNet(Net dstNet) layerParams.type = "Power"; } } + else if (layer_type == "Clip") + { + layerParams.type = "ReLU6"; + replaceLayerParam(layerParams, "min", "min_value"); + replaceLayerParam(layerParams, "max", "max_value"); + + } else if (layer_type == "LeakyRelu") { layerParams.type = "ReLU"; diff --git a/modules/dnn/test/test_onnx_importer.cpp b/modules/dnn/test/test_onnx_importer.cpp index c99b8cf431..186239494f 100644 --- a/modules/dnn/test/test_onnx_importer.cpp +++ b/modules/dnn/test/test_onnx_importer.cpp @@ -136,6 +136,11 @@ TEST_P(Test_ONNX_layers, ReLU) testONNXModels("ReLU"); } +TEST_P(Test_ONNX_layers, Clip) +{ + testONNXModels("clip", npy); +} + TEST_P(Test_ONNX_layers, MaxPooling_Sigmoid) { testONNXModels("maxpooling_sigmoid"); From 82e5b961d362e29585da8542f704ddb3007cdd64 Mon Sep 17 00:00:00 2001 From: Vitaly Tuzov Date: Wed, 3 Jul 2019 15:15:28 +0300 Subject: [PATCH 6/6] Fixed initUndistortRectifyMap AVX2 implementation --- modules/calib3d/test/test_undistort.cpp | 30 +++++++++++++++++++++++++ modules/imgproc/src/undistort.avx2.cpp | 2 +- 2 files changed, 31 insertions(+), 1 deletion(-) diff --git a/modules/calib3d/test/test_undistort.cpp b/modules/calib3d/test/test_undistort.cpp index a4590b45e6..42ad294e51 100644 --- a/modules/calib3d/test/test_undistort.cpp +++ b/modules/calib3d/test/test_undistort.cpp @@ -1114,4 +1114,34 @@ TEST(Calib3d_UndistortPoints, outputShape) } } +TEST(Calib3d_initUndistortRectifyMap, regression_14467) +{ + Size size_w_h(512 + 3, 512); + Matx33f k( + 6200, 0, size_w_h.width / 2.0f, + 0, 6200, size_w_h.height / 2.0f, + 0, 0, 1 + ); + + Mat mesh_uv(size_w_h, CV_32FC2); + for (int i = 0; i < size_w_h.height; i++) + { + for (int j = 0; j < size_w_h.width; j++) + { + mesh_uv.at(i, j) = Vec2f((float)j, (float)i); + } + } + + Matx d( + 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, + 0.09, 0.0 + ); + Mat mapxy, dst; + initUndistortRectifyMap(k, d, noArray(), k, size_w_h, CV_32FC2, mapxy, noArray()); + undistortPoints(mapxy.reshape(2, (int)mapxy.total()), dst, k, d, noArray(), k); + dst = dst.reshape(2, mapxy.rows); + EXPECT_LE(cvtest::norm(dst, mesh_uv, NORM_INF), 1e-3); +} + }} // namespace diff --git a/modules/imgproc/src/undistort.avx2.cpp b/modules/imgproc/src/undistort.avx2.cpp index 69998be39b..9b6608a783 100644 --- a/modules/imgproc/src/undistort.avx2.cpp +++ b/modules/imgproc/src/undistort.avx2.cpp @@ -124,7 +124,7 @@ int initUndistortRectifyMapLine_AVX(float* m1f, float* m2f, short* m1, ushort* m _mm256_mul_pd(__matTilt_20, __xd), _mm256_mul_pd(__matTilt_21, __yd)), __matTilt_22); #endif __m256d __invProj = _mm256_blendv_pd( - __one, _mm256_div_pd(__one, __vecTilt2), + _mm256_div_pd(__one, __vecTilt2), __one, _mm256_cmp_pd(__vecTilt2, _mm256_setzero_pd(), _CMP_EQ_OQ)); #if CV_FMA3