Update controlnet_module.py
Browse files- controlnet_module.py +16 -6
controlnet_module.py
CHANGED
|
@@ -869,8 +869,11 @@ class ControlNetProcessor:
|
|
| 869 |
#=========================
|
| 870 |
|
| 871 |
# Masken speichern in den Arrays
|
| 872 |
-
all_masks_crop = [] #Weiterverarbeitung in Crop-Größe
|
| 873 |
|
|
|
|
|
|
|
|
|
|
| 874 |
# 2. FÜR VERARBEITUNG: Auf CROP-GRÖSSE interpolieren
|
| 875 |
resized_mask_crop = F.interpolate(
|
| 876 |
single_mask,
|
|
@@ -878,6 +881,7 @@ class ControlNetProcessor:
|
|
| 878 |
mode='bilinear',
|
| 879 |
align_corners=False
|
| 880 |
).squeeze()
|
|
|
|
| 881 |
mask_np = resized_mask.sigmoid().cpu().numpy()
|
| 882 |
all_masks_crop.append(mask_np)
|
| 883 |
|
|
@@ -890,12 +894,18 @@ class ControlNetProcessor:
|
|
| 890 |
# ============================================================
|
| 891 |
# HEURISTIK (zur Bestimmung der besten Maske)
|
| 892 |
# ============================================================
|
| 893 |
-
print("🤔
|
| 894 |
|
| 895 |
-
|
| 896 |
-
|
| 897 |
-
|
| 898 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 899 |
|
| 900 |
best_mask_idx = 0
|
| 901 |
best_score = -1
|
|
|
|
| 869 |
#=========================
|
| 870 |
|
| 871 |
# Masken speichern in den Arrays
|
| 872 |
+
all_masks_crop = [] #Weiterverarbeitung in Crop-Größe
|
| 873 |
|
| 874 |
+
|
| 875 |
+
for i in range(num_masks):
|
| 876 |
+
single_mask = outputs.pred_masks[:, :, i, :, :]
|
| 877 |
# 2. FÜR VERARBEITUNG: Auf CROP-GRÖSSE interpolieren
|
| 878 |
resized_mask_crop = F.interpolate(
|
| 879 |
single_mask,
|
|
|
|
| 881 |
mode='bilinear',
|
| 882 |
align_corners=False
|
| 883 |
).squeeze()
|
| 884 |
+
|
| 885 |
mask_np = resized_mask.sigmoid().cpu().numpy()
|
| 886 |
all_masks_crop.append(mask_np)
|
| 887 |
|
|
|
|
| 894 |
# ============================================================
|
| 895 |
# HEURISTIK (zur Bestimmung der besten Maske)
|
| 896 |
# ============================================================
|
| 897 |
+
print("🤔 HEURISTIK AUF CROP-GRÖSSE BERECHNEN")
|
| 898 |
|
| 899 |
+
|
| 900 |
+
# BBox-Information für Heuristik (IN CROP-KOORDINATEN!)
|
| 901 |
+
bbox_center = ((x1 + x2) // 2, (y1 + y2) // 2)
|
| 902 |
+
bbox_area = (x2 - x1) * (y2 - y1)
|
| 903 |
+
|
| 904 |
+
print(f" CROP-BBox: [{x1}, {y1}, {x2}, {y2}]")
|
| 905 |
+
print(f" CROP-BBox-Größe: {x2-x1}×{y2-y1}px = {bbox_area:,}px²")
|
| 906 |
+
print(f" CROP-BBox-Zentrum: {bbox_center}")
|
| 907 |
+
print(f" Crop-Bildgröße: {image.width}×{image.height}")
|
| 908 |
+
|
| 909 |
|
| 910 |
best_mask_idx = 0
|
| 911 |
best_score = -1
|