Spaces:
Sleeping
Sleeping
Update sam_module.py
Browse files- sam_module.py +8 -4
sam_module.py
CHANGED
|
@@ -808,10 +808,14 @@ def create_sam_mask(self, image, bbox_coords, mode):
|
|
| 808 |
print(f" • Kompaktheits-Score: {compactness_score:.3f}")
|
| 809 |
|
| 810 |
# 3. BBOX-ÜBERLAPPUNG (20%)
|
| 811 |
-
bbox_mask = np.zeros((
|
| 812 |
-
bbox_mask[
|
| 813 |
-
|
| 814 |
bbox_overlap_ratio = overlap / mask_area_pixels if mask_area_pixels > 0 else 0
|
|
|
|
|
|
|
|
|
|
|
|
|
| 815 |
|
| 816 |
# Für Kopf: Sollte großteils in BBox sein (mind. 70%)
|
| 817 |
if bbox_overlap_ratio >= 0.7:
|
|
@@ -850,7 +854,7 @@ def create_sam_mask(self, image, bbox_coords, mode):
|
|
| 850 |
print(f"✅ Beste Maske ausgewählt: Nr. {best_mask_idx+1} mit Score {best_score:.3f}")
|
| 851 |
|
| 852 |
# Beste Maske verwenden
|
| 853 |
-
mask_np =
|
| 854 |
max_val = mask_np.max()
|
| 855 |
print(f"🔍 Maximaler SAM-Konfidenzwert der besten Maske: {max_val:.3f}")
|
| 856 |
|
|
|
|
| 808 |
print(f" • Kompaktheits-Score: {compactness_score:.3f}")
|
| 809 |
|
| 810 |
# 3. BBOX-ÜBERLAPPUNG (20%)
|
| 811 |
+
bbox_mask = np.zeros((original_image.height, original_image.width), dtype=np.uint8)
|
| 812 |
+
bbox_mask[original_bbox[1]:original_bbox[3], original_bbox[0]:original_bbox[2]] = 1
|
| 813 |
+
overlap = np.sum(mask_binary & bbox_mask)
|
| 814 |
bbox_overlap_ratio = overlap / mask_area_pixels if mask_area_pixels > 0 else 0
|
| 815 |
+
|
| 816 |
+
print(f" 🔍 Maske {i+1}: Fläche={mask_area_pixels:,}px, "
|
| 817 |
+
f"Überlappung={overlap:,}px ({bbox_overlap_ratio:.1%})")
|
| 818 |
+
|
| 819 |
|
| 820 |
# Für Kopf: Sollte großteils in BBox sein (mind. 70%)
|
| 821 |
if bbox_overlap_ratio >= 0.7:
|
|
|
|
| 854 |
print(f"✅ Beste Maske ausgewählt: Nr. {best_mask_idx+1} mit Score {best_score:.3f}")
|
| 855 |
|
| 856 |
# Beste Maske verwenden
|
| 857 |
+
mask_np = all_masks_crop[best_mask_idx]
|
| 858 |
max_val = mask_np.max()
|
| 859 |
print(f"🔍 Maximaler SAM-Konfidenzwert der besten Maske: {max_val:.3f}")
|
| 860 |
|