TensorFlow学习笔记(更新中)

TensorFlow学习笔记

目前处于入门状态,参考资料有《TensorFLOW实战深度学习》,《深度学习》等书籍和tensorflow官网教程:

目录


TF图像处理函数

1.图像的编解码,读取,显示

import matplotlib.pyplot as plt
import tensorflow as tf
#读取图片数据,使用文件的绝对路径
image_raw_data = tf.gfile.FastGFile("path/to/your/pic".'r').read()

with tf.Session() as sess:
    #图片解码,对JEPG格式的图像进行解码,得到图像张量
    img_data = tf.image.decode_jpeg(image_raw_data)
    #输出解码后的张量数据
    print img_data.eval()
    #使用pyplot进行可视化
    plt.imshow(img_data.eval())
    ply.show()
    #图像编码成png格式,保存
    encoded_image = tf.image.encode_png(img_data)
    tf.gfile.GFile("path/your/want/picname","wb").write(encoded_image.eval())

2.图像调整
调整数据,使得图像符合网络输入要求.且可以扩充数据集,增加模型的鲁棒性,使网络在不同光照条件,尺度上都能有良好的表现.

#图像大小调整,可选的插值方法有双线性插值,最邻近插值,双三次插值,面积插值.默认为双线性插值
resize = tf.image.resize_images(img_data, [300,300], method="RsizeMethod.BILINEAR")
#图像裁剪,如果原图小于目标图像大小,自动补0填充.如果原图大于目标图像,自动裁剪居中部分.
padded = tf.image.resize_iamge_with_crop_or_pad(img_data, 1000, 3000)
croped = tf.image.resize_iamge_with_crop_or_pad(img_data, 100, 300)
#按比例裁剪图像
central_cropped = tf.image.central_crop(img_data, 0.5)

#图像翻转
#上下翻转
flipped = tf.image.flip_up_down(img_data)
#一定概率上下翻转
flipped = tf.image.random_flip_up_down(img_data)
#左右翻转
flipped = tf.image.flip_left_right(img_data)
flipped = tf.image.random_flip_left_right(img_data)
#对角线翻转
transposed = tf.image.transpose_image(img_data)


#色彩调整
#亮度调整
adjusted = tf.image.adjust_brightness(img_data, -0.5)
adjusted = tf.image.random_brightness(img_data, max_delta)
#对比度调整
adjusted = tf.image.adjust_contrast(img_data, -4)
adjusted = tf.image.random_contrast(img_data, lower, upper)
#色相调整
adjusted = tf.image.adjust_hue(img_data, 0.1)
adjusted = tf.image.random_hue(image, max_delta)
#饱和度
adjusted = tf.image.adjust_saturation(img_data, -4)
adjusted = tf.image.random_saturation(img_data, lower, upper)
#图像标准化,将图像亮度均值变为0,方差变为1
adjusted = tf.image.per_image_whitening(img_data)

#标注框处理
#tf.image.draw_bounding_boxes函数要求图像中的数字为实数,先进行类型转换
#且,其输入要求为四个四维矩阵用于存储标定框信息,所以需要给解码后的图像增加一维
batched = tf.expand_dims(tf.image.convert_image_dtpye(img_data, tf.float32), 0)
#设定标定框相对位置[ymin,xmin,ymax,xmax]
boxes = tf.constant([[[.0.5,.0.5,0.9,0.7], [0.35,0.47,0.5,0.56]]])
result = tf.image.draw_bounding_boxes(batched, boxes)
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值