-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathwritten2all.py
More file actions
44 lines (38 loc) · 1.68 KB
/
written2all.py
File metadata and controls
44 lines (38 loc) · 1.68 KB
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
import os
from generator.generator import generator
from utils import pil2tensor
import logging
def written2all(input_unicode, image_input, opt, is_demo, unicodes):
if is_demo:
path_class = "./data/pths_demo/%s/" % (input_unicode)
else:
path_class = "./data/pths/%s/" % (input_unicode)
if not os.path.isdir(path_class):
return {}
output_images = {}
# change image type to tensor float
image_input_tensor = pil2tensor(image_input)
image_input_tensor = image_input_tensor.unsqueeze(0)
# if pth exist, generate another character using pth
dirs = os.listdir(path_class)
for dir in dirs:
if dir.split('_')[0] == input_unicode:
files = os.listdir("%s/%s/" % (path_class, dir))
for filename in files:
ext = os.path.splitext(filename)[-1]
if ext == '.pth':
unicode_output = dir.split('_')[1].split('.')[-1]
if unicode_output in unicodes:
logging.info(
"PASS making [%s] : unicode is aleady in input",
(unicode_output))
break
# log
logging.info(" start making:[ " + unicode_output + " ]")
path_pth = os.path.abspath("%s/%s/%s" % (path_class, dir,
filename))
logging.info(" done making!:[ " + unicode_output + " ]")
image_gen = generator(image_input_tensor, opt, path_pth)
output_images[unicode_output] = image_gen
break
return output_images