venbab commited on
Commit
f128013
·
verified ·
1 Parent(s): 0cbe5b0

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +24 -25
app.py CHANGED
@@ -16,43 +16,42 @@ CLOTH_DIR = f"{ROOT}/test_color"
16
  PAIRS = f"{ROOT}/test_pairs.txt"
17
 
18
  def prepare_onepair_dataset(user_img_path: str, cloth_img_path: str):
19
- # Reset the temp dataset folder each run
20
  if os.path.exists(ROOT):
21
  shutil.rmtree(ROOT)
22
 
23
- split_dir = f"{ROOT}/test"
24
- img_dir = f"{split_dir}/image"
25
- cloth_dir = f"{split_dir}/cloth"
26
- cloth_maskdir = f"{split_dir}/cloth-mask"
27
-
28
  os.makedirs(img_dir, exist_ok=True)
29
  os.makedirs(cloth_dir, exist_ok=True)
30
- os.makedirs(cloth_maskdir, exist_ok=True)
 
 
 
31
 
32
- user_name = "person.jpg"
33
- cloth_name = "cloth.jpg"
 
34
 
35
- # Save the inputs into expected folders
36
- shutil.copy(user_img_path, f"{img_dir}/{user_name}")
37
- shutil.copy(cloth_img_path, f"{cloth_dir}/{cloth_name}")
38
 
39
- # --- Build cloth mask using rembg alpha ---
40
- cut_rgba = remove(Image.open(cloth_img_path).convert("RGBA"))
41
- alpha = np.array(cut_rgba.split()[-1]) # alpha channel
42
- binmask = Image.fromarray((alpha > 10).astype(np.uint8) * 255, mode="L")
43
- binmask.save(f"{cloth_maskdir}/{cloth_name}", quality=95)
44
 
45
- # IMPORTANT: person (image) first, then cloth
46
- with open(PAIRS, "w") as f:
47
- f.write(f"{cloth_name} {user_name}\n")
48
 
49
- print("PAIR LINE:", open(PAIRS).read().strip())
50
- print("TREE:")
51
-
52
  for p in ["test/image", "test/cloth", "test/cloth-mask"]:
53
- print(p, "=>", os.listdir(os.path.join(ROOT, p)))
 
54
 
55
-
56
  return ROOT
57
 
58
 
 
16
  PAIRS = f"{ROOT}/test_pairs.txt"
17
 
18
  def prepare_onepair_dataset(user_img_path: str, cloth_img_path: str):
19
+ # Reset temp dataset
20
  if os.path.exists(ROOT):
21
  shutil.rmtree(ROOT)
22
 
23
+ # Expected DCI-VTON structure
24
+ img_dir = os.path.join(ROOT, "test", "image")
25
+ cloth_dir = os.path.join(ROOT, "test", "cloth")
26
+ cm_dir = os.path.join(ROOT, "test", "cloth-mask")
 
27
  os.makedirs(img_dir, exist_ok=True)
28
  os.makedirs(cloth_dir, exist_ok=True)
29
+ os.makedirs(cm_dir, exist_ok=True)
30
+
31
+ user_name = "person.jpg" # person image filename
32
+ cloth_name = "cloth.jpg" # garment image filename
33
 
34
+ # Write pairs: CLOTH FIRST, then PERSON (as CPDataset expects)
35
+ with open(os.path.join(ROOT, "test_pairs.txt"), "w") as f:
36
+ f.write(f"{cloth_name} {user_name}\n")
37
 
38
+ # Save images in expected places
39
+ shutil.copy(user_img_path, os.path.join(img_dir, user_name))
40
+ shutil.copy(cloth_img_path, os.path.join(cloth_dir, cloth_name))
41
 
42
+ # --- Compatibility shim ---
43
+ # Some codepaths also try to read image/cloth.jpg; make a duplicate.
44
+ shutil.copy(user_img_path, os.path.join(img_dir, cloth_name))
 
 
45
 
46
+ # Reuse the garment as a coarse cloth-mask (you can replace with a real mask later)
47
+ shutil.copy(cloth_img_path, os.path.join(cm_dir, cloth_name))
 
48
 
49
+ # Debug print
50
+ print("PAIR LINE:", open(os.path.join(ROOT, "test_pairs.txt")).read().strip())
 
51
  for p in ["test/image", "test/cloth", "test/cloth-mask"]:
52
+ full = os.path.join(ROOT, p)
53
+ print(p, "=>", os.listdir(full) if os.path.exists(full) else "MISSING")
54
 
 
55
  return ROOT
56
 
57