Spaces:
Paused
Paused
Upload manifest.py with huggingface_hub
Browse files- manifest.py +25 -2
manifest.py
CHANGED
|
@@ -1,13 +1,36 @@
|
|
| 1 |
import json
|
| 2 |
|
| 3 |
|
| 4 |
-
def
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 5 |
"""Filter accepted+labeled detections and build manifest entries."""
|
| 6 |
manifest = []
|
| 7 |
for det in detections:
|
| 8 |
if det.get("accepted") and det.get("label"):
|
| 9 |
manifest.append({
|
| 10 |
-
"image_path":
|
| 11 |
"object_id": det["id"],
|
| 12 |
"label": det["label"],
|
| 13 |
"bbox": det["box"],
|
|
|
|
| 1 |
import json
|
| 2 |
|
| 3 |
|
| 4 |
+
def _iou(box_a, box_b):
|
| 5 |
+
"""Compute intersection-over-union for two [x1, y1, x2, y2] boxes."""
|
| 6 |
+
x1 = max(box_a[0], box_b[0])
|
| 7 |
+
y1 = max(box_a[1], box_b[1])
|
| 8 |
+
x2 = min(box_a[2], box_b[2])
|
| 9 |
+
y2 = min(box_a[3], box_b[3])
|
| 10 |
+
inter = max(0, x2 - x1) * max(0, y2 - y1)
|
| 11 |
+
area_a = (box_a[2] - box_a[0]) * (box_a[3] - box_a[1])
|
| 12 |
+
area_b = (box_b[2] - box_b[0]) * (box_b[3] - box_b[1])
|
| 13 |
+
union = area_a + area_b - inter
|
| 14 |
+
return inter / union if union > 0 else 0.0
|
| 15 |
+
|
| 16 |
+
|
| 17 |
+
def deduplicate(new_dets: list[dict], existing_dets: list[dict], iou_threshold: float = 0.5) -> list[dict]:
|
| 18 |
+
"""Return only new detections that don't overlap with existing ones."""
|
| 19 |
+
unique = []
|
| 20 |
+
for new in new_dets:
|
| 21 |
+
is_dup = any(_iou(new["box"], ex["box"]) >= iou_threshold for ex in existing_dets)
|
| 22 |
+
if not is_dup:
|
| 23 |
+
unique.append(new)
|
| 24 |
+
return unique
|
| 25 |
+
|
| 26 |
+
|
| 27 |
+
def build_manifest(detections: list[dict]) -> list[dict]:
|
| 28 |
"""Filter accepted+labeled detections and build manifest entries."""
|
| 29 |
manifest = []
|
| 30 |
for det in detections:
|
| 31 |
if det.get("accepted") and det.get("label"):
|
| 32 |
manifest.append({
|
| 33 |
+
"image_path": det.get("image_path", ""),
|
| 34 |
"object_id": det["id"],
|
| 35 |
"label": det["label"],
|
| 36 |
"bbox": det["box"],
|