Spaces:
Sleeping
Sleeping
Sergey Kolbin
commited on
Commit
·
98de2f1
1
Parent(s):
d384e64
mn
Browse files
app.py
CHANGED
|
@@ -115,8 +115,8 @@ def count_big_cats(img, score_threshold, iou_threshold, model_id):
|
|
| 115 |
detector = get_detector(model_id)
|
| 116 |
raw = detector(img, candidate_labels=CANDIDATE_LABELS)
|
| 117 |
|
| 118 |
-
#
|
| 119 |
-
preds =
|
| 120 |
for p in raw:
|
| 121 |
if p["score"] < score_threshold:
|
| 122 |
continue
|
|
@@ -124,11 +124,10 @@ def count_big_cats(img, score_threshold, iou_threshold, model_id):
|
|
| 124 |
if canon is None:
|
| 125 |
continue
|
| 126 |
q = dict(p)
|
| 127 |
-
q["label"] = canon
|
| 128 |
preds.append(q)
|
| 129 |
|
| 130 |
-
# NMS per canonical class
|
| 131 |
-
iou_threshold = iou_threshold
|
| 132 |
preds = class_aware_nms(preds, iou_thresh=iou_threshold)
|
| 133 |
|
| 134 |
tiger_count = sum(1 for p in preds if p["label"] == "tiger")
|
|
@@ -138,6 +137,7 @@ def count_big_cats(img, score_threshold, iou_threshold, model_id):
|
|
| 138 |
img_annotated = annotate(img.copy(), preds)
|
| 139 |
return tiger_count, lion_count, total_count, img_annotated
|
| 140 |
|
|
|
|
| 141 |
# ---------- Demo ----------
|
| 142 |
TEST_IMAGES = {
|
| 143 |
"Tigers": "examples/tiger1.png",
|
|
|
|
| 115 |
detector = get_detector(model_id)
|
| 116 |
raw = detector(img, candidate_labels=CANDIDATE_LABELS)
|
| 117 |
|
| 118 |
+
# 1) Filter by score and canonicalize labels to {"tiger","lion"}
|
| 119 |
+
preds = []
|
| 120 |
for p in raw:
|
| 121 |
if p["score"] < score_threshold:
|
| 122 |
continue
|
|
|
|
| 124 |
if canon is None:
|
| 125 |
continue
|
| 126 |
q = dict(p)
|
| 127 |
+
q["label"] = canon # overwrite with canonical
|
| 128 |
preds.append(q)
|
| 129 |
|
| 130 |
+
# 2) NMS per canonical class (avoids double-counting synonyms like "toy tiger")
|
|
|
|
| 131 |
preds = class_aware_nms(preds, iou_thresh=iou_threshold)
|
| 132 |
|
| 133 |
tiger_count = sum(1 for p in preds if p["label"] == "tiger")
|
|
|
|
| 137 |
img_annotated = annotate(img.copy(), preds)
|
| 138 |
return tiger_count, lion_count, total_count, img_annotated
|
| 139 |
|
| 140 |
+
|
| 141 |
# ---------- Demo ----------
|
| 142 |
TEST_IMAGES = {
|
| 143 |
"Tigers": "examples/tiger1.png",
|