Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(5.x) Merge 4.x #24416

Merged
merged 46 commits into from Oct 24, 2023
Merged

(5.x) Merge 4.x #24416

merged 46 commits into from Oct 24, 2023

Conversation

asmorkalov
Copy link
Contributor

@asmorkalov asmorkalov commented Oct 16, 2023

Contrib: opencv/opencv_contrib#3578
Extra: opencv/opencv_extra#1109

#23109 from seanm:misc-warnings
#23987 from dkurt:openvino_int8_backend
#24233 from jvuillaumier:rotate_flip_hal_hooks
#24234 from dkurt:distanceTransform_max_dist
#24240 from asmorkalov:as/vl4_convert_rgb
#24298 from WanliZhong:extend_perf_net_test
#24315 from fengyuentau:gemm_fixes
#24323 from georgthegreat:akaze-variadic
#24324 from hanliutong:rewrite-fluid
#24325 from hanliutong:rewrite
#24333 from definitelyuncertain:CvtRGB2YUV422
#24337 from mshabunin:bump-ade-012c
#24341 from emmanuel-ferdman:wip
#24342 from asmorkalov:as/java_test_status
#24343 from mshabunin:fix-test-writes
#24344 from asmorkalov:as/einsum_fallback_fix
#24349 from AleksandrPanov:aruco_check_board_separation
#24350 from dkurt:py_return_non_utf8_string
#24351 from sergiomb2:master
#24353 from alexlyulkov:al/fixed-cumsum-layer
#24354 from asmorkalov:as/charuco_ub
#24355 from AleksandrPanov:dynamic_window_in_aruco_cornerRefinement
#24356 from VadimLevin:dev/vlevin/typing-re-export
#24359 from asmorkalov:as/FastNeuralStyle_eccv16_tuning
#24362 from dkurt:enable_ov_2023_tests
#24368 from mshabunin:rvv-clang-17
#24370 from LiuPeiqiCN:4.x
#24386 from fengyuentau:fix_dtype_nary_eltwise
#24401 from mshabunin:enable-riscv-ci

Previous "Merge 4.x": #24338

hanliutong and others added 30 commits September 22, 2023 12:14
OpenVINO backend for INT8 models opencv#23987

### Pull Request Readiness Checklist

