tensorflow图像裁剪后如何实现数据增强-创新互联
                                            创新互联www.cdcxhl.cn八线动态BGP香港云服务器提供商,新人活动买多久送多久,划算不套路!

这篇文章主要介绍tensorflow图像裁剪后如何实现数据增强,文中示例代码介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们一定要看完!
我就废话不多说了,大家还是直接看代码吧~
#!/usr/bin/env python
# encoding: utf-8
'''
@author: lele Ye
@contact: 1750112338@qq.com
@software: pycharm 2018.2
@file: 13mnist.py
@time: 2018/12/17 10:23
@desc:
'''
import tensorflow as tf
import scipy.misc
import matplotlib.pyplot as plt
import random
 
# 读取图像可任意大小
filenames = ['./tianchi.jpg']
# 创建文件读取队列
filename_queue = tf.train.string_input_producer(filenames)
# 一个阅读器,读取整个文件,返回文件名称key,以及文件中所有的内容value
reader = tf.WholeFileReader()
# Returns the next record (key, value) pair produced by a reader
key, value = reader.read(filename_queue)
images = tf.image.decode_jpeg(value) # tf.image.decode_png(value)
target_width = target_height = 224
 
# 裁切图片
with tf.Session() as sess:
  # Coordinator的使用,用于多线程的协调
  coord = tf.train.Coordinator()
  # 启动所有graph收集到的队列运行器(queuerunners)
  threads = tf.train.start_queue_runners(coord=coord)
  height,width,channels = sess.run(tf.shape(images))
  offset_height = random.randint(0,height-target_height)
  offset_width = random.randint(0,width-target_width)
  reshapeimg = tf.image.crop_to_bounding_box(images, offset_height=offset_height, offset_width=offset_width,
                        target_height=target_height,target_width=target_width)
  print(type(reshapeimg)) # 
  reimg1 = reshapeimg.eval() # reimg1的类型是
  scipy.misc.imsave('./crop.jpg', reimg1)
  plt.imshow(reimg1)
  plt.axis("off")
  plt.show()
  # 请求线程结束
  coord.request_stop()
  # 等待线程终止
  coord.join(threads)                                                  名称栏目:tensorflow图像裁剪后如何实现数据增强-创新互联
浏览地址:http://www.scyingshan.cn/article/ppehh.html

 建站
建站
 咨询
咨询 售后
售后
 建站咨询
建站咨询 
 