TensorFlow学习--tensorflow图像处理--添加标注框
来源:互联网 发布:浙江师范大学数据库 编辑:程序博客网 时间:2024/06/05 07:48
添加标注框
tf.image.draw_bounding_boxes
tensorflow通过tf.image.draw_bounding_boxes函数加入标注框.
#!/usr/bin/python# coding:utf-8import matplotlib.pyplot as pltimport tensorflow as tf# 读取图像数据img = tf.gfile.FastGFile('daibola.jpg').read()with tf.Session() as sess: img_data = tf.image.decode_jpeg(img) # tf.image.draw_bounding_boxes要求图像矩阵中的数字为实数 # 利用tf.image.convert_image_dtype将图像矩阵转化为实数 batched = tf.expand_dims(tf.image.convert_image_dtype(img_data, tf.float32), 0) # 边界框坐标是相对于宽度和宽度在[0.0,1.0]内的浮点数,即这里给出的都是图像的相对位置[0.1, 0.2, 0.8, 0.8]即(0.1*wide, 0.2*high)到(0.8*wide, 0.8*high) boxes = tf.constant([[[0.1, 0.2, 0.8, 0.8]]]) # 在图像上绘制边界框 result = tf.image.draw_bounding_boxes(batched, boxes) plt.subplot(121), plt.imshow(img_data.eval()), plt.title('original') plt.subplot(122), plt.imshow(result[0].eval()), plt.title('result') plt.show()
输出:
图像比较大时,部分边界框可能会出现显示问题.可以先将图像缩小一些,让标注清楚.
resize = tf.image.resize_images(img_data, (200, 350), method=1)
tf.image.sample_distorted_bounding_box
通过tf.image.sample_distorted_bounding_box函数可以实现图像的随机截取.通常用于随机截取图像上由信息量的部分以提高模型的鲁帮性/robustness.使训练出的模型不受识别物体的大小的影响.
#!/usr/bin/python# coding:utf-8import matplotlib.pyplot as pltimport tensorflow as tf# 读取图像数据img = tf.gfile.FastGFile('daibola.jpg').read()with tf.Session() as sess: img_data = tf.image.decode_jpeg(img) boxes = tf.constant([[[0.2, 0.2, 0.9, 0.7]]]) # 为图像生成一个随机扭曲的边界框 # 通过提供标注框的方式来告诉随机截取图像的范围 begin, size, bbox_for_draw = tf.image.sample_distorted_bounding_box(tf.shape(img_data), bounding_boxes=boxes) # 在张量形状中插入1个维度 batched1 = tf.expand_dims(tf.image.convert_image_dtype(img_data, tf.float32), 0) # 在图像上绘制边界框 image_with_box = tf.image.draw_bounding_boxes(batched1, bbox_for_draw) # 从张量中提取切片 distorted_image = tf.slice(img_data, begin, size) plt.subplot(121), plt.imshow(img_data.eval()), plt.title('original') plt.subplot(122), plt.imshow(distorted_image.eval()), plt.title('result') plt.show()
阅读全文
0 0
- TensorFlow学习--tensorflow图像处理--添加标注框
- TensorFlow学习--tensorflow图像预处理
- TensorFlow学习--tensorflow图像处理--图像读取/格式转换
- TensorFlow学习--tensorflow图像处理--图像翻转及大小色彩调整
- tensorflow在图像中加入标注框
- tensorflow学习之图像处理
- Tensorflow 图像处理函数
- 12、TensorFlow 图像处理
- TensorFlow学习--AlexNet实现&图像识别
- TensorFlow学习--VGGNet实现&图像识别
- Tensorflow中图像处理函数
- 在TensorFlow中使用深度学习GANs处理图像
- Tensorflow深度学习之十一:基础图像处理
- Tensorflow深度学习之十二:基础图像处理之二
- Tensorflow深度学习之十三:基础图像处理之三
- TensorFlow学习笔记-图像预处理
- TensorFlow 图像处理和解码操作函数
- 【TensorFlow】数据处理(对图像的处理)
- HTML-JavaScript-登录网页及验证
- box-sizing&&0utline属性
- IOException parsing XML document from class path resource resource [com/zj/spring01/helloworld/appli
- 利用指向调用函数输出两个数中的较大者
- 基于Android、ios平台,支持接口开发的移动端车牌识别技术
- TensorFlow学习--tensorflow图像处理--添加标注框
- 日常手残
- [深度学习]Ubuntu16.04 + GTX 1050 + cuda8.0 + cuDNN5.1 + caffe安装详解
- 从控制台接收输入字符【20171114练习】
- 虎扑网评论基础抓取
- Selenium3.x Python实现鼠标悬停的几种方法
- 电路小任务
- 小白学习javascript——运算符
- sqlserer2008数据库还原