anujakkulkarni commited on
Commit
b6787a3
·
verified ·
1 Parent(s): cf85638

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +15 -7
app.py CHANGED
@@ -11,10 +11,11 @@ from concurrent.futures import ThreadPoolExecutor, as_completed, TimeoutError
11
  # -------------------- CONFIG --------------------
12
  model_paths = {
13
  "pores": "pores.pt",
14
- "newpig": "newpig.pt",
15
  "wrinkle": "wrinkle.pt",
16
  }
17
  default_conf_threshold = 0.05
 
18
  imgsz = 1024
19
 
20
  # -------------------- INIT --------------------
@@ -77,7 +78,12 @@ def detect_skin_type_from_image(img):
77
 
78
  # -------------------- HELPERS --------------------
79
  def run_model(model_name, model, img, face_polygon, face_area):
80
- conf = 0.03 if model_name == "newpig" else default_conf_threshold
 
 
 
 
 
81
  results = model(img, conf=conf, imgsz=imgsz)
82
  boxes_xy = results[0].boxes.xyxy.cpu().numpy()
83
  boxes_cls = results[0].boxes.cls.cpu().numpy().astype(int)
@@ -86,7 +92,9 @@ def run_model(model_name, model, img, face_polygon, face_area):
86
 
87
  for i, cls_id in enumerate(boxes_cls):
88
  cls_name = model.names.get(cls_id, str(cls_id)).lower()
89
- if model_name == "newpig" and cls_name in ["pores", "wrinkle"]:
 
 
90
  continue
91
 
92
  x1, y1, x2, y2 = boxes_xy[i].astype(int)
@@ -98,10 +106,10 @@ def run_model(model_name, model, img, face_polygon, face_area):
98
 
99
  skin_percentages = {name.lower(): 0.0 for name in model.names.values()}
100
 
101
- if model_name == "newpig":
102
- for dup in ["pores", "wrinkle"]:
103
- if dup in skin_percentages:
104
- skin_percentages.pop(dup)
105
 
106
  for cls_id, polys in class_polygons.items():
107
  union_poly = unary_union(polys)
 
11
  # -------------------- CONFIG --------------------
12
  model_paths = {
13
  "pores": "pores.pt",
14
+ "combine": "combine.pt", # ✅ replaced newpig with combine
15
  "wrinkle": "wrinkle.pt",
16
  }
17
  default_conf_threshold = 0.05
18
+ combine_conf_threshold = 0.08 # ✅ special threshold for combine.pt
19
  imgsz = 1024
20
 
21
  # -------------------- INIT --------------------
 
78
 
79
  # -------------------- HELPERS --------------------
80
  def run_model(model_name, model, img, face_polygon, face_area):
81
+ # set special conf threshold for combine.pt
82
+ if model_name == "combine":
83
+ conf = combine_conf_threshold
84
+ else:
85
+ conf = default_conf_threshold
86
+
87
  results = model(img, conf=conf, imgsz=imgsz)
88
  boxes_xy = results[0].boxes.xyxy.cpu().numpy()
89
  boxes_cls = results[0].boxes.cls.cpu().numpy().astype(int)
 
92
 
93
  for i, cls_id in enumerate(boxes_cls):
94
  cls_name = model.names.get(cls_id, str(cls_id)).lower()
95
+
96
+ # ✅ Ignore wrinkles from combine.pt
97
+ if model_name == "combine" and cls_name == "wrinkle":
98
  continue
99
 
100
  x1, y1, x2, y2 = boxes_xy[i].astype(int)
 
106
 
107
  skin_percentages = {name.lower(): 0.0 for name in model.names.values()}
108
 
109
+ # Remove wrinkle from combine model output completely
110
+ if model_name == "combine":
111
+ if "wrinkle" in skin_percentages:
112
+ skin_percentages.pop("wrinkle")
113
 
114
  for cls_id, polys in class_polygons.items():
115
  union_poly = unary_union(polys)