使用tensorflow对图像数据增强和增广

该博客介绍了如何利用TensorFlow库对图像数据进行增强和扩增,包括图像的垂直翻转、水平翻转以及按90度倍数的旋转操作,旨在提升深度学习模型的训练效果。
摘要由CSDN通过智能技术生成

使用tensorflow

分别对数据集中图像使用翻转(垂直和左右)和旋转(90度的倍数)

import tensorflow as tf
import os

def trans(img, img_data, sav):
    #翻转操作是镜像的,旋转是非镜像的
    #垂直翻转
    flipped_up_down = tf.image.flip_up_down(img_data)
    #水平翻转
    flipped_left_right = tf.image.flip_left_right(img_data)
    #以90度的倍数进行旋转
    rotate_90 = tf.image.rot90(img_data, k=1)
    rotate_180 = tf.image.rot90(img_data, k=2)
    rotate_270 = tf.image.rot90(img_data, k=3)
    #编码
    encoded_image_u = tf.image.encode_jpeg(flipped_up_down)
    encoded_image_l = tf.image.encode_jpeg(flipped_left_right)
    encoded_image_r9 = tf.image.encode_jpeg(rotate_90)
    encoded_image_r18 = tf.image.encode_jpeg(rotate_180)
    encoded_image_r27 = tf.image.encode_jpeg(rotate_270)
    with tf.Session() as sess:
        u, l, r9, r18, r27 = sess.run([encoded_image_u, encoded_image_l, encoded_image_r9, 
                encoded_ima
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值