-
Notifications
You must be signed in to change notification settings - Fork 1
/
test.py
43 lines (33 loc) · 1.05 KB
/
test.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
# -*- conding: utf-8 -*-
import os
import time
import argparse
import tensorflow as tf
from PIL import Image
import numpy as np
from image_preprocessor import preprocess, denormalize
from auto_painter import load_auto_painter_model, generate_image
parser = argparse.ArgumentParser()
parser.add_argument('--path', default='./test.png', help='inference image path')
args = parser.parse_args()
# If you want to use GPU, Comment out this line.
os.environ["CUDA_VISIBLE_DEVICES"]="-1"
model = load_auto_painter_model()
IMG_WIDTH = 512
IMG_HEIGTH = 512
def load_image(filename):
with open(filename, 'rb') as f:
return np.array(f.read())
def test():
curr_time = time.time()
image_path = args.path
source = load_image(image_path)
adjusted_image = preprocess(source, IMG_WIDTH, IMG_HEIGTH)
image = denormalize(adjusted_image)
result = generate_image(model, adjusted_image)
image = Image.fromarray(result)
image_path = './images/'
filename = 'result_image.png'
image.save(image_path + filename)
if __name__ == '__main__':
test()