Commit 94c8b74
authored
Merge pull request opencv#28425 from Anemptyship:fix/squeeze-all-dims
DNN: Fix Squeeze to remove all size-1 dims when axes is empty opencv#28425
Fixes opencv#28424
OpenCV Extra: [opencv/opencv_extra#1308](opencv/opencv_extra#1308)
This PR fixes the ONNX Squeeze operator to correctly remove all size-1 dimensions when `axes` is not provided, conforming to the ONNX specification.
### Details
Per [ONNX Squeeze specification](https://onnx.ai/onnx/operators/onnx__Squeeze.html):
> 'If axes is not provided, all the single dimensions will be removed from the shape.'
Previously, OpenCV DNN would not remove any dimensions in this case, causing shape mismatch errors with models like LaMa (inpainting).
### Example
```python
# Input: [1, 1, 2, 4]
# Squeeze with no axes attribute
# Before: [1, 1, 2, 4] ✗ (No change)
# After: [2, 4] ✓ (matches ONNX Runtime)
```
### Tests
Added `testONNXModels("squeeze_no_axes")` which validates this behavior with new test data.
opencv_extra_pr=opencv/opencv_extra#1324
### 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 (4.x for bug fixes)
- [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 CMake1 parent 36b2bb7 commit 94c8b74
2 files changed
Lines changed: 11 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2163 | 2163 | | |
2164 | 2164 | | |
2165 | 2165 | | |
| 2166 | + | |
| 2167 | + | |
| 2168 | + | |
| 2169 | + | |
| 2170 | + | |
| 2171 | + | |
| 2172 | + | |
| 2173 | + | |
2166 | 2174 | | |
2167 | 2175 | | |
2168 | 2176 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
103 | 103 | | |
104 | 104 | | |
105 | 105 | | |
| 106 | + | |
| 107 | + | |
106 | 108 | | |
107 | 109 | | |
108 | 110 | | |
| |||
1187 | 1189 | | |
1188 | 1190 | | |
1189 | 1191 | | |
| 1192 | + | |
1190 | 1193 | | |
1191 | 1194 | | |
1192 | 1195 | | |
| |||
0 commit comments