Upload VITON-HD/eval/generate_fid_stats_base.py with huggingface_hub
Browse files
VITON-HD/eval/generate_fid_stats_base.py
ADDED
@@ -0,0 +1,40 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import argparse
|
2 |
+
import os
|
3 |
+
import shutil
|
4 |
+
|
5 |
+
from cleanfid import fid
|
6 |
+
from tqdm import tqdm
|
7 |
+
|
8 |
+
|
9 |
+
def make_custom_stats(dresscode_dataroot: str, vitonhd_dataroot: str):
|
10 |
+
if dresscode_dataroot is not None:
|
11 |
+
dresscode_filesplit = os.path.join(dresscode_dataroot, f"test_pairs_paired.txt")
|
12 |
+
with open(dresscode_filesplit, 'r') as f:
|
13 |
+
lines = f.read().splitlines()
|
14 |
+
for category in ['lower_body', 'upper_body', 'dresses']:
|
15 |
+
if not fid.test_stats_exists(f"dresscode_{category}", mode='clean'):
|
16 |
+
paths = [os.path.join(dresscode_dataroot, category, 'images', line.strip().split()[0]) for line in lines if
|
17 |
+
os.path.exists(os.path.join(dresscode_dataroot, category, 'images', line.strip().split()[0]))]
|
18 |
+
tmp_folder = f"/tmp/dresscode/{category}"
|
19 |
+
os.makedirs(tmp_folder, exist_ok=True)
|
20 |
+
for path in tqdm(paths):
|
21 |
+
shutil.copy(path, tmp_folder)
|
22 |
+
fid.make_custom_stats(f"dresscode_{category}", tmp_folder, mode="clean", verbose=True)
|
23 |
+
|
24 |
+
if not fid.test_stats_exists(f"dresscode_all", mode='clean'):
|
25 |
+
paths = [os.path.join(dresscode_dataroot, category, 'images', line.strip().split()[0]) for line in lines for
|
26 |
+
category in ['lower_body', 'upper_body', 'dresses'] if
|
27 |
+
os.path.exists(os.path.join(dresscode_dataroot, category, 'images', line.strip().split()[0]))]
|
28 |
+
tmp_folder = f"/tmp/dresscode/all"
|
29 |
+
os.makedirs(tmp_folder, exist_ok=True)
|
30 |
+
for path in tqdm(paths):
|
31 |
+
shutil.copy(path, tmp_folder)
|
32 |
+
fid.make_custom_stats(f"dresscode_all", tmp_folder, mode="clean", verbose=True)
|
33 |
+
|
34 |
+
if vitonhd_dataroot is not None:
|
35 |
+
if not fid.test_stats_exists(f"vitonhd_all", mode='clean'):
|
36 |
+
fid.make_custom_stats(f"vitonhd_all", os.path.join(vitonhd_dataroot, 'test', 'image'), mode="clean",
|
37 |
+
verbose=True)
|
38 |
+
if not fid.test_stats_exists(f"vitonhd_upper_body", mode='clean'):
|
39 |
+
fid.make_custom_stats(f"vitonhd_upper_body", os.path.join(vitonhd_dataroot, 'test', 'image'), mode="clean",
|
40 |
+
verbose=True)
|