Files
opencv-MIRROR/modules/dnn
Ishita Singh e55e631516 dnn: keep the TopK axis attribute unchanged in finalize
TopKLayerImpl::finalize previously normalized the axis attribute by
overwriting this->axis with normalize_axis(axis, input_shape.size()).
When the layer was created with a negative axis (such as the default -1),
this replaced the relative index with a positive index fixed to the rank
of the first input.

Subsequent runs on an input of different rank then either:
- evaluated TopK along the wrong axis (e.g. axis 1 instead of axis 2
  when moving from a 2D tensor to a 3D tensor), or
- triggered an out-of-range assertion in getMemoryShapes (e.g. axis 2
  on a 2D tensor when moving from a 3D tensor to a 2D tensor).

Fix this by keeping this->axis unmodified and storing the normalized axis
separately for execution. Add unit tests for both increasing and decreasing
rank inputs on the same TopK layer instance.
2026-11-30 16:14:05 +05:30
..