Spaces:
Paused
Paused
Update app.py
Browse files
app.py
CHANGED
|
@@ -67,7 +67,7 @@ def analyze():
|
|
| 67 |
all_percentages = {}
|
| 68 |
|
| 69 |
for model_name, model in models.items():
|
| 70 |
-
#
|
| 71 |
conf = 0.03 if model_name == "newpig" else default_conf_threshold
|
| 72 |
|
| 73 |
results = model(img, conf=conf, imgsz=imgsz)
|
|
@@ -79,7 +79,7 @@ def analyze():
|
|
| 79 |
for i, cls_id in enumerate(boxes_cls):
|
| 80 |
cls_name = model.names.get(cls_id, str(cls_id))
|
| 81 |
|
| 82 |
-
# Skip pores from newpig
|
| 83 |
if model_name == "newpig" and cls_name.lower() == "pores":
|
| 84 |
continue
|
| 85 |
|
|
@@ -90,13 +90,23 @@ def analyze():
|
|
| 90 |
if intersection.area > 0:
|
| 91 |
class_polygons[cls_id].append(intersection)
|
| 92 |
|
| 93 |
-
#
|
| 94 |
-
skin_percentages = {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 95 |
for cls_id, polys in class_polygons.items():
|
| 96 |
union_poly = unary_union(polys)
|
| 97 |
pixels = union_poly.area
|
| 98 |
percentage = (pixels / face_area) * 100 if face_area > 0 else 0.0
|
| 99 |
cls_name = model.names.get(cls_id, str(cls_id))
|
|
|
|
|
|
|
| 100 |
skin_percentages[cls_name] = round(percentage, 2)
|
| 101 |
|
| 102 |
all_percentages[model_name] = skin_percentages
|
|
|
|
| 67 |
all_percentages = {}
|
| 68 |
|
| 69 |
for model_name, model in models.items():
|
| 70 |
+
# Confidence per model
|
| 71 |
conf = 0.03 if model_name == "newpig" else default_conf_threshold
|
| 72 |
|
| 73 |
results = model(img, conf=conf, imgsz=imgsz)
|
|
|
|
| 79 |
for i, cls_id in enumerate(boxes_cls):
|
| 80 |
cls_name = model.names.get(cls_id, str(cls_id))
|
| 81 |
|
| 82 |
+
# Skip pores from newpig
|
| 83 |
if model_name == "newpig" and cls_name.lower() == "pores":
|
| 84 |
continue
|
| 85 |
|
|
|
|
| 90 |
if intersection.area > 0:
|
| 91 |
class_polygons[cls_id].append(intersection)
|
| 92 |
|
| 93 |
+
# Pre-fill with 0 for all classes
|
| 94 |
+
skin_percentages = {
|
| 95 |
+
name: 0.0 for name in model.names.values()
|
| 96 |
+
}
|
| 97 |
+
|
| 98 |
+
# Remove pores from newpig
|
| 99 |
+
if model_name == "newpig" and "pores" in skin_percentages:
|
| 100 |
+
skin_percentages.pop("pores")
|
| 101 |
+
|
| 102 |
+
# Fill detected percentages
|
| 103 |
for cls_id, polys in class_polygons.items():
|
| 104 |
union_poly = unary_union(polys)
|
| 105 |
pixels = union_poly.area
|
| 106 |
percentage = (pixels / face_area) * 100 if face_area > 0 else 0.0
|
| 107 |
cls_name = model.names.get(cls_id, str(cls_id))
|
| 108 |
+
if model_name == "newpig" and cls_name.lower() == "pores":
|
| 109 |
+
continue
|
| 110 |
skin_percentages[cls_name] = round(percentage, 2)
|
| 111 |
|
| 112 |
all_percentages[model_name] = skin_percentages
|