日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

【tensorFlow】——图像数据增强、读取图像、保存图像

發布時間:2023/12/10 编程问答 33 豆豆
生活随笔 收集整理的這篇文章主要介紹了 【tensorFlow】——图像数据增强、读取图像、保存图像 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
#!/usr/bin/env python # -*- coding: utf-8 -*- # @Time : 2021/4/13 10:54 # @Author : @linlianqin # @Site : # @File : 數據增強(distorted).py # @Software: PyCharm # @description:一些基于TensorFlow的數據處理方法import tensorflow as tf import cv2 import matplotlib.pyplot as pltpath = r'E:\gitHubProjects\tensorflow_learning\CNN卷積神經網絡-cifar數據集分類\tensorflow_image_processing\1.png'def tf_imgae_processing():# 讀取圖像文件image_raw = tf.gfile.GFile(path,'rb').read() # 以二進制的形式讀取with tf.Session() as sess:## 對圖像進行解碼得到圖像的三維矩陣數據image_data = tf.image.decode_image(image_raw)h,w,c = image_data.eval().shapeprint("image_data.shape:",(h,w,c))# 顯示圖像plt.imshow(image_data.eval())plt.show()# 裁剪圖像crop_img = tf.random_crop(image_data,[300,300,c])plt.imshow(crop_img.eval())plt.show()## 保存圖像crop_encode_img = tf.image.encode_png(crop_img)with tf.gfile.GFile(r'E:\gitHubProjects\tensorflow_learning\CNN卷積神經網絡-cifar數據集分類\tensorflow_image_proces'r'sing'+'\crop_img.png','wb') as f:f.write(crop_encode_img.eval())# 隨機左右翻轉圖像(也可以隨機上下翻轉)flip_img = tf.image.random_flip_left_right(crop_img)plt.imshow(flip_img.eval())plt.show()## 保存圖像flip_encode_img = tf.image.encode_png(flip_img)with tf.gfile.GFile(r'E:\gitHubProjects\tensorflow_learning\CNN卷積神經網絡-cifar數據集分類\tensorflow_image_proces'r'sing' + '\\flip_img.png', 'wb') as f:f.write(flip_encode_img.eval())# 調整亮度brightness_img = tf.image.random_brightness(flip_img,max_delta=0.8)plt.imshow(brightness_img.eval())plt.show()## 保存圖像brightness_encode_img = tf.image.encode_png(brightness_img)with tf.gfile.GFile(r'E:\gitHubProjects\tensorflow_learning\CNN卷積神經網絡-cifar數據集分類\tensorflow_image_proces'r'sing' + '\\brightness_img.png', 'wb') as f:f.write(brightness_encode_img.eval())# 對比度contrast_img = tf.image.random_brightness(brightness_img, max_delta=0.8)plt.imshow(contrast_img.eval())plt.show()## 保存圖像contrast_encode_img = tf.image.encode_png(contrast_img)with tf.gfile.GFile(r'E:\gitHubProjects\tensorflow_learning\CNN卷積神經網絡-cifar數據集分類\tensorflow_image_proces'r'sing' + '\\contrast_img.png', 'wb') as f:f.write(contrast_encode_img.eval())# 標準化# tf.image.per_image_standardization(image_data)# 打亂數據集# tf.train.shuffle_batch(image,label)tf_imgae_processing()

原圖像

裁剪圖像

翻轉圖像

亮度圖像

對比圖像

總結

以上是生活随笔為你收集整理的【tensorFlow】——图像数据增强、读取图像、保存图像的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。