33import torch
44
55
6+ # ── Static non-fused (batch=1) ──────────────────────────────────────────────
7+
8+
69@pytest .mark .slow
710@pytest .mark .onnx_extras
8- def test_onnx_package_with_dynamic_batch_size_and_letterbox_numpy (
9- coin_counting_yololite_n_onnx_dynamic_bs_letterbox_package : str ,
11+ def test_static_non_fused_numpy (
12+ coin_counting_yololite_edge_n_onnx_static_bs_stretch_package : str ,
1013 coins_counting_image_numpy : np .ndarray ,
1114) -> None :
12- # given
1315 from inference_models .models .yololite .yololite_object_detection_onnx import (
1416 YOLOLiteForObjectDetectionOnnx ,
1517 )
1618
1719 model = YOLOLiteForObjectDetectionOnnx .from_pretrained (
18- model_name_or_path = coin_counting_yololite_n_onnx_dynamic_bs_letterbox_package ,
20+ model_name_or_path = coin_counting_yololite_edge_n_onnx_static_bs_stretch_package ,
1921 onnx_execution_providers = ["CUDAExecutionProvider" , "CPUExecutionProvider" ],
2022 )
23+ predictions = model (
24+ coins_counting_image_numpy , confidence = 0.25 , iou_threshold = 0.45
25+ )
26+
27+ assert len (predictions ) == 1
28+ assert predictions [0 ].xyxy .shape [1 ] == 4
29+ assert len (predictions [0 ].confidence ) > 0
30+ assert torch .all (predictions [0 ].confidence >= 0.25 )
31+ assert torch .all (predictions [0 ].confidence <= 1.0 )
32+
33+
34+ # ── Dynamic non-fused ────────────────────────────────────────────────────────
35+
36+
37+ @pytest .mark .slow
38+ @pytest .mark .onnx_extras
39+ def test_dynamic_non_fused_numpy (
40+ coin_counting_yololite_edge_n_onnx_dynamic_bs_stretch_package : str ,
41+ coins_counting_image_numpy : np .ndarray ,
42+ ) -> None :
43+ from inference_models .models .yololite .yololite_object_detection_onnx import (
44+ YOLOLiteForObjectDetectionOnnx ,
45+ )
2146
22- # when
47+ model = YOLOLiteForObjectDetectionOnnx .from_pretrained (
48+ model_name_or_path = coin_counting_yololite_edge_n_onnx_dynamic_bs_stretch_package ,
49+ onnx_execution_providers = ["CUDAExecutionProvider" , "CPUExecutionProvider" ],
50+ )
2351 predictions = model (
2452 coins_counting_image_numpy ,
2553 confidence = 0.25 ,
2654 iou_threshold = 0.45 ,
2755 max_detections = 100 ,
2856 )
2957
30- # then
31- assert isinstance (predictions , list )
3258 assert len (predictions ) == 1
3359 assert predictions [0 ].xyxy .shape [1 ] == 4
3460 assert predictions [0 ].xyxy .dtype == torch .int32
@@ -41,38 +67,30 @@ def test_onnx_package_with_dynamic_batch_size_and_letterbox_numpy(
4167
4268@pytest .mark .slow
4369@pytest .mark .onnx_extras
44- def test_onnx_package_with_dynamic_batch_size_and_letterbox_batch_numpy (
45- coin_counting_yololite_n_onnx_dynamic_bs_letterbox_package : str ,
70+ def test_dynamic_non_fused_batch_numpy (
71+ coin_counting_yololite_edge_n_onnx_dynamic_bs_stretch_package : str ,
4672 coins_counting_image_numpy : np .ndarray ,
4773) -> None :
48- # given
4974 from inference_models .models .yololite .yololite_object_detection_onnx import (
5075 YOLOLiteForObjectDetectionOnnx ,
5176 )
5277
5378 model = YOLOLiteForObjectDetectionOnnx .from_pretrained (
54- model_name_or_path = coin_counting_yololite_n_onnx_dynamic_bs_letterbox_package ,
79+ model_name_or_path = coin_counting_yololite_edge_n_onnx_dynamic_bs_stretch_package ,
5580 onnx_execution_providers = ["CUDAExecutionProvider" , "CPUExecutionProvider" ],
5681 )
57-
58- # when
5982 predictions = model (
6083 [coins_counting_image_numpy , coins_counting_image_numpy ],
6184 confidence = 0.25 ,
6285 iou_threshold = 0.45 ,
6386 max_detections = 100 ,
6487 )
6588
66- # then
67- assert isinstance (predictions , list )
6889 assert len (predictions ) == 2
6990 for pred in predictions :
7091 assert pred .xyxy .shape [1 ] == 4
71- assert pred .xyxy .dtype == torch .int32
7292 assert len (pred .confidence ) > 0
7393 assert torch .all (pred .confidence >= 0.25 )
74- assert torch .all (pred .confidence <= 1.0 )
75- # Both images are identical, so detections should match
7694 assert predictions [0 ].xyxy .shape == predictions [1 ].xyxy .shape
7795 assert torch .allclose (
7896 predictions [0 ].confidence , predictions [1 ].confidence , atol = 0.01
@@ -81,98 +99,145 @@ def test_onnx_package_with_dynamic_batch_size_and_letterbox_batch_numpy(
8199
82100@pytest .mark .slow
83101@pytest .mark .onnx_extras
84- def test_onnx_package_with_dynamic_batch_size_and_letterbox_torch (
85- coin_counting_yololite_n_onnx_dynamic_bs_letterbox_package : str ,
102+ def test_dynamic_non_fused_torch (
103+ coin_counting_yololite_edge_n_onnx_dynamic_bs_stretch_package : str ,
86104 coins_counting_image_torch : torch .Tensor ,
87105) -> None :
88- # given
89106 from inference_models .models .yololite .yololite_object_detection_onnx import (
90107 YOLOLiteForObjectDetectionOnnx ,
91108 )
92109
93110 model = YOLOLiteForObjectDetectionOnnx .from_pretrained (
94- model_name_or_path = coin_counting_yololite_n_onnx_dynamic_bs_letterbox_package ,
111+ model_name_or_path = coin_counting_yololite_edge_n_onnx_dynamic_bs_stretch_package ,
95112 onnx_execution_providers = ["CUDAExecutionProvider" , "CPUExecutionProvider" ],
96113 )
97-
98- # when
99114 predictions = model (
100- coins_counting_image_torch ,
101- confidence = 0.25 ,
102- iou_threshold = 0.45 ,
103- max_detections = 100 ,
115+ coins_counting_image_torch , confidence = 0.25 , iou_threshold = 0.45
104116 )
105117
106- # then
107- assert isinstance (predictions , list )
108118 assert len (predictions ) == 1
109119 assert predictions [0 ].xyxy .shape [1 ] == 4
110- assert predictions [0 ].xyxy .dtype == torch .int32
111120 assert len (predictions [0 ].confidence ) > 0
112121 assert torch .all (predictions [0 ].confidence >= 0.25 )
113122
114123
115124@pytest .mark .slow
116125@pytest .mark .onnx_extras
117- def test_onnx_high_confidence_threshold_returns_fewer_detections (
118- coin_counting_yololite_n_onnx_dynamic_bs_letterbox_package : str ,
126+ def test_dynamic_non_fused_high_confidence_returns_fewer (
127+ coin_counting_yololite_edge_n_onnx_dynamic_bs_stretch_package : str ,
119128 coins_counting_image_numpy : np .ndarray ,
120129) -> None :
121- # given
122130 from inference_models .models .yololite .yololite_object_detection_onnx import (
123131 YOLOLiteForObjectDetectionOnnx ,
124132 )
125133
126134 model = YOLOLiteForObjectDetectionOnnx .from_pretrained (
127- model_name_or_path = coin_counting_yololite_n_onnx_dynamic_bs_letterbox_package ,
135+ model_name_or_path = coin_counting_yololite_edge_n_onnx_dynamic_bs_stretch_package ,
128136 onnx_execution_providers = ["CUDAExecutionProvider" , "CPUExecutionProvider" ],
129137 )
138+ low = model (coins_counting_image_numpy , confidence = 0.1 , iou_threshold = 0.45 )
139+ high = model (coins_counting_image_numpy , confidence = 0.8 , iou_threshold = 0.45 )
140+
141+ assert len (low [0 ].confidence ) >= len (high [0 ].confidence )
142+
143+
144+ @pytest .mark .slow
145+ @pytest .mark .onnx_extras
146+ def test_dynamic_non_fused_class_agnostic_nms (
147+ coin_counting_yololite_edge_n_onnx_dynamic_bs_stretch_package : str ,
148+ coins_counting_image_numpy : np .ndarray ,
149+ ) -> None :
150+ from inference_models .models .yololite .yololite_object_detection_onnx import (
151+ YOLOLiteForObjectDetectionOnnx ,
152+ )
130153
131- # when
132- low_conf_predictions = model (
133- coins_counting_image_numpy , confidence = 0.1 , iou_threshold = 0.45
154+ model = YOLOLiteForObjectDetectionOnnx . from_pretrained (
155+ model_name_or_path = coin_counting_yololite_edge_n_onnx_dynamic_bs_stretch_package ,
156+ onnx_execution_providers = [ "CUDAExecutionProvider" , "CPUExecutionProvider" ],
134157 )
135- high_conf_predictions = model (
136- coins_counting_image_numpy , confidence = 0.8 , iou_threshold = 0.45
158+ standard = model (
159+ coins_counting_image_numpy , confidence = 0.25 , iou_threshold = 0.45 ,
160+ class_agnostic_nms = False ,
161+ )
162+ agnostic = model (
163+ coins_counting_image_numpy , confidence = 0.25 , iou_threshold = 0.45 ,
164+ class_agnostic_nms = True ,
137165 )
138166
139- # then
140- assert len (low_conf_predictions [0 ].confidence ) >= len (
141- high_conf_predictions [0 ].confidence
167+ assert len (agnostic [0 ].confidence ) <= len (standard [0 ].confidence )
168+
169+
170+ # ── NMS-fused ────────────────────────────────────────────────────────────────
171+
172+
173+ @pytest .mark .slow
174+ @pytest .mark .onnx_extras
175+ def test_fused_nms_numpy (
176+ coin_counting_yololite_edge_n_onnx_dynamic_bs_stretch_fused_nms_package : str ,
177+ coins_counting_image_numpy : np .ndarray ,
178+ ) -> None :
179+ from inference_models .models .yololite .yololite_object_detection_onnx import (
180+ YOLOLiteForObjectDetectionOnnx ,
181+ )
182+
183+ model = YOLOLiteForObjectDetectionOnnx .from_pretrained (
184+ model_name_or_path = coin_counting_yololite_edge_n_onnx_dynamic_bs_stretch_fused_nms_package ,
185+ onnx_execution_providers = ["CUDAExecutionProvider" , "CPUExecutionProvider" ],
142186 )
187+ predictions = model (coins_counting_image_numpy , confidence = 0.25 )
188+
189+ assert len (predictions ) == 1
190+ assert predictions [0 ].xyxy .shape [1 ] == 4
191+ assert predictions [0 ].xyxy .dtype == torch .int32
192+ assert len (predictions [0 ].confidence ) > 0
193+ assert torch .all (predictions [0 ].confidence >= 0.25 )
194+ assert torch .all (predictions [0 ].confidence <= 1.0 )
143195
144196
145197@pytest .mark .slow
146198@pytest .mark .onnx_extras
147- def test_onnx_class_agnostic_nms (
148- coin_counting_yololite_n_onnx_dynamic_bs_letterbox_package : str ,
199+ def test_fused_nms_batch_numpy (
200+ coin_counting_yololite_edge_n_onnx_dynamic_bs_stretch_fused_nms_package : str ,
149201 coins_counting_image_numpy : np .ndarray ,
150202) -> None :
151- # given
152203 from inference_models .models .yololite .yololite_object_detection_onnx import (
153204 YOLOLiteForObjectDetectionOnnx ,
154205 )
155206
156207 model = YOLOLiteForObjectDetectionOnnx .from_pretrained (
157- model_name_or_path = coin_counting_yololite_n_onnx_dynamic_bs_letterbox_package ,
208+ model_name_or_path = coin_counting_yololite_edge_n_onnx_dynamic_bs_stretch_fused_nms_package ,
158209 onnx_execution_providers = ["CUDAExecutionProvider" , "CPUExecutionProvider" ],
159210 )
211+ predictions = model (
212+ [coins_counting_image_numpy , coins_counting_image_numpy ], confidence = 0.25 ,
213+ )
160214
161- # when
162- standard_predictions = model (
163- coins_counting_image_numpy ,
164- confidence = 0.25 ,
165- iou_threshold = 0.45 ,
166- class_agnostic_nms = False ,
215+ assert len (predictions ) == 2
216+ for pred in predictions :
217+ assert pred .xyxy .shape [1 ] == 4
218+ assert len (pred .confidence ) > 0
219+ assert torch .all (pred .confidence >= 0.25 )
220+ assert predictions [0 ].xyxy .shape == predictions [1 ].xyxy .shape
221+ assert torch .allclose (
222+ predictions [0 ].confidence , predictions [1 ].confidence , atol = 0.01
167223 )
168- agnostic_predictions = model (
169- coins_counting_image_numpy ,
170- confidence = 0.25 ,
171- iou_threshold = 0.45 ,
172- class_agnostic_nms = True ,
224+
225+
226+ @pytest .mark .slow
227+ @pytest .mark .onnx_extras
228+ def test_fused_nms_high_confidence_returns_fewer (
229+ coin_counting_yololite_edge_n_onnx_dynamic_bs_stretch_fused_nms_package : str ,
230+ coins_counting_image_numpy : np .ndarray ,
231+ ) -> None :
232+ from inference_models .models .yololite .yololite_object_detection_onnx import (
233+ YOLOLiteForObjectDetectionOnnx ,
173234 )
174235
175- # then - class-agnostic NMS should suppress more overlapping boxes
176- assert len ( agnostic_predictions [ 0 ]. confidence ) <= len (
177- standard_predictions [ 0 ]. confidence
236+ model = YOLOLiteForObjectDetectionOnnx . from_pretrained (
237+ model_name_or_path = coin_counting_yololite_edge_n_onnx_dynamic_bs_stretch_fused_nms_package ,
238+ onnx_execution_providers = [ "CUDAExecutionProvider" , "CPUExecutionProvider" ],
178239 )
240+ low = model (coins_counting_image_numpy , confidence = 0.1 )
241+ high = model (coins_counting_image_numpy , confidence = 0.8 )
242+
243+ assert len (low [0 ].confidence ) >= len (high [0 ].confidence )
0 commit comments