Update app.py
Browse files
app.py
CHANGED
@@ -39,28 +39,33 @@ def pil_to_binary_mask(pil_image, threshold=0):
|
|
39 |
output_mask = Image.fromarray(mask)
|
40 |
return output_mask
|
41 |
|
42 |
-
|
|
|
|
|
43 |
def get_mask_location(mode, category, parsing, keypoints):
|
44 |
parsing = np.array(parsing)
|
45 |
mask = np.zeros_like(parsing)
|
46 |
|
|
|
|
|
47 |
if category == "μμ":
|
48 |
-
# μμμ ν΄λΉνλ
|
49 |
mask[np.isin(parsing, [5, 6, 7])] = 255
|
50 |
elif category == "νμ":
|
51 |
-
# νμμ ν΄λΉνλ
|
52 |
mask[np.isin(parsing, [9, 12, 13, 14, 15, 16, 17, 18, 19])] = 255
|
53 |
elif category == "λλ μ€":
|
54 |
-
# λλ μ€μ ν΄λΉνλ λΆλΆ λ§μ€νΉ (
|
55 |
mask[np.isin(parsing, [5, 6, 7, 9, 12, 13, 14, 15, 16, 17, 18, 19])] = 255
|
56 |
else:
|
57 |
raise ValueError(f"Unknown category: {category}")
|
58 |
|
59 |
-
|
60 |
-
# μλ₯Ό λ€μ΄, μμμ κ²½μ° μ΄κΉ¨μ ν리 μ¬μ΄μ μμμΌλ‘ μ νν μ μμ΅λλ€.
|
61 |
|
62 |
mask_gray = Image.fromarray(mask)
|
63 |
return mask_gray, mask_gray
|
|
|
|
|
64 |
|
65 |
base_path = 'yisol/IDM-VTON'
|
66 |
example_path = os.path.join(os.path.dirname(__file__), 'example')
|
@@ -167,15 +172,19 @@ def start_tryon(dict, garm_img, garment_des, is_checked, is_checked_crop, denois
|
|
167 |
else:
|
168 |
human_img = human_img_orig.resize((768,1024))
|
169 |
|
|
|
170 |
status_message = ""
|
171 |
if is_checked:
|
172 |
try:
|
|
|
173 |
keypoints = openpose_model(human_img.resize((384,512)))
|
174 |
model_parse, _ = parsing_model(human_img.resize((384,512)))
|
175 |
mask, mask_gray = get_mask_location('hd', category, model_parse, keypoints)
|
176 |
mask = mask.resize((768,1024))
|
|
|
177 |
except Exception as e:
|
178 |
status_message = f"μλ λ§μ€ν¬ μμ± μ€ μ€λ₯κ° λ°μνμ΅λλ€: {str(e)}. κΈ°λ³Έ λ§μ€ν¬λ₯Ό μ¬μ©ν©λλ€."
|
|
|
179 |
mask = Image.new('L', (768, 1024), 255)
|
180 |
else:
|
181 |
if dict['layers'] and dict['layers'][0]:
|
|
|
39 |
output_mask = Image.fromarray(mask)
|
40 |
return output_mask
|
41 |
|
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 |
mask[np.isin(parsing, [5, 6, 7])] = 255
|
54 |
elif category == "νμ":
|
55 |
+
# νμμ ν΄λΉνλ λΆλΆλ§ λ§μ€νΉ (ν체)
|
56 |
mask[np.isin(parsing, [9, 12, 13, 14, 15, 16, 17, 18, 19])] = 255
|
57 |
elif category == "λλ μ€":
|
58 |
+
# λλ μ€μ ν΄λΉνλ λΆλΆ λ§μ€νΉ (μ체μ ν체)
|
59 |
mask[np.isin(parsing, [5, 6, 7, 9, 12, 13, 14, 15, 16, 17, 18, 19])] = 255
|
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
|
67 |
+
|
68 |
+
|
69 |
|
70 |
base_path = 'yisol/IDM-VTON'
|
71 |
example_path = os.path.join(os.path.dirname(__file__), 'example')
|
|
|
172 |
else:
|
173 |
human_img = human_img_orig.resize((768,1024))
|
174 |
|
175 |
+
|
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]:
|