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

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +15 -6
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
- # utils_mask.py νŒŒμΌμ— μžˆλŠ” get_mask_location ν•¨μˆ˜λ₯Ό μˆ˜μ •ν•©λ‹ˆλ‹€.
 
 
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]: