jatamura commited on
Commit
641c00f
·
verified ·
1 Parent(s): 27af8e6

Update python_utils/get_model.py

Browse files
Files changed (1) hide show
  1. python_utils/get_model.py +3 -15
python_utils/get_model.py CHANGED
@@ -35,29 +35,17 @@ def load_model():
35
 
36
  def mask_nms(masks, scores, nms_threshold=0.5):
37
  import supervision as sv
38
- from shapely.geometry.polygon import Polygon
39
 
40
- polygons = []
41
- for mask in masks:
42
- contour = sv.mask_to_polygons(mask)
43
- if len(contour) > 0:
44
- polygons.append(Polygon(contour[0]))
45
- else:
46
- polygons.append(Polygon([]))
47
  order = sorted(range(len(scores)), key=lambda i: scores[i], reverse=True)
48
  keep = []
49
  while order:
50
  i = order.pop(0)
51
  keep.append(i)
52
  for j in order:
53
- # Calculate the IoU between the two polygons
54
- intersection = polygons[i].intersection(polygons[j]).area
55
- union = polygons[i].union(polygons[j]).area
56
- iou = intersection / union
57
 
58
- # intersection = masks[i] * masks[j]
59
- # union = masks[i] + masks[j]
60
- # iou = intersection.sum() / union.sum()
61
 
62
  # Remove masks with IoU greater than the threshold
63
  if iou > nms_threshold:
 
35
 
36
  def mask_nms(masks, scores, nms_threshold=0.5):
37
  import supervision as sv
 
38
 
 
 
 
 
 
 
 
39
  order = sorted(range(len(scores)), key=lambda i: scores[i], reverse=True)
40
  keep = []
41
  while order:
42
  i = order.pop(0)
43
  keep.append(i)
44
  for j in order:
 
 
 
 
45
 
46
+ intersection = masks[i] * masks[j]
47
+ union = masks[i] + masks[j]
48
+ iou = intersection.sum() / union.sum()
49
 
50
  # Remove masks with IoU greater than the threshold
51
  if iou > nms_threshold: