1
0
mirror of https://github.com/opencv/opencv.git synced 2026-07-29 07:13:02 +04:00

Fix: TopK layer K boundary check allows K == input_dim (#28445)

The TopK layer was incorrectly rejecting K values equal to the input
dimension size. According to ONNX specification, K should be allowed
to equal the dimension size (to retrieve all elements).

Changed validation from 'K < input_shape[axis]' to 'K <= input_shape[axis]'

This fixes the error when loading YOLOv10 ONNX models that use TopK
with K equal to the dimension size.

Fixes #28445
This commit is contained in:
Sikandar
2026-01-27 09:35:36 +05:00
parent 774c7e01b3
commit d8f8267700
+2 -2
View File
@@ -97,9 +97,9 @@ public:
// Normalize axis
int axis_normalized = normalize_axis(axis, input_shape.size());
// Check if K is in range (0, input_shape[axis])
// Check if K is in range (0, input_shape[axis]]
CV_CheckGT(K, 0, "TopK: K needs to be a positive integer");
CV_CheckLT(K, input_shape[axis_normalized], "TopK: K is out of range");
CV_CheckLE(K, input_shape[axis_normalized], "TopK: K is out of range");
// Assign output shape
auto output_shape = input_shape;