DawnC commited on
Commit
bede3ac
1 Parent(s): e669b52

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +6 -5
app.py CHANGED
@@ -195,7 +195,7 @@ async def predict_single_dog(image):
195
 
196
  # return dogs
197
 
198
- async def detect_multiple_dogs(image, conf_threshold=0.35, iou_threshold=0.55):
199
  results = model_yolo(image, conf=conf_threshold, iou=iou_threshold)[0]
200
  dogs = []
201
  boxes = []
@@ -221,7 +221,6 @@ async def detect_multiple_dogs(image, conf_threshold=0.35, iou_threshold=0.55):
221
  return dogs
222
 
223
  def is_valid_dog(image):
224
- # 將PIL Image轉換為numpy陣列
225
  img_array = np.array(image)
226
 
227
  # 1. 簡單的紋理檢測
@@ -235,11 +234,13 @@ def is_valid_dog(image):
235
  colors = kmeans.cluster_centers_
236
  color_variety = np.std(colors)
237
 
238
- # 3. 形狀檢測(簡化版,檢查長寬比)
239
  aspect_ratio = image.width / image.height
 
240
 
241
- # 根據特徵綜合判斷
242
- if texture > 10 and color_variety > 30 and 0.5 < aspect_ratio < 2:
 
243
  return True
244
  return False
245
 
 
195
 
196
  # return dogs
197
 
198
+ async def detect_multiple_dogs(image, conf_threshold=0.25, iou_threshold=0.6):
199
  results = model_yolo(image, conf=conf_threshold, iou=iou_threshold)[0]
200
  dogs = []
201
  boxes = []
 
221
  return dogs
222
 
223
  def is_valid_dog(image):
 
224
  img_array = np.array(image)
225
 
226
  # 1. 簡單的紋理檢測
 
234
  colors = kmeans.cluster_centers_
235
  color_variety = np.std(colors)
236
 
237
+ # 3. 形狀檢測(檢查長寬比和面積)
238
  aspect_ratio = image.width / image.height
239
+ area_ratio = (image.width * image.height) / (image.width * image.height)
240
 
241
+ # 放寬判斷條件
242
+ if (texture > 5 and color_variety > 20 and
243
+ 0.3 < aspect_ratio < 3 and area_ratio > 0.05):
244
  return True
245
  return False
246