-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathgen.py
66 lines (48 loc) · 2.24 KB
/
gen.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
55
56
57
58
59
60
61
62
63
64
65
66
# -*- coding: utf-8 -*-
import tensorflow as tf
import argparse
from model.zi2ziNet.unet import UNet
parser = argparse.ArgumentParser(description='Train')
# parser.add_argument('--src_font', dest='src_font', required=True, help='path of the source font')
# parser.add_argument('--dst_font', dest='dst_font', required=True, help='path of the target font')
parser.add_argument('--text', dest='text', default=None)
parser.add_argument('--checkpoint', dest='checkpoint', required=True)
args = parser.parse_args()
def inspect_graph():
from pprint import pprint
var_list = tf.global_variables()
collection_list = tf.get_default_graph().get_all_collection_keys()
pprint(var_list)
pprint(tf.get_default_graph().get_tensor_by_name("no_target_A_and_B_images:0"))
from subprocess import call
def main(_):
config = tf.ConfigProto()
with open("./infer_charset", "w") as f:
if args.text:
f.write(args.text)
f.write("南去經三國,東來過五湖。")
f.write("︽永東國酬愛鬱靈鷹袋︾")
f.write("あのイーハトーヴォのすきとおった風、夏でも底に冷たさをもつ青いそら、うつくしい森で飾られたモーリオ市、郊外のぎらぎらひかる草の波。")
f.write("동해물과、백두산이、마르고닳도록、하느님이、보우하사。")
f.write("ABCDEFGHIJKLM")
f.write("\n")
call(
"rm -rf zi2ziu_infer_sample && mkdir -p zi2ziu_infer_sample",
shell=True)
call(
"python3 font2img.py --src_font fonts/NotoSansCJK.ttc --dst_font fonts/NotoSerifCJK.ttc --sample_dir zi2ziu_infer_sample --mode RGB --charset infer_charset",
shell=True)
call(
"python3 img2pickle.py --dir zi2ziu_infer_sample --save_dir zi2ziu_infer_sample --split_ratio 1",
shell=True
)
with tf.Session(config=config) as sess:
model = UNet()
model.register_session(sess)
model.build_model(is_training=False)
tf.global_variables_initializer().run()
model.infer(source_obj="./zi2ziu_infer_sample/val.obj", model_dir=args.checkpoint,
embedding_ids=[0], save_dir="./inferred/")
print("Done")
if __name__ == '__main__':
tf.app.run()