Update controlnet_module.py
Browse files- controlnet_module.py +14 -1
controlnet_module.py
CHANGED
|
@@ -224,8 +224,21 @@ class ControlNetProcessor:
|
|
| 224 |
# 6. In NumPy konvertieren und Schwellenwert anwenden
|
| 225 |
mask_np = final_mask.sigmoid().cpu().numpy()
|
| 226 |
print(f" Nach Sigmoid und CPU: {mask_np.shape}, Wertebereich: [{mask_np.min():.3f}, {mask_np.max():.3f}]")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 227 |
|
| 228 |
-
mask_array = (mask_np > 0.9).astype(np.uint8) * 255
|
| 229 |
unique_vals = np.unique(mask_array)
|
| 230 |
print(f" Nach Threshold (0.9): {mask_array.shape}, Unique Werte: {unique_vals}")
|
| 231 |
|
|
|
|
| 224 |
# 6. In NumPy konvertieren und Schwellenwert anwenden
|
| 225 |
mask_np = final_mask.sigmoid().cpu().numpy()
|
| 226 |
print(f" Nach Sigmoid und CPU: {mask_np.shape}, Wertebereich: [{mask_np.min():.3f}, {mask_np.max():.3f}]")
|
| 227 |
+
|
| 228 |
+
|
| 229 |
+
# VERWENDEN SIE:
|
| 230 |
+
# 1. Finde den maximalen Wert in mask_np
|
| 231 |
+
max_val = mask_np.max()
|
| 232 |
+
print(f" 🔍 Maximaler SAM-Konfidenzwert: {max_val:.3f}")
|
| 233 |
+
|
| 234 |
+
# 2. Setze Threshold auf 80% des Maximalwerts (oder einen anderen Prozentsatz)
|
| 235 |
+
dynamic_threshold = max_val * 0.8
|
| 236 |
+
print(f" 🎯 Dynamischer Threshold: {dynamic_threshold:.3f} (80% von Maximum)")
|
| 237 |
+
|
| 238 |
+
# 3. Anwenden
|
| 239 |
+
mask_array = (mask_np > dynamic_threshold).astype(np.uint8) * 255
|
| 240 |
|
| 241 |
+
#mask_array = (mask_np > 0.9).astype(np.uint8) * 255
|
| 242 |
unique_vals = np.unique(mask_array)
|
| 243 |
print(f" Nach Threshold (0.9): {mask_array.shape}, Unique Werte: {unique_vals}")
|
| 244 |
|