-
大小: 5.61MB文件類型: .zip金幣: 1下載: 0 次發布日期: 2023-11-18
- 語言: 其他
- 標簽: tensorflow??
資源簡介
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
- 下一篇:圖像處理面試問題
評論
共有 條評論