没有合适的资源?快使用搜索试试~ 我知道了~
我就废话不多说了,大家还是直接看代码吧~ #!/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
资源详情
资源评论
资源推荐
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)) # <class 'tensorflow.python.framework.ops.Tensor'>
reimg1 = reshapeimg.eval() # reimg1的类型是<class 'numpy.ndarray'>
scipy.misc.imsave('./crop.jpg', reimg1)
plt.imshow(reimg1)
plt.axis("off")
plt.show()
# 请求线程结束
coord.request_stop()
# 等待线程终止
coord.join(threads)
原始图像480x320x3:
裁剪后224x224x3:
weixin_38605967
- 粉丝: 7
- 资源: 971
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- 126641091882064LSPatch.apk
- 5G网络基础培训课件.zip
- 2024-spring-HIT-CS-大作业
- yolo目标检测项目实验
- downloadFile-1.hc
- C++课程设计:基于Qt的航班信息管理系统
- ADS7822UVerilog驱动,前面传的有点问题
- 基于python的高性能爬虫程序,使用了多线程+缓存+xpath实现的,这里以彼-岸图库为例,实现,仅用于学习交流
- 中分辨率成像光谱仪(MODIS)烧毁面积产品信息MODIS-C6-BA-User-Guide-1.2.pdf
- Screenshot_20240427_172613_com.huawei.browser.jpg
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
评论0