DawnC commited on
Commit
fdb7582
·
1 Parent(s): 5654e3b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +1 -52
app.py CHANGED
@@ -167,7 +167,7 @@ async def predict_single_dog(image):
167
  return top1_prob, topk_breeds, topk_probs_percent
168
 
169
 
170
- async def detect_multiple_dogs(image, conf_threshold=0.4, iou_threshold=0.55):
171
  results = model_yolo(image, conf=conf_threshold, iou=iou_threshold)[0]
172
  dogs = []
173
  boxes = []
@@ -195,56 +195,6 @@ async def detect_multiple_dogs(image, conf_threshold=0.4, iou_threshold=0.55):
195
  return dogs
196
 
197
 
198
- # async def detect_multiple_dogs(image, conf_threshold=0.35, iou_threshold=0.5):
199
- # results = model_yolo(image, conf=conf_threshold, iou=iou_threshold)[0]
200
- # dogs = []
201
- # boxes = []
202
-
203
- # for box in results.boxes:
204
- # if box.cls == 16: # COCO dataset class for dog is 16
205
- # xyxy = box.xyxy[0].tolist()
206
- # confidence = box.conf.item()
207
- # boxes.append((xyxy, confidence))
208
-
209
- # if not boxes:
210
- # dogs.append((image, 1.0, [0, 0, image.width, image.height]))
211
- # else:
212
- # nms_boxes = non_max_suppression(boxes, iou_threshold)
213
-
214
- # for box, confidence in nms_boxes:
215
- # x1, y1, x2, y2 = [int(coord) for coord in box]
216
- # cropped_image = image.crop((x1, y1, x2, y2))
217
- # dogs.append((cropped_image, confidence, [x1, y1, x2, y2]))
218
-
219
- # # 應用過濾器來移除可能的錯誤檢測
220
- # dogs = filter_detections(dogs, (image.width, image.height))
221
-
222
- # return dogs
223
-
224
- # def filter_detections(dogs, image_size):
225
- # filtered_dogs = []
226
- # image_area = image_size[0] * image_size[1]
227
- # num_dogs = len(dogs)
228
-
229
- # # 根據檢測到的狗的數量動態調整閾值
230
- # if num_dogs > 5:
231
- # min_ratio, max_ratio = 0.003, 0.5
232
- # elif num_dogs > 2:
233
- # min_ratio, max_ratio = 0.005, 0.6
234
- # else:
235
- # min_ratio, max_ratio = 0.01, 0.7
236
-
237
- # for dog in dogs:
238
- # _, confidence, box = dog
239
- # dog_area = (box[2] - box[0]) * (box[3] - box[1])
240
- # area_ratio = dog_area / image_area
241
-
242
- # if min_ratio < area_ratio < max_ratio:
243
- # filtered_dogs.append(dog)
244
-
245
- # return filtered_dogs
246
-
247
-
248
  def non_max_suppression(boxes, iou_threshold):
249
  keep = []
250
  boxes = sorted(boxes, key=lambda x: x[1], reverse=True)
@@ -385,7 +335,6 @@ async def predict(image):
385
  return error_msg, None, gr.update(visible=False, choices=[]), None
386
 
387
 
388
-
389
  def show_details(choice, previous_output, initial_state):
390
  if not choice:
391
  return previous_output, gr.update(visible=True), initial_state
 
167
  return top1_prob, topk_breeds, topk_probs_percent
168
 
169
 
170
+ async def detect_multiple_dogs(image, conf_threshold=0.35, iou_threshold=0.55):
171
  results = model_yolo(image, conf=conf_threshold, iou=iou_threshold)[0]
172
  dogs = []
173
  boxes = []
 
195
  return dogs
196
 
197
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
198
  def non_max_suppression(boxes, iou_threshold):
199
  keep = []
200
  boxes = sorted(boxes, key=lambda x: x[1], reverse=True)
 
335
  return error_msg, None, gr.update(visible=False, choices=[]), None
336
 
337
 
 
338
  def show_details(choice, previous_output, initial_state):
339
  if not choice:
340
  return previous_output, gr.update(visible=True), initial_state