mirror of
https://github.com/opencv/opencv.git
synced 2026-12-02 12:12:06 -06:00
GatherElementsLayerImpl::finalize previously normalized the axis attribute by overwriting this->axis with normalize_axis(axis, data.dims). When the layer was created with a negative axis (such as -1, supported by the ONNX GatherElements specification), this replaced the relative index with a positive index fixed to the rank of the first input. Subsequent evaluations on an input of different rank on the same layer then: - evaluated GatherElements along the wrong axis (e.g. axis 1 instead of axis 2 when moving from a 2D tensor to a 3D tensor), leading to silent data corruption, or - triggered an assertion failure in normalize_axis (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 regression tests covering both decreasing and increasing rank on the same GatherElements layer instance.