forked from younghkim1/23-2_DSL_Modeling_FontGenerator
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.py
66 lines (41 loc) · 1.86 KB
/
main.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
import numpy as np
import matplotlib.pyplot as plt
import torch
import torch.nn as nn
import random
from model import *
from dataset import *
from utils import *
def main():
# UNet_result_feat.npz 파일이 있는 경로 설정
# ex."/content/drive/MyDrive/FancyFont/현빈"
UNet_result_feat_path = ""
UNet_result_feat = load_UNet_result_feat(UNet_result_feat_path)
# generator_result.pt 파일이 있는 경로 설정
# ex."/content/drive/MyDrive/FancyFont/현빈"
generator_result_path = ""
generator = load_trained_model(generator_result_path)
device = torch.device("cuda") if torch.cuda.is_available()\
else torch.device("cpu")
print(f"Current Device: {device}")
generator = generator.to(device)
# font.npz 파일이 있는 경로 설정
# ex. "/content/drive/MyDrive/FancyFont/현빈"
font_path = ""
font_dataset = load_and_make_font_dataset(UNet_result_feat, font_path=font_path)
font_idx, input_sentence = enter_font_and_sentence()
word_idx_list = kor_to_idx(input_sentence)
generated_img_list = generate_images(generator, font_dataset,
font_idx, word_idx_list)
show_generated_images(generated_img_list)
# path for saving the generated images
saving_path = ''
# save the generated image at the "saving_path"
# saved file name: 'font'+str(font_idx)+'_'+input_sentence+'.npy
# ex. 'font3_안녕하세요.npy'
# file format: ndarray with
# "# of generated letters" * height(=32) * width(=32) * channel(=1) size
# ex. input sentence: 안녕하세요 -> 5*32*32*1 size ndarray
save_img_as_npy(font_idx, input_sentence, generated_img_list, saving_path)
if __name__ == '__main__':
main()