Astridkraft commited on
Commit
698ba41
·
verified ·
1 Parent(s): d02ccbc

Update sam_module.py

Browse files
Files changed (1) hide show
  1. sam_module.py +17 -0
sam_module.py CHANGED
@@ -343,7 +343,24 @@ def create_sam_mask(self, image, bbox_coords, mode):
343
  outputs = self.sam_model(**inputs)
344
  print(f"✅ Vorhersage abgeschlossen")
345
  print(f" Anzahl der Vorhersagemasken: {outputs.pred_masks.shape[2]}")
 
346
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
347
  # BBox-Information für Heuristik
348
  bbox_center = ((x1 + x2) // 2, (y1 + y2) // 2)
349
  bbox_area = (x2 - x1) * (y2 - y1)
 
343
  outputs = self.sam_model(**inputs)
344
  print(f"✅ Vorhersage abgeschlossen")
345
  print(f" Anzahl der Vorhersagemasken: {outputs.pred_masks.shape[2]}")
346
+
347
 
348
+ #Sammlung der Masken
349
+ all_masks = []
350
+
351
+ for i in range(num_masks):
352
+ single_mask = outputs.pred_masks[:, :, i, :, :]
353
+ resized_mask = F.interpolate(
354
+ single_mask,
355
+ size=(image.height, image.width),
356
+ mode='bilinear',
357
+ align_corners=False
358
+ ).squeeze()
359
+
360
+ mask_np = resized_mask.sigmoid().cpu().numpy()
361
+ all_masks.append(mask_np)
362
+
363
+
364
  # BBox-Information für Heuristik
365
  bbox_center = ((x1 + x2) // 2, (y1 + y2) // 2)
366
  bbox_area = (x2 - x1) * (y2 - y1)