aiqcamp commited on
Commit
089e25c
β€’
1 Parent(s): bd21015

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +29 -8
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
- 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
@@ -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]: