资源简介
tensorflow图像风格迁移代码 tensorflow图像风格迁移代码
代码片段和文件信息
# coding: utf-8
from __future__ import print_function
import tensorflow as tf
from preprocessing import preprocessing_factory
import reader
import model
import time
import os
tf.app.flags.DEFINE_string(‘loss_model‘ ‘vgg_16‘ ‘The name of the architecture to evaluate. ‘
‘You can view all the support models in nets/nets_factory.py‘)
tf.app.flags.DEFINE_integer(‘image_size‘ 256 ‘Image size to train.‘)
tf.app.flags.DEFINE_string(“model_file“ “models.ckpt“ ““)
tf.app.flags.DEFINE_string(“image_file“ “a.jpg“ ““)
FLAGS = tf.app.flags.FLAGS
def main(_):
# Get image‘s height and width.
height = 0
width = 0
with open(FLAGS.image_file ‘rb‘) as img:
with tf.Session().as_default() as sess:
if FLAGS.image_file.lower().endswith(‘png‘):
image = sess.run(tf.image.decode_png(img.read()))
else:
image = sess.run(tf.image.decode_jpeg(img.read()))
height = image.shape[0]
width = image.shape[1]
tf.logging.info(‘Image size: %dx%d‘ % (width height))
with tf.Graph().as_default():
with tf.Session().as_default() as sess:
# Read image data.
image_preprocessing_fn _ = preprocessing_factory.get_preprocessing(
FLAGS.loss_model
is_training=False)
image = reader.get_image(FLAGS.image_file height width image_preprocessing_fn)
# Add batch dimension
image = tf.expand_dims(image 0)
generated = model.net(image training=False)
generated = tf.cast(generated tf.uint8)
# Remove batch dimension
generated = tf.squeeze(generated [0])
# Restore model variables.
saver = tf.train.Saver(tf.global_variables() write_version=tf.train.SaverDef.V1)
sess.run([tf.global_variables_initializer() tf.local_variables_initializer()])
# Use absolute path
FLAGS.model_file = os.path.abspath(FLAGS.model_file)
saver.restore(sess FLAGS.model_file)
# Make sure ‘generated‘ directory exists.
generated_file = ‘generated/res.jpg‘
if os.path.exists(‘generated‘) is False:
os.makedirs(‘generated‘)
# Generate and write image data to file.
with open(generated_file ‘wb‘) as img:
start_time = time.time()
img.write(sess.run(tf.image.encode_jpeg(generated)))
end_time = time.time()
tf.logging.info(‘Elapsed time: %fs‘ % (end_time - start_time))
tf.logging.info(‘Done. Please check %s.‘ % generated_file)
if __name__ == ‘__main__‘:
tf.logging.set_verbosity(tf.logging.INFO)
tf.app.run()
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
目录 0 2018-05-02 08:38 chapter_7\
文件 1125 2018-04-11 21:35 chapter_7\.gitignore
文件 2450 2018-04-11 21:35 chapter_7\README.md
文件 4076 2018-04-11 21:35 chapter_7\README_eng.md
目录 0 2018-05-02 08:38 chapter_7\conf\
文件 988 2018-04-11 21:35 chapter_7\conf\candy.yml
文件 990 2018-04-11 21:35 chapter_7\conf\cubist.yml
文件 1006 2018-04-11 21:35 chapter_7\conf\denoised_starry.yml
文件 994 2018-04-11 21:35 chapter_7\conf\feathers.yml
文件 990 2018-04-11 21:35 chapter_7\conf\mosaic.yml
文件 990 2018-04-11 21:35 chapter_7\conf\scream.yml
文件 988 2018-04-11 21:35 chapter_7\conf\udnie.yml
文件 987 2018-04-11 21:35 chapter_7\conf\wave.yml
文件 2800 2018-04-11 21:35 chapter_7\eval.py
文件 3638 2018-04-11 21:35 chapter_7\export.py
目录 0 2018-05-02 08:38 chapter_7\img\
文件 376101 2018-04-11 21:35 chapter_7\img\candy.jpg
文件 45249 2018-04-11 21:35 chapter_7\img\cubist.jpg
文件 731923 2018-04-11 21:35 chapter_7\img\denoised_starry.jpg
文件 322013 2018-04-11 21:35 chapter_7\img\feathers.jpg
文件 77378 2018-04-11 21:35 chapter_7\img\mosaic.jpg
目录 0 2018-05-02 08:38 chapter_7\img\results\
文件 177122 2018-04-11 21:35 chapter_7\img\results\cubist.jpg
文件 259131 2018-04-11 21:35 chapter_7\img\results\denoised_starry.jpg
文件 232247 2018-04-11 21:35 chapter_7\img\results\feathers.jpg
文件 291969 2018-04-11 21:35 chapter_7\img\results\mosaic.jpg
文件 197602 2018-04-11 21:35 chapter_7\img\results\scream.jpg
文件 35293 2018-04-11 21:35 chapter_7\img\results\st
文件 53294 2018-04-11 21:35 chapter_7\img\results\st
文件 45395 2018-04-11 21:35 chapter_7\img\results\st
文件 54955 2018-04-11 21:35 chapter_7\img\results\st
............此处省略56个文件信息
- 上一篇:AI面相-1.1.7
- 下一篇:图像处理面试问题
相关资源
- TensorFlow Machine Learning Cookbook
- Learning TensorFlow: A Guide to Building Deep
- tensorflow271134
- TensorFlow for Machine Intelligence 书籍源码
- 《Hands-On Machine Learning with Scikit-Learn
- Building Machine Learning Projects with Tensor
- TensorFlow Powerful Predictive Analytics with
- 北大tensorflow学习笔记
- LSTMandRNN.zip
- 使用TensorFlow搭建智能开发系统,自动
- Packt.TensorFlow.Machine.Learning.Cookbook.201
- tensorflow深度学习CNN智能识别车牌
- Tensorflow GNN实战.zip
- tensorflow从入门到精通
- 深度卷积生成对抗网络TensorFlow代码实
- TensorFlow_中文手册
- siamese mnist 孪生网络
- TensorFlow 中文文档 1.8 掘金 2018.5.19
- Tensorflow(一)训练自己的数据集——
- libtensorflow_inference.so
- 使用TPU对104种花朵进行分类-东北大学
- Omniglot数据集自编码器的设计与实现
- Hands-On Machine Learning 英文原版
- 《TensorFlow Keras 深度学习人工智能实践
- TensorFlow+on+Yarn:深度学习遇上大数据
- opencv4.0结合TensorFlow实现mask rcnn的目标
- Learning TensorFlow_A Guide to Building Deep L
- Deep.Learning.with.TensorFlow
- 基于Tensorflow的小波神经网络实验代码
- TensorFlow入门:使用卷积网络模型实现
评论
共有 条评论