mirror of
https://github.com/opencv/opencv.git
synced 2026-12-02 11:51:55 -06:00
085c1942184b7bda04478519dd896aa5de403693
FlattenLayerImpl::finalize previously overwrote _startAxis and _endAxis in place with normalize_axis(..., numAxes) for the rank of the first input. Because end_axis defaults to -1 (and axis can also be negative), this permanently replaced relative negative axes with positive indices bound to the first input rank. Reusing the same Flatten layer with an input of a different rank then failed in two ways: Increasing rank (e.g., default axis=1, end_axis=-1: 3D [2, 3, 4] followed by 4D [2, 3, 4, 5]): silently flattened only axes [1, 2] and returned shape [2, 12, 5] instead of [2, 60]. Decreasing rank (e.g., 4D [2, 3, 4, 5] followed by 3D [2, 3, 4]): threw an assertion error in normalize_axis because the stale _endAxis = 3 was out of range for a 3D input. Fix Keep _startAxis and _endAxis unmodified in FlattenLayerImpl::finalize, while still validating the normalized axis range (0 <= startAxis <= endAxis < numAxes). All backends already handle raw axis attributes cleanly: getMemoryShapes, initCann, and initNgraph normalize _startAxis and _endAxis into local variables, and forward, forward_ocl, and initCUDA operate directly on the output shapes.
OpenCV: Open Source Computer Vision Library
Resources
- Homepage: https://opencv.org
- Courses: https://opencv.org/courses
- Docs: https://docs.opencv.org/4.x/
- Q&A forum: https://forum.opencv.org
- previous forum (read only): https://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 X
- OpenCV.ai: Computer Vision and AI development services from the OpenCV team.
Description
Languages
C++
87.7%
C
3.1%
Python
2.9%
CMake
2%
Java
1.5%
Other
2.6%