Upload folder using huggingface_hub
Browse files- miner.py +26 -3
- weights.onnx +2 -2
miner.py
CHANGED
|
@@ -72,7 +72,7 @@ class Miner:
|
|
| 72 |
self.input_width = self._safe_dim(self.input_shape[3], default=1280)
|
| 73 |
|
| 74 |
self.conf_thres = 0.25
|
| 75 |
-
self.iou_thres = 0.
|
| 76 |
self.max_det = 300
|
| 77 |
|
| 78 |
print(f"✅ ONNX model loaded from: {model_path}")
|
|
@@ -265,7 +265,7 @@ class Miner:
|
|
| 265 |
"""
|
| 266 |
orig_h, orig_w = image.shape[:2]
|
| 267 |
|
| 268 |
-
|
| 269 |
|
| 270 |
img, ratio, pad = self._letterbox(
|
| 271 |
image, (self.input_width, self.input_height)
|
|
@@ -369,13 +369,36 @@ class Miner:
|
|
| 369 |
boxes /= ratio
|
| 370 |
boxes = self._clip_boxes(boxes, (orig_w, orig_h))
|
| 371 |
|
| 372 |
-
#
|
| 373 |
if apply_optional_dedup and len(boxes) > 1:
|
| 374 |
keep_idx = self._nms(boxes, scores, self.iou_thres)
|
| 375 |
boxes = boxes[keep_idx]
|
| 376 |
scores = scores[keep_idx]
|
| 377 |
cls_ids = cls_ids[keep_idx]
|
| 378 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 379 |
results: list[BoundingBox] = []
|
| 380 |
for box, conf, cls_id in zip(boxes, scores, cls_ids):
|
| 381 |
x1, y1, x2, y2 = box.tolist()
|
|
|
|
| 72 |
self.input_width = self._safe_dim(self.input_shape[3], default=1280)
|
| 73 |
|
| 74 |
self.conf_thres = 0.25
|
| 75 |
+
self.iou_thres = 0.45
|
| 76 |
self.max_det = 300
|
| 77 |
|
| 78 |
print(f"✅ ONNX model loaded from: {model_path}")
|
|
|
|
| 265 |
"""
|
| 266 |
orig_h, orig_w = image.shape[:2]
|
| 267 |
|
| 268 |
+
image = self._enhance_image(image)
|
| 269 |
|
| 270 |
img, ratio, pad = self._letterbox(
|
| 271 |
image, (self.input_width, self.input_height)
|
|
|
|
| 369 |
boxes /= ratio
|
| 370 |
boxes = self._clip_boxes(boxes, (orig_w, orig_h))
|
| 371 |
|
| 372 |
+
# Dedup: standard NMS + containment check
|
| 373 |
if apply_optional_dedup and len(boxes) > 1:
|
| 374 |
keep_idx = self._nms(boxes, scores, self.iou_thres)
|
| 375 |
boxes = boxes[keep_idx]
|
| 376 |
scores = scores[keep_idx]
|
| 377 |
cls_ids = cls_ids[keep_idx]
|
| 378 |
|
| 379 |
+
# Remove boxes where a smaller box is mostly contained in a larger one
|
| 380 |
+
if len(boxes) > 1:
|
| 381 |
+
keep = np.ones(len(boxes), dtype=bool)
|
| 382 |
+
areas = (boxes[:, 2] - boxes[:, 0]) * (boxes[:, 3] - boxes[:, 1])
|
| 383 |
+
for i in range(len(boxes)):
|
| 384 |
+
if not keep[i]:
|
| 385 |
+
continue
|
| 386 |
+
for j in range(i + 1, len(boxes)):
|
| 387 |
+
if not keep[j]:
|
| 388 |
+
continue
|
| 389 |
+
xx1 = np.maximum(boxes[i, 0], boxes[j, 0])
|
| 390 |
+
yy1 = np.maximum(boxes[i, 1], boxes[j, 1])
|
| 391 |
+
xx2 = np.minimum(boxes[i, 2], boxes[j, 2])
|
| 392 |
+
yy2 = np.minimum(boxes[i, 3], boxes[j, 3])
|
| 393 |
+
inter = max(0.0, xx2 - xx1) * max(0.0, yy2 - yy1)
|
| 394 |
+
smaller_area = min(areas[i], areas[j])
|
| 395 |
+
if smaller_area > 0 and inter / smaller_area > 0.6:
|
| 396 |
+
victim = j if scores[i] >= scores[j] else i
|
| 397 |
+
keep[victim] = False
|
| 398 |
+
boxes = boxes[keep]
|
| 399 |
+
scores = scores[keep]
|
| 400 |
+
cls_ids = cls_ids[keep]
|
| 401 |
+
|
| 402 |
results: list[BoundingBox] = []
|
| 403 |
for box, conf, cls_id in zip(boxes, scores, cls_ids):
|
| 404 |
x1, y1, x2, y2 = box.tolist()
|
weights.onnx
CHANGED
|
@@ -1,3 +1,3 @@
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
-
oid sha256:
|
| 3 |
-
size
|
|
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:be6e4b7e468f655482d0f73509954721601eacb68d376d8191a14bdb7f3d3105
|
| 3 |
+
size 19404973
|