tensorflow Data Augmentation 代码(翻转,亮度,裁切)

本文介绍了TensorFlow中用于图像处理的数据增强技术,包括JPEG和PNG图片的解码与编码,图像的resize、crop、翻转及亮度调整等操作,这些方法有助于训练更健壮的模型。
摘要由CSDN通过智能技术生成

《一》     Encoding and Decoding

1. tf.image.decode_jpeg(contents, channels=None, ratio=None, fancy_upscaling=None, try_recover_truncated=None, acceptable_fraction=None, name=None)

Decode a JPEG-encoded image to a uint8 tensor.   将一张jpeg的图片解码成uint8的张量,形状3-D, [height, width, channels]

contents 是编码过的图片,是一个类型为string的tensor,形状0-D,

channels 代表通道,如果为默认的0,则表示使用编码图片的通道数,若为1,则输出为灰度图,若为3,则输出为rgb格式

eg:

import tensorflow as tf
import numpy as np
img_path = '/Users/apple/Downloads/Medlinker/util/1.jpg'   # 图片存放的路径

def decode_img(path):
    file_queue = tf.train.string_input_producer([path])    # 注意这儿的输入是一个列表,参数还有shuffle,是否打乱
    image_reader = tf.WholeFileReader()
    key, image = image_reader.read(file_queue)
    image_decode = tf.image.decode_jpeg(image, channels=0)

    with tf.Session() as sess:
        coord = tf.train.Coordinator()
        threads = tf.train.start_queue_runners(sess=sess, coord=coord)
        # sess.run(tf.global_variables_initializer())
        x = sess.run(image_decode)
        coord.reques
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值