DawnC commited on
Commit
48f9f74
·
1 Parent(s): 3393519

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +2 -2
app.py CHANGED
@@ -243,7 +243,7 @@ def soft_nms(boxes, scores, sigma=0.5, thresh=0.001, method='gaussian'):
243
 
244
  # 刪除得分低於閾值的框
245
  keep = scores > thresh
246
- boxes = boxes[keep]
247
  scores = scores[keep]
248
 
249
  return boxes, scores
@@ -265,7 +265,7 @@ async def detect_multiple_dogs(image, conf_threshold=0.35, iou_threshold=0.55):
265
  dogs.append((image, 1.0, [0, 0, image.width, image.height]))
266
  else:
267
  boxes = torch.stack(boxes)
268
- scores = torch.stack(scores)
269
  nms_boxes, nms_scores = soft_nms(boxes, scores, thresh=iou_threshold)
270
 
271
  for box, score in zip(nms_boxes, nms_scores):
 
243
 
244
  # 刪除得分低於閾值的框
245
  keep = scores > thresh
246
+ boxes = boxes[keep.squeeze(-1)] # 確保 keep 的維度與 boxes 匹配
247
  scores = scores[keep]
248
 
249
  return boxes, scores
 
265
  dogs.append((image, 1.0, [0, 0, image.width, image.height]))
266
  else:
267
  boxes = torch.stack(boxes)
268
+ scores = torch.stack(scores).squeeze(-1) # 確保 scores 是一維張量
269
  nms_boxes, nms_scores = soft_nms(boxes, scores, thresh=iou_threshold)
270
 
271
  for box, score in zip(nms_boxes, nms_scores):