forked from VinAIResearch/CPM
-
Notifications
You must be signed in to change notification settings - Fork 0
/
create_beautygan_uv.py
54 lines (42 loc) · 1.76 KB
/
create_beautygan_uv.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
"""
Generate texture for dataset_folder
"""
import argparse
import glob
import os
import cv2
from texture_generator import Texture_Generator
from tqdm import tqdm as tqdm
def get_args():
parser = argparse.ArgumentParser()
parser.add_argument("--path", default=".", type=str)
parser.add_argument("--savedir", default="./MakeupTransfer_UV", type=str)
args = parser.parse_args()
print(" ⊱ ──────ஓ๑♡๑ஓ ────── ⊰")
for arg in vars(args):
print("{:>15}: {:>30}".format(str(arg), str(getattr(args, arg))))
print()
return args
if __name__ == "__main__":
args = get_args()
generator = Texture_Generator()
list_imgs = glob.glob(os.path.join(args.path, "images", "*", "*.png"))
filenames = [x.split("/all/images/")[-1] for x in list_imgs]
list_segs = [os.path.join(args.path, "segs", x) for x in filenames]
print("Found {} images, together with {} segmentation mask".format(len(list_imgs), len(list_segs)))
subdirs = [
os.path.join(args.savedir, x) for x in ["images/non-makeup", "images/makeup", "segs/non-makeup", "segs/makeup"]
]
for subpath in subdirs:
if not os.path.isdir(subpath):
os.makedirs(subpath)
print("Created: ", subpath)
print(" ⊱ ──────ஓ๑♡๑ஓ ────── ⊰")
print("")
print("New images will be saved in: ", args.savedir)
for i in tqdm(range(0, len(list_imgs))):
image = cv2.imread(list_imgs[i])
seg = cv2.imread(list_segs[i])
uv_texture, uv_seg = generator.get_texture(image, seg)
cv2.imwrite(os.path.join(args.savedir, "images", filenames[i]), uv_texture)
cv2.imwrite(os.path.join(args.savedir, "segs", filenames[i]), uv_seg)