Update app.py
Browse files
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
|
| 20 |
if os.path.exists(ROOT):
|
| 21 |
shutil.rmtree(ROOT)
|
| 22 |
|
| 23 |
-
|
| 24 |
-
img_dir
|
| 25 |
-
cloth_dir =
|
| 26 |
-
|
| 27 |
-
|
| 28 |
os.makedirs(img_dir, exist_ok=True)
|
| 29 |
os.makedirs(cloth_dir, exist_ok=True)
|
| 30 |
-
os.makedirs(
|
|
|
|
|
|
|
|
|
|
| 31 |
|
| 32 |
-
|
| 33 |
-
|
|
|
|
| 34 |
|
| 35 |
-
# Save
|
| 36 |
-
shutil.copy(user_img_path,
|
| 37 |
-
shutil.copy(cloth_img_path,
|
| 38 |
|
| 39 |
-
# ---
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
binmask = Image.fromarray((alpha > 10).astype(np.uint8) * 255, mode="L")
|
| 43 |
-
binmask.save(f"{cloth_maskdir}/{cloth_name}", quality=95)
|
| 44 |
|
| 45 |
-
#
|
| 46 |
-
|
| 47 |
-
f.write(f"{cloth_name} {user_name}\n")
|
| 48 |
|
| 49 |
-
|
| 50 |
-
print("
|
| 51 |
-
|
| 52 |
for p in ["test/image", "test/cloth", "test/cloth-mask"]:
|
| 53 |
-
|
|
|
|
| 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 |
|