mirror of
https://github.com/opencv/opencv.git
synced 2026-12-02 12:12:06 -06:00
FlattenLayerImpl::finalize previously overwrote _startAxis and _endAxis with normalize_axis(..., numAxes) for the rank of the first input. Since end_axis defaults to -1 (and axis can also be negative), this replaced relative negative indices with positive indices bound to the first input rank. Reusing the same Flatten layer on an input of a different rank then: - flattened the wrong range of dimensions when rank increased (e.g. [2, 3, 4, 5] flattened to [2, 12, 5] instead of [2, 60] for default axis=1, end_axis=-1), or - triggered an assertion failure in normalize_axis when rank decreased (e.g. stale end_axis=3 on a 3D input). getMemoryShapes, initCann, and initNgraph already normalize _startAxis and _endAxis locally, and forward/forward_ocl/initCUDA use the output shapes directly. Keep _startAxis and _endAxis unchanged in finalize while still validating the normalized axis range.