Update app.py
Browse files
app.py
CHANGED
@@ -42,25 +42,34 @@ def pil_to_binary_mask(pil_image, threshold=0):
|
|
42 |
import numpy as np
|
43 |
from PIL import Image
|
44 |
|
|
|
45 |
def get_mask_location(mode, category, parsing, keypoints):
|
46 |
parsing = np.array(parsing)
|
47 |
mask = np.zeros_like(parsing)
|
48 |
|
49 |
-
print(f"Selected category: {category}")
|
|
|
50 |
|
51 |
if category == "μμ":
|
52 |
# μμμ ν΄λΉνλ λΆλΆλ§ λ§μ€νΉ (μ체, ν)
|
53 |
-
|
|
|
|
|
54 |
elif category == "νμ":
|
55 |
# νμμ ν΄λΉνλ λΆλΆλ§ λ§μ€νΉ (ν체)
|
56 |
-
|
|
|
|
|
57 |
elif category == "λλ μ€":
|
58 |
# λλ μ€μ ν΄λΉνλ λΆλΆ λ§μ€νΉ (μ체μ ν체)
|
59 |
-
|
|
|
|
|
60 |
else:
|
61 |
raise ValueError(f"Unknown category: {category}")
|
62 |
|
63 |
-
print(f"Mask shape: {mask.shape}, Unique values: {np.unique(mask)}")
|
|
|
64 |
|
65 |
mask_gray = Image.fromarray(mask)
|
66 |
return mask_gray, mask_gray
|
@@ -176,15 +185,27 @@ def start_tryon(dict, garm_img, garment_des, is_checked, is_checked_crop, denois
|
|
176 |
status_message = ""
|
177 |
if is_checked:
|
178 |
try:
|
179 |
-
print(f"Processing category: {category}")
|
180 |
keypoints = openpose_model(human_img.resize((384,512)))
|
181 |
model_parse, _ = parsing_model(human_img.resize((384,512)))
|
|
|
|
|
|
|
|
|
|
|
182 |
mask, mask_gray = get_mask_location('hd', category, model_parse, keypoints)
|
183 |
mask = mask.resize((768,1024))
|
184 |
-
print(f"Mask created for category {category}")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
185 |
except Exception as e:
|
186 |
status_message = f"μλ λ§μ€ν¬ μμ± μ€ μ€λ₯κ° λ°μνμ΅λλ€: {str(e)}. κΈ°λ³Έ λ§μ€ν¬λ₯Ό μ¬μ©ν©λλ€."
|
187 |
-
print(f"Error in mask creation: {str(e)}")
|
188 |
mask = Image.new('L', (768, 1024), 255)
|
189 |
else:
|
190 |
if dict['layers'] and dict['layers'][0]:
|
|
|
42 |
import numpy as np
|
43 |
from PIL import Image
|
44 |
|
45 |
+
|
46 |
def get_mask_location(mode, category, parsing, keypoints):
|
47 |
parsing = np.array(parsing)
|
48 |
mask = np.zeros_like(parsing)
|
49 |
|
50 |
+
print(f"Selected category: {category}")
|
51 |
+
print(f"Unique values in parsing: {np.unique(parsing)}")
|
52 |
|
53 |
if category == "μμ":
|
54 |
# μμμ ν΄λΉνλ λΆλΆλ§ λ§μ€νΉ (μ체, ν)
|
55 |
+
upper_body = [5, 6, 7]
|
56 |
+
mask[np.isin(parsing, upper_body)] = 255
|
57 |
+
print(f"Masking upper body parts: {upper_body}")
|
58 |
elif category == "νμ":
|
59 |
# νμμ ν΄λΉνλ λΆλΆλ§ λ§μ€νΉ (ν체)
|
60 |
+
lower_body = [9, 12, 13, 14, 15, 16, 17, 18, 19]
|
61 |
+
mask[np.isin(parsing, lower_body)] = 255
|
62 |
+
print(f"Masking lower body parts: {lower_body}")
|
63 |
elif category == "λλ μ€":
|
64 |
# λλ μ€μ ν΄λΉνλ λΆλΆ λ§μ€νΉ (μ체μ ν체)
|
65 |
+
full_body = [5, 6, 7, 9, 12, 13, 14, 15, 16, 17, 18, 19]
|
66 |
+
mask[np.isin(parsing, full_body)] = 255
|
67 |
+
print(f"Masking full body parts: {full_body}")
|
68 |
else:
|
69 |
raise ValueError(f"Unknown category: {category}")
|
70 |
|
71 |
+
print(f"Mask shape: {mask.shape}, Unique values in mask: {np.unique(mask)}")
|
72 |
+
print(f"Number of masked pixels: {np.sum(mask == 255)}")
|
73 |
|
74 |
mask_gray = Image.fromarray(mask)
|
75 |
return mask_gray, mask_gray
|
|
|
185 |
status_message = ""
|
186 |
if is_checked:
|
187 |
try:
|
188 |
+
print(f"Processing category: {category}")
|
189 |
keypoints = openpose_model(human_img.resize((384,512)))
|
190 |
model_parse, _ = parsing_model(human_img.resize((384,512)))
|
191 |
+
|
192 |
+
# νμ± λͺ¨λΈμ μΆλ ₯ νμΈ
|
193 |
+
print(f"Parsing model output shape: {model_parse.shape}")
|
194 |
+
print(f"Unique values in parsing model output: {np.unique(model_parse)}")
|
195 |
+
|
196 |
mask, mask_gray = get_mask_location('hd', category, model_parse, keypoints)
|
197 |
mask = mask.resize((768,1024))
|
198 |
+
print(f"Mask created for category {category}")
|
199 |
+
|
200 |
+
# λ§μ€ν¬ νμΈ
|
201 |
+
print(f"Final mask shape: {mask.size}")
|
202 |
+
mask_array = np.array(mask)
|
203 |
+
print(f"Unique values in final mask: {np.unique(mask_array)}")
|
204 |
+
print(f"Number of masked pixels in final mask: {np.sum(mask_array == 255)}")
|
205 |
+
|
206 |
except Exception as e:
|
207 |
status_message = f"μλ λ§μ€ν¬ μμ± μ€ μ€λ₯κ° λ°μνμ΅λλ€: {str(e)}. κΈ°λ³Έ λ§μ€ν¬λ₯Ό μ¬μ©ν©λλ€."
|
208 |
+
print(f"Error in mask creation: {str(e)}")
|
209 |
mask = Image.new('L', (768, 1024), 255)
|
210 |
else:
|
211 |
if dict['layers'] and dict['layers'][0]:
|