TODO:
- [x] DetectionOutput layer (opencv#24069)
- [x] Less FP32 fallbacks (i.e. Sigmoid, eltwise sum)
- [x] Accuracy, performance tests (opencv#24039)
- [x] Single layer tests (convolution)
- [x] ~~Fixes for OpenVINO 2022.1 (https://pullrequest.opencv.org/buildbot/builders/precommit_custom_linux/builds/100334)~~


Performace results for object detection model `coco_efficientdet_lite0_v1_1.0_quant_2021_09_06.tflite`:
| backend | performance (median time) |
|---|---|
| OpenCV | 77.42ms |
| OpenVINO 2023.0 | 10.90ms |

CPU: `11th Gen Intel(R) Core(TM) i5-1135G7 @ 2.40GHz`

Serialized model per-layer stats (note that Convolution should use `*_I8` primitives if they are quantized correctly): https://gist.github.com/dkurt/7772bbf1907035441bb5454f19f0feef

---

See details at https://github.com/opencv/opencv/wiki/How_to_contribute#making-a-good-pull-request

- [x] I agree to contribute to the project under Apache 2 License.
- [x] To the best of my knowledge, the proposed patch is not based on a code under GPL or another license that is incompatible with OpenCV
- [x] The PR is proposed to the proper branch
- [x] There is a reference to the original bug report and related work
- [x] There is accuracy test, performance test and test data in opencv_extra repository, if applicable
      Patch to opencv_extra has the same branch name.
- [x] The feature is well documented and sample code can be built with the project CMake
fix: update location to `samples/dnn/download_models.py`
Fail Java test suite, execution, if one of test failed.
…_separation

add aruco board separation check
Fixed CumSum dnn layer opencv#24353

Fixes opencv#20110

The algorithm had several errors, so I rewrote it.
Also the layer didn't work with non constant axis tensor. Fixed it.
Enabled CumSum layer tests from ONNX conformance.
Import Python typing module as `_typing` to avoid name clashes.
so we don't use numpy.distutils to get includes dirs of python-numpy
Fix tests writing to current work dir opencv#24343

Several tests were writing files in the current work directory and did not clean up after test. Moved all temporary files to the `/tmp` dir and added a cleanup code.
Change max distance at distanceTransform opencv#24234

### Pull Request Readiness Checklist

resolves opencv#23895
related: opencv#12278

* DIST_MASK_3 and DIST_MASK_5 maximal distance increased from 8192 to 65533 +/- 1
* Fix squares processing at DIST_MASK_PRECISE
* - [ ] TODO: Check with IPP

```cpp
    cv::Mat gray = cv::imread("opencv/samples/data/stuff.jpg", cv::ImreadModes::IMREAD_GRAYSCALE);

    cv::Mat gray_resize;
    cv::resize(gray, gray_resize, cv::Size(70000,70000), 0.0, 0.0, cv::INTER_LINEAR);

    gray_resize = gray_resize >= 100;

    cv::Mat dist;
    cv::distanceTransform(gray_resize, dist, cv::DIST_L2, cv::DIST_MASK_5, CV_32F);

    double minVal, maxVal;
    minMaxLoc(dist, &minVal, &maxVal);
    dist = 255 * (dist - minVal) / (maxVal - minVal);
    std::cout << minVal << " " << maxVal << std::endl;

    cv::Mat dist_resize;
    cv::resize(dist, dist_resize, cv::Size(1024,1024), 0.0, 0.0, cv::INTER_LINEAR);

    cv::String outfilePath = "test_mask_5.png";
    cv::imwrite(outfilePath, dist_resize);
```

mask | 4.x | PR |
----------|--------------|--------------
DIST_MASK_3 | <img src="https://github.com/opencv/opencv/assets/25801568/23e5de76-a8ba-4eb8-ab03-fa55672834be" width="128"> | <img src="https://github.com/opencv/opencv/assets/25801568/e1149f6a-49d6-47bd-a2a8-20bb7e4dafa4" width="128"> |
DIST_MASK_5 | <img src="https://github.com/opencv/opencv/assets/25801568/98aba29b-8865-4b9a-8066-669b16d175c9" width="128"> | <img src="https://github.com/opencv/opencv/assets/25801568/54f62ed2-9ef6-485f-bd63-48cc96accd7d" width="128"> |
DIST_MASK_PRECISE | <img src="https://github.com/opencv/opencv/assets/25801568/c4d79451-fd7a-461f-98fc-13060c63f473" width="128"> | <img src="https://github.com/opencv/opencv/assets/25801568/b5bfcaf5-bc48-40ba-b8e3-d000e5ab48db" width="128">|

See details at https://github.com/opencv/opencv/wiki/How_to_contribute#making-a-good-pull-request

- [x] I agree to contribute to the project under Apache 2 License.
- [x] To the best of my knowledge, the proposed patch is not based on a code under GPL or another license that is incompatible with OpenCV
- [x] The PR is proposed to the proper branch
- [x] There is a reference to the original bug report and related work
- [x] There is accuracy test, performance test and test data in opencv_extra repository, if applicable
      Patch to opencv_extra has the same branch name.
- [x] The feature is well documented and sample code can be built with the project CMake
`numpy.distutils` is removed in numpy 1.26 on Python 3.12.
Removed invalid reference usage in charuco detector
…export

feat: re-export cv2.typing module as typing
Extend performance test models opencv#24298

**Merged With opencv/opencv_extra#1095

This PR aims to extend the performance tests. 

- **YOLOv5** for object detection
- **YOLOv8** for object detection
- **EfficientNet** for classification

Models from OpenCV Zoo:

- **YOLOX** for object detection
- **YuNet** for face detection
- **SFace** for face recognization
- **MPPalm** for palm detection
- **MPHand** for hand landmark
- **MPPose** for pose estimation
- **ViTTrack** for object tracking
- **PPOCRv3** for text detection
- **CRNN** for text recognization
- **PPHumanSeg** for human segmentation

If other models should be added, **please leave some comments**. Thanks!



Build opencv with script:
```shell
-DBUILD_opencv_python2=OFF
-DBUILD_opencv_python3=OFF
-DBUILD_opencv_gapi=OFF
-DINSTALL_PYTHON_EXAMPLES=OFF
-DINSTALL_C_EXAMPLES=OFF
-DBUILD_DOCS=OFF
-DBUILD_EXAMPLES=OFF
-DBUILD_ZLIB=OFF
-DWITH_FFMPEG=OFF
```



Performance Test on **Apple M2 CPU**
```shell
MacOS 14.0
8 threads
```

**1 thread:**
| Name of Test | 4.5.5-1th | 4.6.0-1th | 4.7.0-1th | 4.8.0-1th | 4.8.1-1th |
|--------------|:---------:|:---------:|:---------:|:---------:|:---------:|
| CRNN         |  76.244   |  76.611   |  62.534   |  57.678   |  57.238   |
| EfficientNet |    ---    |    ---    |  109.224  |  130.753  |  109.076  |
| MPHand       |    ---    |    ---    |  19.289   |  22.727   |  27.593   |
| MPPalm       |  47.150   |  47.061   |  41.064   |  65.598   |  40.109   |
| MPPose       |    ---    |    ---    |  26.592   |  32.022   |  26.956   |
| PPHumanSeg   |  41.672   |  41.790   |  27.819   |  27.212   |  30.461   |
| PPOCRv3      |    ---    |    ---    |  140.371  |  187.922  |  170.026  |
| SFace        |  43.830   |  43.834   |  27.575   |  30.653   |  26.387   |
| ViTTrack     |    ---    |    ---    |    ---    |  14.617   |  15.028   |
| YOLOX        | 1060.507  | 1061.361  |  495.816  |  533.309  |  549.713  |
| YOLOv5       |    ---    |    ---    |    ---    |  191.350  |  193.261  |
| YOLOv8       |    ---    |    ---    |  198.893  |  218.733  |  223.142  |
| YuNet        |  27.084   |  27.095   |  26.238   |  30.512   |  34.439   |
| MobileNet_SSD_Caffe         |  44.742   |  44.565   |  33.005   |  29.421   |  29.286   |
| MobileNet_SSD_v1_TensorFlow |  49.352   |  49.274   |  35.163   |  32.134   |  31.904   |
| MobileNet_SSD_v2_TensorFlow |  83.537   |  83.379   |  56.403   |  42.947   |  42.148   |
| ResNet_50                   |  148.872  |  148.817  |  77.331   |  67.682   |  67.760   |


**n threads:**
| Name of Test | 4.5.5-nth | 4.6.0-nth | 4.7.0-nth | 4.8.0-nth | 4.8.1-nth |
|--------------|:---------:|:---------:|:---------:|:---------:|:---------:|
| CRNN         |  44.262   |  44.408   |  41.540   |  40.731   |  41.151   |
| EfficientNet |    ---    |    ---    |  28.683   |  42.676   |  38.204   |
| MPHand       |    ---    |    ---    |   6.738   |  13.126   |   8.155   |
| MPPalm       |  16.613   |  16.588   |  12.477   |  31.370   |  17.048   |
| MPPose       |    ---    |    ---    |  12.985   |  19.700   |  16.537   |
| PPHumanSeg   |  14.993   |  15.133   |  13.438   |  15.269   |  15.252   |
| PPOCRv3      |    ---    |    ---    |  63.752   |  85.469   |  76.190   |
| SFace        |  10.685   |  10.822   |   8.127   |   8.318   |   7.934   |
| ViTTrack     |    ---    |    ---    |    ---    |  10.079   |   9.579   |
| YOLOX        |  417.358  |  422.977  |  230.036  |  234.662  |  228.555  |
| YOLOv5       |    ---    |    ---    |    ---    |  74.249   |  75.480   |
| YOLOv8       |    ---    |    ---    |  63.762   |  88.770   |  70.927   |
| YuNet        |   8.589   |   8.731   |  11.269   |  16.466   |  14.513   |
| MobileNet_SSD_Caffe         |  12.575   |  12.636   |  11.529   |  12.114   |  12.236   |
| MobileNet_SSD_v1_TensorFlow |  13.922   |  14.160   |  13.078   |  12.124   |  13.298   |
| MobileNet_SSD_v2_TensorFlow |  25.096   |  24.836   |  22.823   |  20.238   |  20.319   |
| ResNet_50                   |  41.561   |  41.296   |  29.092   |  30.412   |  29.339   |


Performance Test on [Intel Core i7-12700K](https://www.intel.com/content/www/us/en/products/sku/134594/intel-core-i712700k-processor-25m-cache-up-to-5-00-ghz/specifications.html)
```shell
Ubuntu 22.04.2 LTS
8 Performance-cores (3.60 GHz, turbo up to 4.90 GHz)
4 Efficient-cores (2.70 GHz, turbo up to 3.80 GHz)
20 threads
```


**1 thread:**
| Name of Test | 4.5.5-1th | 4.6.0-1th | 4.7.0-1th | 4.8.0-1th | 4.8.1-1th |
|--------------|:---------:|:---------:|:---------:|:---------:|:---------:|
| CRNN         |  16.752   |  16.851   |  16.840   |  16.625   |  16.663   |
| EfficientNet |    ---    |    ---    |  61.107   |  76.037   |  53.890   |
| MPHand       |    ---    |    ---    |   8.906   |   9.969   |   8.403   |
| MPPalm       |  24.243   |  24.638   |  18.104   |  35.140   |  18.387   |
| MPPose       |    ---    |    ---    |  12.322   |  16.515   |  12.355   |
| PPHumanSeg   |  15.249   |  15.303   |  10.203   |  10.298   |  10.353   |
| PPOCRv3      |    ---    |    ---    |  87.788   |  144.253  |  90.648   |
| SFace        |  15.583   |  15.884   |  13.957   |  13.298   |  13.284   |
| ViTTrack     |    ---    |    ---    |    ---    |  11.760   |  11.710   |
| YOLOX        |  324.927  |  325.173  |  235.986  |  253.653  |  254.472  |
| YOLOv5       |    ---    |    ---    |    ---    |  102.163  |  102.621  |
| YOLOv8       |    ---    |    ---    |  87.013   |  103.182  |  103.146  |
| YuNet        |  12.806   |  12.645   |  10.515   |  12.647   |  12.711   |
| MobileNet_SSD_Caffe         |  23.556   |  23.768   |  24.304   |  22.569   |  22.602   |
| MobileNet_SSD_v1_TensorFlow |  26.136   |  26.276   |  26.854   |  24.828   |  24.961   |
| MobileNet_SSD_v2_TensorFlow |  43.521   |  43.614   |  46.892   |  44.044   |  44.682   |
| ResNet_50                   |  73.588   |  73.501   |  75.191   |  66.893   |  65.144   |


**n thread:**
| Name of Test | 4.5.5-nth | 4.6.0-nth | 4.7.0-nth | 4.8.0-nth | 4.8.1-nth | 
|--------------|:---------:|:---------:|:---------:|:---------:|:---------:|
| CRNN         |   8.665   |   8.827   |  10.643   |   7.703   |   7.743   | 
| EfficientNet |    ---    |    ---    |  16.591   |  12.715   |   9.022   |   
| MPHand       |    ---    |    ---    |   2.678   |   2.785   |   1.680   |           
| MPPalm       |   5.309   |   5.319   |   3.822   |  10.568   |   4.467   |       
| MPPose       |    ---    |    ---    |   3.644   |   6.088   |   4.608   |        
| PPHumanSeg   |   4.756   |   4.865   |   5.084   |   5.179   |   5.148   |        
| PPOCRv3      |    ---    |    ---    |  32.023   |  50.591   |  32.414   |      
| SFace        |   3.838   |   3.980   |   4.629   |   3.145   |   3.155   |       
| ViTTrack     |    ---    |    ---    |    ---    |  10.335   |  10.357   |   
| YOLOX        |  68.314   |  68.081   |  82.801   |  74.219   |  73.970   |      
| YOLOv5       |    ---    |    ---    |    ---    |  47.150   |  47.523   |    
| YOLOv8       |    ---    |    ---    |  32.195   |  30.359   |  30.267   |    
| YuNet        |   2.604   |   2.644   |   2.622   |   3.278   |   3.349   |    
| MobileNet_SSD_Caffe         |  13.005   |   5.935   |   8.586   |   4.629   |   4.713   |
| MobileNet_SSD_v1_TensorFlow |   7.002   |   7.129   |   9.314   |   5.271   |   5.213   |
| MobileNet_SSD_v2_TensorFlow |  11.939   |  12.111   |  22.688   |  12.038   |  12.086   |
| ResNet_50                   |  18.227   |  18.600   |  26.150   |  15.584   |  15.706   |
Rewrite Universal Intrinsic code: float related part opencv#24325

The goal of this series of PRs is to modify the SIMD code blocks guarded by CV_SIMD macro: rewrite them by using the new Universal Intrinsic API.

The series of PRs is listed below:
opencv#23885 First patch, an example
opencv#23980 Core module
opencv#24058 ImgProc module, part 1
opencv#24132 ImgProc module, part 2
opencv#24166 ImgProc module, part 3
opencv#24301 Features2d and calib3d module
opencv#24324 Gapi module

This patch (hopefully) is the last one in the series. 

This patch mainly involves 3 parts
1. Add some modifications related to float (CV_SIMD_64F)
2. Use `#if (CV_SIMD || CV_SIMD_SCALABLE)` instead of `#if CV_SIMD || CV_SIMD_SCALABLE`, 
    then we can get the `CV_SIMD` module that is not enabled for `CV_SIMD_SCALABLE` by looking for `if CV_SIMD`
3. Summary of `CV_SIMD` blocks that remains unmodified: Updated comments
    - Some blocks will cause test fail when enable for RVV, marked as `TODO: enable for CV_SIMD_SCALABLE, ....`
    - Some blocks can not be rewrited directly. (Not commented in the source code, just listed here)
      - ./modules/core/src/mathfuncs_core.simd.hpp (Vector type wrapped in class/struct)
      - ./modules/imgproc/src/color_lab.cpp (Array of vector type)
      - ./modules/imgproc/src/color_rgb.simd.hpp (Array of vector type)
      - ./modules/imgproc/src/sumpixels.simd.hpp (fixed length algorithm, strongly ralated with `CV_SIMD_WIDTH`)
      These algorithms will need to be redesigned to accommodate scalable backends.

### Pull Request Readiness Checklist

See details at https://github.com/opencv/opencv/wiki/How_to_contribute#making-a-good-pull-request

- [ ] I agree to contribute to the project under Apache 2 License.
- [ ] To the best of my knowledge, the proposed patch is not based on a code under GPL or another license that is incompatible with OpenCV
- [ ] The PR is proposed to the proper branch
- [ ] There is a reference to the original bug report and related work
- [ ] There is accuracy test, performance test and test data in opencv_extra repository, if applicable
      Patch to opencv_extra has the same branch name.
- [ ] The feature is well documented and sample code can be built with the project CMake
Add HAL implementation hooks to cv::flip() and cv::rotate() functions from core module opencv#24233

Hello,

This change proposes the addition of HAL hooks for cv::flip() and cv::rotate() functions from OpenCV core module.
Flip and rotation are functions commonly available from 2D hardware accelerators. This is convenient provision to enable custom optimized implementation of image flip/rotation on systems embedding such accelerator.

Thank you

### Pull Request Readiness Checklist

See details at https://github.com/opencv/opencv/wiki/How_to_contribute#making-a-good-pull-request

- [x] I agree to contribute to the project under Apache 2 License.
- [x] To the best of my knowledge, the proposed patch is not based on a code under GPL or another license that is incompatible with OpenCV
- [x] The PR is proposed to the proper branch
- [ ] There is a reference to the original bug report and related work
- [ ] There is accuracy test, performance test and test data in opencv_extra repository, if applicable
      Patch to opencv_extra has the same branch name.
- [ ] The feature is well documented and sample code can be built with the project CMake
* Fixed clang -Wnewline-eof warnings
* Fixed all trivial clang -Wextra-semi and -Wc++98-compat-extra-semi warnings
* Removed trailing semi from various macros
* Fixed various -Wunused-macros warnings
* Fixed some trivial -Wdocumentation warnings
* Fixed some -Wdocumentation-deprecated-sync warnings
* Fixed incorrect indentation
* Suppressed some clang warnings in 3rd party code
* Fixed QRCodeEncoder::Params documentation.

---------

Co-authored-by: Alexander Smorkalov <alexander.smorkalov@xperience.ai>
asmorkalov and others added 7 commits October 13, 2023 10:25
Rewrite Universal Intrinsic code: gapi module (fluid part).
…cv16_tuning

Tuned threshold for FastNeuralStyle_eccv16 test
dnn: fix inconsistent input dtype for nary eltwise layers opencv#24386

Resolves opencv#24385
Merge with opencv/opencv_extra#1107
Relates opencv#24092 (comment)

### Pull Request Readiness Checklist

See details at https://github.com/opencv/opencv/wiki/How_to_contribute#making-a-good-pull-request

- [x] I agree to contribute to the project under Apache 2 License.
- [x] To the best of my knowledge, the proposed patch is not based on a code under GPL or another license that is incompatible with OpenCV
- [x] The PR is proposed to the proper branch
- [x] There is a reference to the original bug report and related work
- [x] There is accuracy test, performance test and test data in opencv_extra repository, if applicable
      Patch to opencv_extra has the same branch name.
- [x] The feature is well documented and sample code can be built with the project CMake
Co-authored-by: Maksim Shabunin <maksim.shabunin@gmail.com>
Added test with V4L CAP_PROP_CONVERT_RGB=false.
@asmorkalov asmorkalov changed the base branch from 4.x to 5.x October 16, 2023 18:26
@asmorkalov asmorkalov force-pushed the 5.x-merge-4.x branch 2 times, most recently from c807b55 to 4cbd3d0 Compare October 17, 2023 12:45
@asmorkalov asmorkalov changed the title WIP: Merge branch 4.x (5.x) Merge 4.x Oct 17, 2023
Copy link
Contributor

@opencv-alalek opencv-alalek left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I expect to have these extra changes:

diff --git a/modules/3d/src/precomp.hpp b/modules/3d/src/precomp.hpp
index 7d96a4becc..ef6bf01297 100755
--- a/modules/3d/src/precomp.hpp
+++ b/modules/3d/src/precomp.hpp
@@ -89,7 +89,7 @@ namespace cv {
  * @param ep outlier ratio
  * @param modelPoints number of model points required for estimation
  * @param maxIters maximum number of iterations
- * @return
+ * @return The number of iterations according to the formula
  * \f[
  * \frac{\ln(1-p)}{\ln\left(1-(1-ep)^\mathrm{modelPoints}\right)}
  * \f]
diff --git a/modules/core/include/opencv2/core/matx.hpp b/modules/core/include/opencv2/core/matx.hpp
index e7a7694e9f..fae4526584 100644
--- a/modules/core/include/opencv2/core/matx.hpp
+++ b/modules/core/include/opencv2/core/matx.hpp
@@ -1002,8 +1002,6 @@ Matx<_Tp, m, n> MatxCommaInitializer<_Tp, m, n>::operator *() const
     return *dst;
 }
 
-
-
 /////////////////////////////////// Vec Implementation ///////////////////////////////////
 
 template<typename _Tp, int cn> inline
diff --git a/modules/core/src/arithm.simd.hpp b/modules/core/src/arithm.simd.hpp
index 2c26680b51..3f2f3f10a1 100644
--- a/modules/core/src/arithm.simd.hpp
+++ b/modules/core/src/arithm.simd.hpp
@@ -104,10 +104,6 @@ namespace cv { namespace hal {
 
 #ifdef ARITHM_DEFINITIONS_ONLY
 
-#if !(CV_SIMD_64F || CV_SIMD_SCALABLE_64F)
-typedef int v_float64; // dummy
-#endif
-
 //=======================================
 // Utility
 //=======================================
diff --git a/modules/core/test/test_io.cpp b/modules/core/test/test_io.cpp
index 71994d1cd6..c08e6ba17a 100644
--- a/modules/core/test/test_io.cpp
+++ b/modules/core/test/test_io.cpp
@@ -690,6 +690,7 @@ static void test_filestorage_basic(int write_flags, const char* suffix_name, boo
             }
             std::cout << "Storage size: " << sz << std::endl;
             EXPECT_LE(sz, (size_t)6000);
+
         }
         {   /* read */
             cv::FileStorage fs(name, cv::FileStorage::READ + (useMemory ? cv::FileStorage::MEMORY : 0));
@@ -768,10 +769,10 @@ static void test_filestorage_basic(int write_flags, const char* suffix_name, boo
         if (useMemory) {
             EXPECT_EQ(0, cv::norm(_rd_in, _rd_out, NORM_INF));
         }
-        if (testReadWrite && !useMemory && !generateTestData) {
+        if (testReadWrite && !useMemory && !generateTestData)
+        {
             EXPECT_EQ(0, remove(name.c_str()));
         }
-
     }
 }
 
diff --git a/modules/dnn/perf/perf_net.cpp b/modules/dnn/perf/perf_net.cpp
index a8ad06a30d..46484e82c5 100644
--- a/modules/dnn/perf/perf_net.cpp
+++ b/modules/dnn/perf/perf_net.cpp
@@ -269,7 +269,8 @@ PERF_TEST_P_(DNNTestNetwork, Inception_v2_Faster_RCNN)
         (backend == DNN_BACKEND_OPENCV && target == DNN_TARGET_OPENCL_FP16))
         throw SkipTestException("");
     processNet("dnn/faster_rcnn_inception_v2_coco_2018_01_28.pb",
-               "dnn/faster_rcnn_inception_v2_coco_2018_01_28.pbtxt", cv::Size(800, 600));
+               "dnn/faster_rcnn_inception_v2_coco_2018_01_28.pbtxt",
+               cv::Size(800, 600));
 }
 
 PERF_TEST_P_(DNNTestNetwork, EfficientDet)
diff --git a/modules/stereo/src/precomp.hpp b/modules/stereo/src/precomp.hpp
index a786466ae6..24f8f675b8 100644
--- a/modules/stereo/src/precomp.hpp
+++ b/modules/stereo/src/precomp.hpp
@@ -65,7 +65,7 @@ namespace cv
  * @param ep outlier ratio
  * @param modelPoints number of model points required for estimation
  * @param maxIters maximum number of iterations
- * @return
+ * @return The number of iterations according to the formula
  * \f[
  * \frac{\ln(1-p)}{\ln\left(1-(1-ep)^\mathrm{modelPoints}\right)}
  * \f]
diff --git a/samples/dnn/README.md b/samples/dnn/README.md
index 8c06b262ee..c99b735a1f 100644
--- a/samples/dnn/README.md
+++ b/samples/dnn/README.md
@@ -50,14 +50,14 @@ python your_script.py
 **Note** that you can provide a directory using **save_dir** parameter or via **OPENCV_SAVE_DIR** environment variable.
 
 #### Face detection
-[An origin model](https://github.com/opencv/opencv/tree/4.x/samples/dnn/face_detector)
+[An origin model](https://github.com/opencv/opencv/tree/5.x/samples/dnn/face_detector)
 with single precision floating point weights has been quantized using [TensorFlow framework](https://www.tensorflow.org/).
 To achieve the best accuracy run the model on BGR images resized to `300x300` applying mean subtraction
 of values `(104, 177, 123)` for each blue, green and red channels correspondingly.
 
 The following are accuracy metrics obtained using [COCO object detection evaluation
 tool](http://cocodataset.org/#detections-eval) on [FDDB dataset](http://vis-www.cs.umass.edu/fddb/)
-(see [script](https://github.com/opencv/opencv/blob/4.x/modules/dnn/misc/face_detector_accuracy.py))
+(see [script](https://github.com/opencv/opencv/blob/5.x/modules/dnn/misc/face_detector_accuracy.py))
 applying resize to `300x300` and keeping an origin images' sizes.

modules/core/test/test_io.cpp Show resolved Hide resolved
modules/core/include/opencv2/core/matx.hpp Outdated Show resolved Hide resolved
samples/dnn/README.md Outdated Show resolved Hide resolved
modules/dnn/perf/perf_net.cpp Outdated Show resolved Hide resolved
@asmorkalov asmorkalov force-pushed the 5.x-merge-4.x branch 2 times, most recently from 4ab8568 to eed3844 Compare October 19, 2023 06:36
@asmorkalov
Copy link
Contributor Author

The test failure reason is at

for (int j = 1; j < std::min(4, inputsData[i].size[1]) && singleMean; ++j)

The code expects, that all intermediate tensors (cv::Mat) have at least 2 dimensions. It's true for 4.x, but not for 5.x. The assert is enabled in debug only and the issue is not visible in release.
@vpisarev @opencv-alalek I propose to disable the failed tests for now and fix the issue with the next PR to 5.x. What do you think?

@vpisarev
Copy link
Contributor

The test failure reason is at

for (int j = 1; j < std::min(4, inputsData[i].size[1]) && singleMean; ++j)

The code expects, that all intermediate tensors (cv::Mat) have at least 2 dimensions. It's true for 4.x, but not for 5.x. The assert is enabled in debug only and the issue is not visible in release.
@vpisarev @opencv-alalek I propose to disable the failed tests for now and fix the issue with the next PR to 5.x. What do you think?

use inputsData[i].total() instead of inputsData[i].size[1]?

@asmorkalov
Copy link
Contributor Author

@opencv-alalek @vpisarev I fixed the issue with shapes with small check. Please review the solution.

@opencv-alalek
Copy link
Contributor

There are build issues with MSVS2019:

But they are here since August.

if (isFP16)
CV_CheckTypeEQ(outputs[i].type(), CV_16SC1, "");
else
CV_CheckTypeEQ(outputs[i].type(), CV_32FC1, "");

bool singleMean = true;
for (int j = 1; j < std::min(4, inputsData[i].size[1]) && singleMean; ++j)
for (int j = 1; j < std::min(4, total_c) && singleMean && inputsData[i].dims >=2; ++j)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

inputsData[i].dims >=2

Why do we need that condition?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if I understood correctly size[1] corresponds to channels in NCHW. in case of 1d input, singleMean branch should be used (it does not iterate over the second dimension. @vpisarev @dkurt Is it right assumption?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Problem is related to changes from here: #23473
User code goes to be broken after 4.x, mostly in a silent and unexpected way.

singleMean is true iff mean[i] = X (same value) for all i in [0..total_c]`.

1D doesn't guarantee that this is true (need to add separate test for that, because current tests pass just [0,0,0,0]).

Next, there is the same problem in OpenCL code branch few lines below.

It also raises the same exception, but it is suppressed. See FIXIT comment here: https://github.com/opencv/opencv/blame/19926e2979ef049a89dd029e2231555db40c2776/modules/dnn/src/dnn.cpp#L629

Einsum violates agreement of .setInput() API.
Test ignores the first batch number "N". Next is expected to be "C" as channels.

Accepted layouts are:

  • NCHW (2d color image, dims=4)
  • NCDHW (3d, e.g. "Test_TensorFlow_layers.concat_3d" test, dims=5)
  • there is no 1D input expected. "NC" layout should be used instead.

There is a lack of layouts information metadata so they must be started from "NC" dimensions to keep assumption works.

BTW, there is some input with dims=3. No idea what is that. E.g. check "Test_TensorFlow_layers.l2_normalize_3d" test (--test_debug=1 could show more).


So I propose:

  • to revert changes here.
  • to disable Einsum test in this PR
  • 4.x: to add CHECK(inputsData[i].dims, 2, "") check (for both CPU and OpenCL code)
  • 4.x: to add check in .setInput() to "fail fast"
  • 4.x: to fix Einsum tests and use "NC" layout to avoid violation of .setInput() assumptions.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This feature if not very flexible, I agree. I think that adding a check that input has at least 2 dimensions is a good option because this initially designed for image processing networks that usually apply mean subtraction as a preprocessing step. I have not seen much models with 1D input that do the same. Usually, their input data is much more complicated (text tokens, audio sampling) and mean processing is not used.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we add also a flag such as bool preprocessing which indicates if mean/scale were actually specified but not initialized by default with zero/ones?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I disabled cumsum tests and created an issue for it. Let's "merge" merge PR and then try to handle the issue separately. I prefer to have dedicated PRs for significant changes to not hide it in merge commit with conflicts.

@asmorkalov asmorkalov merged commit 97620c0 into opencv:5.x Oct 24, 2023
23 checks passed
@asmorkalov asmorkalov mentioned this pull request Nov 3, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet