Spaces:
Running
on
Zero
Running
on
Zero
Update app.py
Browse files
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.
|
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 >
|
|
|
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 |
|