fitleech commited on
Commit
621075f
·
verified ·
1 Parent(s): 59348ca

Upload folder using huggingface_hub

Browse files
Files changed (5) hide show
  1. __pycache__/miner.cpython-312.pyc +0 -0
  2. chute_config.yml +21 -0
  3. miner.py +453 -0
  4. readme.md +4 -0
  5. weights.onnx +3 -0
__pycache__/miner.cpython-312.pyc ADDED
Binary file (30.5 kB). View file
 
chute_config.yml ADDED
@@ -0,0 +1,21 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ Image:
2
+ from_base: parachutes/python:3.12
3
+ run_command:
4
+ - pip install --upgrade setuptools wheel
5
+ - pip install 'numpy>=1.23' 'onnxruntime-gpu[cuda,cudnn]>=1.16' 'opencv-python>=4.7' 'pillow>=9.5' 'huggingface_hub>=0.19.4' 'pydantic>=2.0' 'pyyaml>=6.0' 'aiohttp>=3.9'
6
+ - pip install torch torchvision
7
+
8
+ NodeSelector:
9
+ gpu_count: 1
10
+ min_vram_gb_per_gpu: 16
11
+ max_hourly_price_per_gpu: 2
12
+ include:
13
+ - pro_6000
14
+
15
+ Chute:
16
+ timeout_seconds: 900
17
+ concurrency: 4
18
+ max_instances: 5
19
+ scaling_threshold: 0.5
20
+ shutdown_after_seconds: 288000
21
+ tee: true
miner.py ADDED
@@ -0,0 +1,453 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from pathlib import Path
2
+ import math
3
+
4
+ import cv2
5
+ import numpy as np
6
+ import onnxruntime as ort
7
+ from numpy import ndarray
8
+ from pydantic import BaseModel
9
+
10
+
11
+ class BoundingBox(BaseModel):
12
+ x1: int
13
+ y1: int
14
+ x2: int
15
+ y2: int
16
+ cls_id: int
17
+ conf: float
18
+
19
+
20
+ class TVFrameResult(BaseModel):
21
+ frame_id: int
22
+ boxes: list[BoundingBox]
23
+ keypoints: list[tuple[int, int]]
24
+
25
+
26
+ class Miner:
27
+ """ONNX Runtime miner."""
28
+
29
+ class_names = ["petrol hose", "petrol pump", "price board", "roof canopy"]
30
+ input_size = 1280
31
+ iou_thres = 0.3
32
+ soft_sigma = 0.6
33
+ max_det = 300
34
+ _conf_thres_array = np.array([0.15, 0.55, 0.35, 0.15], dtype=np.float32)
35
+
36
+ def __init__(self, path_hf_repo: Path) -> None:
37
+ model_path = path_hf_repo / "weights.onnx"
38
+ print("ORT version:", ort.__version__)
39
+
40
+ try:
41
+ ort.preload_dlls()
42
+ print("preload_dlls success")
43
+ except Exception as e:
44
+ print(f"preload_dlls failed: {e}")
45
+
46
+ print("ORT available providers BEFORE session:", ort.get_available_providers())
47
+
48
+ sess_options = ort.SessionOptions()
49
+ sess_options.graph_optimization_level = ort.GraphOptimizationLevel.ORT_ENABLE_ALL
50
+
51
+ try:
52
+ self.session = ort.InferenceSession(
53
+ str(model_path),
54
+ sess_options=sess_options,
55
+ providers=["CUDAExecutionProvider", "CPUExecutionProvider"],
56
+ )
57
+ print("Created ORT session with preferred CUDA provider list")
58
+ except Exception as e:
59
+ print(f"CUDA session creation failed, falling back to CPU: {e}")
60
+ self.session = ort.InferenceSession(
61
+ str(model_path),
62
+ sess_options=sess_options,
63
+ providers=["CPUExecutionProvider"],
64
+ )
65
+
66
+ print("ORT session providers:", self.session.get_providers())
67
+
68
+ for inp in self.session.get_inputs():
69
+ print("INPUT:", inp.name, inp.shape, inp.type)
70
+ for out in self.session.get_outputs():
71
+ print("OUTPUT:", out.name, out.shape, out.type)
72
+
73
+ self.input_name = self.session.get_inputs()[0].name
74
+ self.output_names = [output.name for output in self.session.get_outputs()]
75
+ self.input_shape = self.session.get_inputs()[0].shape
76
+
77
+ self.input_height = self._safe_dim(self.input_shape[2], default=self.input_size)
78
+ self.input_width = self._safe_dim(self.input_shape[3], default=self.input_size)
79
+
80
+ print(f"ONNX model loaded from: {model_path}")
81
+ print(f"ONNX input: name={self.input_name}, shape={self.input_shape}")
82
+ print("per-class conf: " + ", ".join(
83
+ f"{n}={t:.3f}" for n, t in zip(self.class_names,
84
+ self._conf_thres_array.tolist())))
85
+
86
+ def __repr__(self) -> str:
87
+ return (
88
+ f"ONNXRuntime(session={type(self.session).__name__}, "
89
+ f"providers={self.session.get_providers()})"
90
+ )
91
+
92
+ @staticmethod
93
+ def _safe_dim(value, default: int) -> int:
94
+ return value if isinstance(value, int) and value > 0 else default
95
+
96
+ def _letterbox(self, image: ndarray, new_shape: tuple[int, int],
97
+ color=(114, 114, 114)
98
+ ) -> tuple[ndarray, float, tuple[float, float]]:
99
+ h, w = image.shape[:2]
100
+ new_w, new_h = new_shape
101
+ ratio = min(new_w / w, new_h / h)
102
+ resized_w = int(round(w * ratio))
103
+ resized_h = int(round(h * ratio))
104
+ if (resized_w, resized_h) != (w, h):
105
+ interp = cv2.INTER_CUBIC if ratio > 1.0 else cv2.INTER_LINEAR
106
+ image = cv2.resize(image, (resized_w, resized_h), interpolation=interp)
107
+ dw = (new_w - resized_w) / 2.0
108
+ dh = (new_h - resized_h) / 2.0
109
+ left = int(round(dw - 0.1))
110
+ right = int(round(dw + 0.1))
111
+ top = int(round(dh - 0.1))
112
+ bottom = int(round(dh + 0.1))
113
+ padded = cv2.copyMakeBorder(image, top, bottom, left, right,
114
+ borderType=cv2.BORDER_CONSTANT, value=color)
115
+ return padded, ratio, (dw, dh)
116
+
117
+ def _preprocess(self, image: ndarray
118
+ ) -> tuple[np.ndarray, float, tuple[float, float],
119
+ tuple[int, int]]:
120
+ orig_h, orig_w = image.shape[:2]
121
+ img, ratio, pad = self._letterbox(image, (self.input_width, self.input_height))
122
+ img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
123
+ img = img.astype(np.float32) / 255.0
124
+ img = np.transpose(img, (2, 0, 1))[None, ...]
125
+ img = np.ascontiguousarray(img, dtype=np.float32)
126
+ return img, ratio, pad, (orig_w, orig_h)
127
+
128
+ @staticmethod
129
+ def _clip_boxes(boxes: np.ndarray, image_size: tuple[int, int]) -> np.ndarray:
130
+ w, h = image_size
131
+ boxes[:, 0] = np.clip(boxes[:, 0], 0, w - 1)
132
+ boxes[:, 1] = np.clip(boxes[:, 1], 0, h - 1)
133
+ boxes[:, 2] = np.clip(boxes[:, 2], 0, w - 1)
134
+ boxes[:, 3] = np.clip(boxes[:, 3], 0, h - 1)
135
+ return boxes
136
+
137
+ @staticmethod
138
+ def _xywh_to_xyxy(boxes: np.ndarray) -> np.ndarray:
139
+ out = np.empty_like(boxes)
140
+ out[:, 0] = boxes[:, 0] - boxes[:, 2] / 2.0
141
+ out[:, 1] = boxes[:, 1] - boxes[:, 3] / 2.0
142
+ out[:, 2] = boxes[:, 0] + boxes[:, 2] / 2.0
143
+ out[:, 3] = boxes[:, 1] + boxes[:, 3] / 2.0
144
+ return out
145
+
146
+ @staticmethod
147
+ def _hard_nms(boxes: np.ndarray, scores: np.ndarray,
148
+ iou_thresh: float) -> np.ndarray:
149
+ n = len(boxes)
150
+ if n == 0:
151
+ return np.array([], dtype=np.intp)
152
+ order = np.argsort(-scores)
153
+ keep: list[int] = []
154
+ while len(order) > 0:
155
+ i = int(order[0])
156
+ keep.append(i)
157
+ if len(order) == 1:
158
+ break
159
+ rest = order[1:]
160
+ xx1 = np.maximum(boxes[i, 0], boxes[rest, 0])
161
+ yy1 = np.maximum(boxes[i, 1], boxes[rest, 1])
162
+ xx2 = np.minimum(boxes[i, 2], boxes[rest, 2])
163
+ yy2 = np.minimum(boxes[i, 3], boxes[rest, 3])
164
+ inter = np.maximum(0.0, xx2 - xx1) * np.maximum(0.0, yy2 - yy1)
165
+ a_i = (max(0.0, boxes[i, 2] - boxes[i, 0]) *
166
+ max(0.0, boxes[i, 3] - boxes[i, 1]))
167
+ a_r = (np.maximum(0.0, boxes[rest, 2] - boxes[rest, 0]) *
168
+ np.maximum(0.0, boxes[rest, 3] - boxes[rest, 1]))
169
+ iou = inter / (a_i + a_r - inter + 1e-7)
170
+ order = rest[iou <= iou_thresh]
171
+ return np.array(keep, dtype=np.intp)
172
+
173
+ @staticmethod
174
+ def _soft_nms(boxes: np.ndarray, scores: np.ndarray,
175
+ sigma: float, score_thresh: float = 0.001
176
+ ) -> tuple[np.ndarray, np.ndarray]:
177
+ n = len(boxes)
178
+ if n == 0:
179
+ return np.array([], dtype=np.intp), np.array([], dtype=np.float32)
180
+ boxes = boxes.astype(np.float32, copy=True)
181
+ scores = scores.astype(np.float32, copy=True)
182
+ order = np.arange(n)
183
+ for i in range(n):
184
+ max_pos = i + int(np.argmax(scores[i:]))
185
+ boxes[[i, max_pos]] = boxes[[max_pos, i]]
186
+ scores[[i, max_pos]] = scores[[max_pos, i]]
187
+ order[[i, max_pos]] = order[[max_pos, i]]
188
+ if i + 1 >= n:
189
+ break
190
+ xx1 = np.maximum(boxes[i, 0], boxes[i + 1:, 0])
191
+ yy1 = np.maximum(boxes[i, 1], boxes[i + 1:, 1])
192
+ xx2 = np.minimum(boxes[i, 2], boxes[i + 1:, 2])
193
+ yy2 = np.minimum(boxes[i, 3], boxes[i + 1:, 3])
194
+ inter = np.maximum(0.0, xx2 - xx1) * np.maximum(0.0, yy2 - yy1)
195
+ a_i = max(0.0, float((boxes[i, 2] - boxes[i, 0]) *
196
+ (boxes[i, 3] - boxes[i, 1])))
197
+ a_j = (np.maximum(0.0, boxes[i + 1:, 2] - boxes[i + 1:, 0]) *
198
+ np.maximum(0.0, boxes[i + 1:, 3] - boxes[i + 1:, 1]))
199
+ iou = inter / (a_i + a_j - inter + 1e-7)
200
+ scores[i + 1:] *= np.exp(-(iou ** 2) / sigma)
201
+ mask = scores > score_thresh
202
+ return order[mask], scores[mask]
203
+
204
+ def _per_class_hard_nms(self, boxes: np.ndarray, scores: np.ndarray,
205
+ cls_ids: np.ndarray, iou_thresh: float
206
+ ) -> np.ndarray:
207
+ if len(boxes) == 0:
208
+ return np.array([], dtype=np.intp)
209
+ all_keep: list[int] = []
210
+ for c in np.unique(cls_ids):
211
+ mask = cls_ids == c
212
+ indices = np.where(mask)[0]
213
+ keep = self._hard_nms(boxes[mask], scores[mask], iou_thresh)
214
+ all_keep.extend(indices[keep].tolist())
215
+ all_keep.sort()
216
+ return np.array(all_keep, dtype=np.intp)
217
+
218
+ def _per_class_soft_nms(self, boxes: np.ndarray, scores: np.ndarray,
219
+ cls_ids: np.ndarray
220
+ ) -> tuple[np.ndarray, np.ndarray, np.ndarray]:
221
+ if len(boxes) == 0:
222
+ return boxes, scores, cls_ids
223
+ out_b: list = []
224
+ out_s: list = []
225
+ out_c: list = []
226
+ for c in np.unique(cls_ids):
227
+ mask = cls_ids == c
228
+ sub_b = boxes[mask]
229
+ sub_s = scores[mask]
230
+ sub_c = cls_ids[mask]
231
+ idx, decayed = self._soft_nms(sub_b, sub_s, self.soft_sigma)
232
+ if len(idx) == 0:
233
+ continue
234
+ out_b.append(sub_b[idx])
235
+ out_s.append(decayed)
236
+ out_c.append(sub_c[idx])
237
+ if not out_b:
238
+ return (np.empty((0, 4), dtype=np.float32),
239
+ np.empty((0,), dtype=np.float32),
240
+ np.empty((0,), dtype=cls_ids.dtype))
241
+ return (np.concatenate(out_b, axis=0),
242
+ np.concatenate(out_s, axis=0),
243
+ np.concatenate(out_c, axis=0))
244
+
245
+ @staticmethod
246
+ def _max_score_per_cluster(post_boxes: np.ndarray,
247
+ full_boxes: np.ndarray,
248
+ full_scores: np.ndarray,
249
+ iou_thresh: float) -> np.ndarray:
250
+ n = len(post_boxes)
251
+ if n == 0:
252
+ return np.empty(0, dtype=np.float32)
253
+ full_areas = (np.maximum(0.0, full_boxes[:, 2] - full_boxes[:, 0]) *
254
+ np.maximum(0.0, full_boxes[:, 3] - full_boxes[:, 1]))
255
+ out = np.empty(n, dtype=np.float32)
256
+ for i in range(n):
257
+ bi = post_boxes[i]
258
+ xx1 = np.maximum(bi[0], full_boxes[:, 0])
259
+ yy1 = np.maximum(bi[1], full_boxes[:, 1])
260
+ xx2 = np.minimum(bi[2], full_boxes[:, 2])
261
+ yy2 = np.minimum(bi[3], full_boxes[:, 3])
262
+ inter = np.maximum(0.0, xx2 - xx1) * np.maximum(0.0, yy2 - yy1)
263
+ a_i = max(0.0, float((bi[2] - bi[0]) * (bi[3] - bi[1])))
264
+ iou = inter / (a_i + full_areas - inter + 1e-7)
265
+ cluster = iou >= iou_thresh
266
+ out[i] = float(np.max(full_scores[cluster])) if np.any(cluster) else 0.0
267
+ return out
268
+
269
+ def _per_view_pipeline(self, boxes: np.ndarray, scores: np.ndarray,
270
+ cls_ids: np.ndarray
271
+ ) -> tuple[np.ndarray, np.ndarray, np.ndarray]:
272
+ if len(boxes) > 1:
273
+ boxes, scores, cls_ids = self._per_class_soft_nms(boxes, scores, cls_ids)
274
+ if len(scores) > self.max_det:
275
+ top = np.argsort(-scores)[: self.max_det]
276
+ boxes, scores, cls_ids = boxes[top], scores[top], cls_ids[top]
277
+ return boxes, scores, cls_ids
278
+
279
+ def _decode_final_dets(self, preds: np.ndarray, ratio: float,
280
+ pad: tuple[float, float],
281
+ orig_size: tuple[int, int]) -> list[BoundingBox]:
282
+ if preds.ndim == 3 and preds.shape[0] == 1:
283
+ preds = preds[0]
284
+ if preds.ndim != 2 or preds.shape[1] < 6:
285
+ raise ValueError(f"Unexpected ONNX final-det output shape: {preds.shape}")
286
+
287
+ boxes = preds[:, :4].astype(np.float32)
288
+ scores = preds[:, 4].astype(np.float32)
289
+ cls_ids = preds[:, 5].astype(np.int32)
290
+
291
+ keep = scores >= self._conf_thres_array[cls_ids]
292
+ boxes = boxes[keep]
293
+ scores = scores[keep]
294
+ cls_ids = cls_ids[keep]
295
+ if len(boxes) == 0:
296
+ return []
297
+
298
+ pad_w, pad_h = pad
299
+ boxes[:, [0, 2]] -= pad_w
300
+ boxes[:, [1, 3]] -= pad_h
301
+ boxes /= ratio
302
+ boxes = self._clip_boxes(boxes, orig_size)
303
+
304
+ boxes, scores, cls_ids = self._per_view_pipeline(boxes, scores, cls_ids)
305
+ return self._build_results(boxes, scores, cls_ids)
306
+
307
+ def _decode_raw_yolo(self, preds: np.ndarray, ratio: float,
308
+ pad: tuple[float, float],
309
+ orig_size: tuple[int, int]) -> list[BoundingBox]:
310
+ if preds.ndim != 3 or preds.shape[0] != 1:
311
+ raise ValueError(f"Unexpected raw ONNX output shape: {preds.shape}")
312
+ preds = preds[0]
313
+ if preds.shape[0] <= 16 and preds.shape[1] > preds.shape[0]:
314
+ preds = preds.T
315
+ if preds.ndim != 2 or preds.shape[1] < 5:
316
+ raise ValueError(f"Unexpected raw output shape: {preds.shape}")
317
+
318
+ boxes_xywh = preds[:, :4].astype(np.float32)
319
+ cls_part = preds[:, 4:].astype(np.float32)
320
+ if cls_part.shape[1] == 1:
321
+ scores = cls_part[:, 0]
322
+ cls_ids = np.zeros(len(scores), dtype=np.int32)
323
+ else:
324
+ cls_ids = np.argmax(cls_part, axis=1).astype(np.int32)
325
+ scores = cls_part[np.arange(len(cls_part)), cls_ids]
326
+
327
+ keep = scores >= self._conf_thres_array[cls_ids]
328
+ boxes_xywh = boxes_xywh[keep]
329
+ scores = scores[keep]
330
+ cls_ids = cls_ids[keep]
331
+ if len(boxes_xywh) == 0:
332
+ return []
333
+ boxes = self._xywh_to_xyxy(boxes_xywh)
334
+
335
+ pad_w, pad_h = pad
336
+ boxes[:, [0, 2]] -= pad_w
337
+ boxes[:, [1, 3]] -= pad_h
338
+ boxes /= ratio
339
+ boxes = self._clip_boxes(boxes, orig_size)
340
+
341
+ boxes, scores, cls_ids = self._per_view_pipeline(boxes, scores, cls_ids)
342
+ return self._build_results(boxes, scores, cls_ids)
343
+
344
+ @staticmethod
345
+ def _build_results(boxes: np.ndarray, scores: np.ndarray,
346
+ cls_ids: np.ndarray) -> list[BoundingBox]:
347
+ results: list[BoundingBox] = []
348
+ for box, conf, cls_id in zip(boxes, scores, cls_ids):
349
+ x1, y1, x2, y2 = box.tolist()
350
+ if x2 <= x1 or y2 <= y1:
351
+ continue
352
+ results.append(
353
+ BoundingBox(
354
+ x1=int(math.floor(x1)),
355
+ y1=int(math.floor(y1)),
356
+ x2=int(math.ceil(x2)),
357
+ y2=int(math.ceil(y2)),
358
+ cls_id=int(cls_id),
359
+ conf=float(conf),
360
+ )
361
+ )
362
+ return results
363
+
364
+ def _postprocess(self, output: np.ndarray, ratio: float,
365
+ pad: tuple[float, float],
366
+ orig_size: tuple[int, int]) -> list[BoundingBox]:
367
+ if output.ndim == 2 and output.shape[1] >= 6:
368
+ return self._decode_final_dets(output, ratio, pad, orig_size)
369
+ if output.ndim == 3 and output.shape[0] == 1 and output.shape[2] == 6:
370
+ return self._decode_final_dets(output, ratio, pad, orig_size)
371
+ return self._decode_raw_yolo(output, ratio, pad, orig_size)
372
+
373
+ def _predict_single(self, image: np.ndarray) -> list[BoundingBox]:
374
+ if image is None:
375
+ raise ValueError("Input image is None")
376
+ if not isinstance(image, np.ndarray):
377
+ raise TypeError(f"Input is not numpy array: {type(image)}")
378
+ if image.ndim != 3:
379
+ raise ValueError(f"Expected HWC image, got shape={image.shape}")
380
+ if image.shape[2] != 3:
381
+ raise ValueError(f"Expected 3 channels, got shape={image.shape}")
382
+ if image.dtype != np.uint8:
383
+ image = image.astype(np.uint8)
384
+
385
+ input_tensor, ratio, pad, orig_size = self._preprocess(image)
386
+ expected = (1, 3, self.input_height, self.input_width)
387
+ if input_tensor.shape != expected:
388
+ raise ValueError(
389
+ f"Bad input tensor shape={input_tensor.shape}, expected={expected}"
390
+ )
391
+
392
+ outputs = self.session.run(self.output_names, {self.input_name: input_tensor})
393
+ return self._postprocess(outputs[0], ratio, pad, orig_size)
394
+
395
+ def _predict_tta(self, image: np.ndarray) -> list[BoundingBox]:
396
+ boxes_orig = self._predict_single(image)
397
+ flipped = cv2.flip(image, 1)
398
+ boxes_flip = self._predict_single(flipped)
399
+ w = image.shape[1]
400
+ boxes_flip = [
401
+ BoundingBox(
402
+ x1=w - b.x2, y1=b.y1, x2=w - b.x1, y2=b.y2,
403
+ cls_id=b.cls_id, conf=b.conf,
404
+ )
405
+ for b in boxes_flip
406
+ ]
407
+ all_boxes = boxes_orig + boxes_flip
408
+ if not all_boxes:
409
+ return []
410
+
411
+ coords = np.array(
412
+ [[b.x1, b.y1, b.x2, b.y2] for b in all_boxes], dtype=np.float32
413
+ )
414
+ scores = np.array([b.conf for b in all_boxes], dtype=np.float32)
415
+ cls_ids = np.array([b.cls_id for b in all_boxes], dtype=np.int32)
416
+
417
+ hard_keep = self._per_class_hard_nms(coords, scores, cls_ids, self.iou_thres)
418
+ if len(hard_keep) == 0:
419
+ return []
420
+ hard_keep = hard_keep[: self.max_det]
421
+ boosted = self._max_score_per_cluster(
422
+ coords[hard_keep], coords, scores, self.iou_thres
423
+ )
424
+
425
+ return [
426
+ BoundingBox(
427
+ x1=all_boxes[i].x1,
428
+ y1=all_boxes[i].y1,
429
+ x2=all_boxes[i].x2,
430
+ y2=all_boxes[i].y2,
431
+ cls_id=all_boxes[i].cls_id,
432
+ conf=float(boosted[j]),
433
+ )
434
+ for j, i in enumerate(hard_keep)
435
+ ]
436
+
437
+ def predict_batch(self, batch_images: list[ndarray], offset: int,
438
+ n_keypoints: int) -> list[TVFrameResult]:
439
+ results: list[TVFrameResult] = []
440
+ for frame_number_in_batch, image in enumerate(batch_images):
441
+ try:
442
+ boxes = self._predict_tta(image)
443
+ except Exception as e:
444
+ print(f"Inference failed for frame {offset + frame_number_in_batch}: {e}")
445
+ boxes = []
446
+ results.append(
447
+ TVFrameResult(
448
+ frame_id=offset + frame_number_in_batch,
449
+ boxes=boxes,
450
+ keypoints=[(0, 0) for _ in range(max(0, int(n_keypoints)))],
451
+ )
452
+ )
453
+ return results
readme.md ADDED
@@ -0,0 +1,4 @@
 
 
 
 
 
1
+ # beverage-detect
2
+
3
+ YOLO26 ONNX detector for the Detect-beverage-detect element.
4
+ Classes: cup, bottle, can.
weights.onnx ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:1f8b26bf323e22151fba40afd107a20906deb880c391e1d765e053a9334b272e
3
+ size 19408156