Dref360 commited on
Commit
8b58215
1 Parent(s): afb0729

Add NMS and fix conversion

Browse files
Files changed (1) hide show
  1. app.py +6 -4
app.py CHANGED
@@ -79,11 +79,13 @@ class KeypointDetector:
79
  target_sizes=torch.tensor([(image.height, image.width)]),
80
  threshold=0.3
81
  )
 
 
82
 
83
  # Get boxes and scores for human class (index 0 in COCO dataset)
84
- boxes = results[0]["boxes"][results[0]["labels"] == 0]
85
- scores = results[0]["scores"][results[0]["labels"] == 0]
86
- return boxes.cpu().numpy(), scores.cpu().numpy()
87
 
88
  def detect_keypoints(self, image: Image.Image):
89
  """Detect keypoints in the image"""
@@ -106,7 +108,7 @@ class KeypointDetector:
106
 
107
  # Setup detections for bounding boxes
108
  detections = sv.Detections(
109
- xyxy=self.coco_to_xyxy(boxes),
110
  confidence=scores,
111
  class_id=np.array([0]*len(scores))
112
  )
 
79
  target_sizes=torch.tensor([(image.height, image.width)]),
80
  threshold=0.3
81
  )
82
+
83
+ dets = sv.Detections.from_transformers(results[0]).with_nms(0.5)
84
 
85
  # Get boxes and scores for human class (index 0 in COCO dataset)
86
+ boxes = dets.xyxy[dets.class_id == 0]
87
+ scores = dets.confidence[dets.class_id == 0]
88
+ return boxes, scores
89
 
90
  def detect_keypoints(self, image: Image.Image):
91
  """Detect keypoints in the image"""
 
108
 
109
  # Setup detections for bounding boxes
110
  detections = sv.Detections(
111
+ xyxy=boxes,
112
  confidence=scores,
113
  class_id=np.array([0]*len(scores))
114
  )