mirror of
https://github.com/opencv/opencv.git
synced 2026-07-29 15:23:05 +04:00
371b80210390ea3e0e29f3feadfae6f621656e40
optimize(dnn): parallelize Resize layer implementation #28442 ### optimize(dnn): parallelize Resize layer implementation This PR addresses the `TODO` in `modules/dnn/src/layers/resize_layer.cpp` regarding the slow implementation of the `Resize` layer when using `opencv_linear` or `nearest` interpolation with specific configurations. ### Changes - Replaced the serial nested loop (batch x channels) with `cv::parallel_for_`. - This allows OpenCV to utilize multi-threading for the resizing operation, which was previously single-threaded for these specific paths. ### Performance Results Benchmark run on 20-thread CPU (AVX2): | Test Case | Resolution Change | Before (ms) | After (ms) | Speedup | | :--- | :--- | :--- | :--- | :--- | | **Upsample Linear** | 64x64 -> 128x128 | 1.47 ms | **0.18 ms** | **~8.1x** | | **Downsample Nearest** | 128x128 -> 64x64 | 1.55 ms | **0.45 ms** | **~3.4x** | **Test Configuration:** - **Upsample**: `[4, 64, 64, 64]` -> `[4, 64, 128, 128]` (Factor: 2.0, Linear) - **Downsample**: `[4, 128, 128, 128]` -> `[4, 128, 64, 64]` (Factor: 0.5, Nearest) ### 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 - [ ] There is accuracy test, performance test and test data in opencv_extra repository, if applicable - Added `modules/dnn/perf/perf_resize.cpp` to verify performance gains. - [ ] The feature is well documented and sample code can be built with the project CMake
OpenCV: Open Source Computer Vision Library
Resources
- Homepage: https://opencv.org
- Courses: https://opencv.org/courses
- Docs: https://docs.opencv.org/5.x/
- Q&A forum: https://forum.opencv.org
- previous forum (read only): http://answers.opencv.org
- Issue tracking: https://github.com/opencv/opencv/issues
- Additional OpenCV functionality: https://github.com/opencv/opencv_contrib
- Donate to OpenCV: https://opencv.org/support/
Contributing
Please read the contribution guidelines before starting work on a pull request.
Summary of the guidelines:
- One pull request per issue;
- Choose the right base branch;
- Include tests and documentation;
- Clean up "oops" commits before submitting;
- Follow the coding style guide.
Additional Resources
- Submit your OpenCV-based project for inclusion in Community Friday on opencv.org
- Subscribe to the OpenCV YouTube Channel featuring OpenCV Live, an hour-long streaming show
- Follow OpenCV on LinkedIn for daily posts showing the state-of-the-art in computer vision & AI
- Apply to be an OpenCV Volunteer to help organize events and online campaigns as well as amplify them
- Follow OpenCV on Mastodon in the Fediverse
- Follow OpenCV on Twitter
- OpenCV.ai: Computer Vision and AI development services from the OpenCV team.
Description
Languages
C++
87.6%
C
3.1%
Python
2.9%
CMake
2%
Java
1.5%
Other
2.7%