原文链接: fast style transfer 快速风格转换 test
上一篇: fast style transfer 快速风格转换 train
下一篇: opencv 和scipy misc 模块 图像resize 速度比较 timeit 模块使用
测试pb文件
在人像上的效果稍微有点欠缺
读取配置文件中的pb路径,将测试图片输入进去后展示出来
素描风格
蒙娜丽莎的效果看起来还是有点厉害的
混合风格
test
import tensorflow as tf
import matplotlib.pyplot as plt
import scipy.misc as sm
from config import *
sess = tf.Session()
output_graph_def = tf.GraphDef()
with open(PB_PATH, "rb") as f:
output_graph_def.ParseFromString(f.read())
tf.import_graph_def(
output_graph_def,
name='', # 默认name为import,类似scope
# return_elements=['generator/mul:0']
)
sess.run(tf.global_variables_initializer())
in_image = sess.graph.get_tensor_by_name("in_x:0")
in_height = sess.graph.get_tensor_by_name("in_height:0")
in_width = sess.graph.get_tensor_by_name("in_width:0")
output = sess.graph.get_tensor_by_name("generator/output:0")
# (1, ?, ?, 3) <unknown> <unknown> (?, ?, ?, ?)
print(in_image.shape, in_height.shape, in_width.shape, output.shape)
with tf.Session() as sess:
sess.run(tf.global_variables_initializer())
for path in TEST_IMAGE_PATHS:
image = sm.imread(path, mode='RGB')
# plt.imshow(image)
# plt.show()
h, w, _ = image.shape
output_val = sess.run(
output, {
in_image: np.expand_dims(image.astype(np.float32), 0),
in_height: h,
in_width: w,
}
)
# (784, 637, 3) (1, 784, 637, 1)
print(image.shape, output_val.shape)
output_val = np.squeeze(output_val, 0)
output_val = np.clip(output_val, 0, 255).astype(np.uint8)
plt.imshow(output_val)
plt.show()