Update sam_module.py
Browse files- sam_module.py +7 -7
sam_module.py
CHANGED
|
@@ -76,7 +76,7 @@ def create_sam_mask(self, image, bbox_coords, mode):
|
|
| 76 |
align_corners=False
|
| 77 |
).squeeze()
|
| 78 |
|
| 79 |
-
mask_np = resized_mask.sigmoid().cpu().numpy()
|
| 80 |
all_masks.append(mask_np) #fügt die aktuelle Maske der Liste all_masks hinzu
|
| 81 |
|
| 82 |
|
|
@@ -236,7 +236,7 @@ def create_sam_mask(self, image, bbox_coords, mode):
|
|
| 236 |
mask_array = mask_array.astype(np.float32) / 255.0
|
| 237 |
print(f" Konvertiert zu Float32: Min={mask_array.min():.3f}, Max={mask_array.max():.3f}")
|
| 238 |
|
| 239 |
-
mask_array = np.clip(mask_array, 0.0, 1.0)
|
| 240 |
mask_array = mask_array ** 0.85 # Gamma-Korrektur Werte > 0.5 werden abgedunkelt, <0.5 aufgehellt-erzeugt natürliche Maskenübergänge
|
| 241 |
print(f" Nach Gamma 0.85: Min={mask_array.min():.3f}, Max={mask_array.max():.3f}")
|
| 242 |
|
|
@@ -506,7 +506,7 @@ def create_sam_mask(self, image, bbox_coords, mode):
|
|
| 506 |
print("-" * 60)
|
| 507 |
|
| 508 |
# ============================================================
|
| 509 |
-
#
|
| 510 |
# Andere Vorgehensweise da SAM bei kleinen Köpfen sonst keine Chance hat!
|
| 511 |
# Bild ausschneiden auf eine vergrößerte quadratische Box - Crops
|
| 512 |
# ============================================================
|
|
@@ -514,7 +514,7 @@ def create_sam_mask(self, image, bbox_coords, mode):
|
|
| 514 |
print(f"💾 Originalbild gesichert: {original_image.size}")
|
| 515 |
|
| 516 |
# ============================================================
|
| 517 |
-
#
|
| 518 |
# ============================================================
|
| 519 |
print("✂️ SCHRITT 2: ERSTELLE QUADRATISCHEN AUSSCHNITT (BBox × 2.5)")
|
| 520 |
|
|
@@ -570,7 +570,7 @@ def create_sam_mask(self, image, bbox_coords, mode):
|
|
| 570 |
print(f" ✅ Quadratischer Ausschnitt erstellt: {cropped_image.size}")
|
| 571 |
|
| 572 |
# ============================================================
|
| 573 |
-
#
|
| 574 |
# ============================================================
|
| 575 |
print("📐 SCHRITT 3: BBox-KOORDINATEN TRANSFORMIEREN")
|
| 576 |
rel_x1 = x1 - crop_x1
|
|
@@ -588,7 +588,7 @@ def create_sam_mask(self, image, bbox_coords, mode):
|
|
| 588 |
print(f" 📏 Relative BBox Größe: {rel_x2-rel_x1} × {rel_y2-rel_y1} px")
|
| 589 |
|
| 590 |
# ============================================================
|
| 591 |
-
#
|
| 592 |
# ============================================================
|
| 593 |
print("🔍 SCHRITT 4: ERWEITERTE BILDAUFBEREITUNG FÜR GESICHTSERKENNUNG")
|
| 594 |
|
|
@@ -617,7 +617,7 @@ def create_sam_mask(self, image, bbox_coords, mode):
|
|
| 617 |
print(f" 📊 SAM-Eingabegröße: {image.size}")
|
| 618 |
|
| 619 |
# ============================================================
|
| 620 |
-
#
|
| 621 |
# ============================================================
|
| 622 |
print("-" * 60)
|
| 623 |
print(f"📦 BOUNDING BOX DETAILS FÜR SAM:")
|
|
|
|
| 76 |
align_corners=False
|
| 77 |
).squeeze()
|
| 78 |
|
| 79 |
+
mask_np = resized_mask.sigmoid().cpu().numpy() #wandelt Modellausgaben in Wahrscheinlichkeiten und bewegt Daten von GPU nach CPU
|
| 80 |
all_masks.append(mask_np) #fügt die aktuelle Maske der Liste all_masks hinzu
|
| 81 |
|
| 82 |
|
|
|
|
| 236 |
mask_array = mask_array.astype(np.float32) / 255.0
|
| 237 |
print(f" Konvertiert zu Float32: Min={mask_array.min():.3f}, Max={mask_array.max():.3f}")
|
| 238 |
|
| 239 |
+
mask_array = np.clip(mask_array, 0.0, 1.0) #begrenzt alle Werte auf 0 und 1
|
| 240 |
mask_array = mask_array ** 0.85 # Gamma-Korrektur Werte > 0.5 werden abgedunkelt, <0.5 aufgehellt-erzeugt natürliche Maskenübergänge
|
| 241 |
print(f" Nach Gamma 0.85: Min={mask_array.min():.3f}, Max={mask_array.max():.3f}")
|
| 242 |
|
|
|
|
| 506 |
print("-" * 60)
|
| 507 |
|
| 508 |
# ============================================================
|
| 509 |
+
# Originalbild sichern
|
| 510 |
# Andere Vorgehensweise da SAM bei kleinen Köpfen sonst keine Chance hat!
|
| 511 |
# Bild ausschneiden auf eine vergrößerte quadratische Box - Crops
|
| 512 |
# ============================================================
|
|
|
|
| 514 |
print(f"💾 Originalbild gesichert: {original_image.size}")
|
| 515 |
|
| 516 |
# ============================================================
|
| 517 |
+
# Crop = BBox × 2.5 (ERHÖHT für mehr Kontext)
|
| 518 |
# ============================================================
|
| 519 |
print("✂️ SCHRITT 2: ERSTELLE QUADRATISCHEN AUSSCHNITT (BBox × 2.5)")
|
| 520 |
|
|
|
|
| 570 |
print(f" ✅ Quadratischer Ausschnitt erstellt: {cropped_image.size}")
|
| 571 |
|
| 572 |
# ============================================================
|
| 573 |
+
# BBox-Koordinaten transformieren
|
| 574 |
# ============================================================
|
| 575 |
print("📐 SCHRITT 3: BBox-KOORDINATEN TRANSFORMIEREN")
|
| 576 |
rel_x1 = x1 - crop_x1
|
|
|
|
| 588 |
print(f" 📏 Relative BBox Größe: {rel_x2-rel_x1} × {rel_y2-rel_y1} px")
|
| 589 |
|
| 590 |
# ============================================================
|
| 591 |
+
# INTENSIVE BILDAUFBEREITUNG FÜR GESICHTSERKENNUNG
|
| 592 |
# ============================================================
|
| 593 |
print("🔍 SCHRITT 4: ERWEITERTE BILDAUFBEREITUNG FÜR GESICHTSERKENNUNG")
|
| 594 |
|
|
|
|
| 617 |
print(f" 📊 SAM-Eingabegröße: {image.size}")
|
| 618 |
|
| 619 |
# ============================================================
|
| 620 |
+
# SAM-AUSFÜHRUNG
|
| 621 |
# ============================================================
|
| 622 |
print("-" * 60)
|
| 623 |
print(f"📦 BOUNDING BOX DETAILS FÜR SAM:")
|