johnlockejrr commited on
Commit
c4194df
·
verified ·
1 Parent(s): 2953294

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +9 -9
app.py CHANGED
@@ -51,17 +51,17 @@ def detect_and_annotate(
51
  masks = None
52
  if results.masks is not None:
53
  masks = results.masks.data.cpu().numpy()
 
 
 
54
  # Resize masks to match original image dimensions
55
  h, w = image.shape[:2]
56
- masks = [
57
- cv2.resize(mask.astype(float), (w, h),
58
- interpolation=cv2.INTER_LINEAR
59
- ).astype(bool)
60
- for mask in masks
61
- ]
62
- masks = np.array(masks)
63
- # Transpose to (H, W, num_masks)
64
- masks = np.transpose(masks, (1, 2, 0))
65
 
66
  # Create Detections object
67
  detections = sv.Detections(
 
51
  masks = None
52
  if results.masks is not None:
53
  masks = results.masks.data.cpu().numpy()
54
+ # Reshape masks to (num_masks, H, W)
55
+ masks = np.transpose(masks, (1, 2, 0)) # From (H, W, num_masks) to (num_masks, H, W)
56
+
57
  # Resize masks to match original image dimensions
58
  h, w = image.shape[:2]
59
+ resized_masks = []
60
+ for mask in masks:
61
+ resized_mask = cv2.resize(mask.astype(float), (w, h), interpolation=cv2.INTER_LINEAR)
62
+ resized_masks.append(resized_mask)
63
+ masks = np.array(resized_masks)
64
+ masks = masks.astype(bool)
 
 
 
65
 
66
  # Create Detections object
67
  detections = sv.Detections(