Spaces:
Running
Running
Commit ·
9432353
1
Parent(s): 2dc1b1e
conf fixed
Browse files- api/utils.py +4 -4
api/utils.py
CHANGED
|
@@ -86,7 +86,7 @@ def extract_metadata(image_bytes):
|
|
| 86 |
def process_image(image):
|
| 87 |
"""Run 3-stage detection and classification with dynamic confidence"""
|
| 88 |
detections = []
|
| 89 |
-
results = DETECT_MODEL(image,conf=0.8 ,iou=0.
|
| 90 |
for r in results:
|
| 91 |
for box in r.boxes:
|
| 92 |
x1, y1, x2, y2 = map(int, box.xyxy[0])
|
|
@@ -94,7 +94,7 @@ def process_image(image):
|
|
| 94 |
if crop.size == 0:
|
| 95 |
continue
|
| 96 |
# ---------------- Stage 2: Buck/Doe ----------------
|
| 97 |
-
buck_res = BUCK_DOE_MODEL(crop
|
| 98 |
buck_probs = buck_res[0].probs
|
| 99 |
top1_idx = buck_probs.top1
|
| 100 |
buck_name = buck_res[0].names[top1_idx]
|
|
@@ -106,11 +106,11 @@ def process_image(image):
|
|
| 106 |
top1_type_idx = type_probs.top1
|
| 107 |
type_name = type_res[0].names[top1_type_idx]
|
| 108 |
type_conf = float(type_probs.top1conf)
|
| 109 |
-
label = f"Deer | Buck | {type_name}
|
| 110 |
final_conf = type_conf
|
| 111 |
else:
|
| 112 |
# Doe: use stage 2 confidence
|
| 113 |
-
label = f"Deer | Doe
|
| 114 |
final_conf = buck_conf
|
| 115 |
detections.append({
|
| 116 |
"label": label,
|
|
|
|
| 86 |
def process_image(image):
|
| 87 |
"""Run 3-stage detection and classification with dynamic confidence"""
|
| 88 |
detections = []
|
| 89 |
+
results = DETECT_MODEL(image,conf=0.8 ,iou=0.4,agnostic_nms=True) # Stage 1: Deer detection
|
| 90 |
for r in results:
|
| 91 |
for box in r.boxes:
|
| 92 |
x1, y1, x2, y2 = map(int, box.xyxy[0])
|
|
|
|
| 94 |
if crop.size == 0:
|
| 95 |
continue
|
| 96 |
# ---------------- Stage 2: Buck/Doe ----------------
|
| 97 |
+
buck_res = BUCK_DOE_MODEL(crop)
|
| 98 |
buck_probs = buck_res[0].probs
|
| 99 |
top1_idx = buck_probs.top1
|
| 100 |
buck_name = buck_res[0].names[top1_idx]
|
|
|
|
| 106 |
top1_type_idx = type_probs.top1
|
| 107 |
type_name = type_res[0].names[top1_type_idx]
|
| 108 |
type_conf = float(type_probs.top1conf)
|
| 109 |
+
label = f"Deer | Buck | {type_name}"
|
| 110 |
final_conf = type_conf
|
| 111 |
else:
|
| 112 |
# Doe: use stage 2 confidence
|
| 113 |
+
label = f"Deer | Doe "
|
| 114 |
final_conf = buck_conf
|
| 115 |
detections.append({
|
| 116 |
"label": label,
|