Dataset之图片数据增强:基于TF实现图片数据增强(原始的训练图片reshaped_image→数据增强→distorted_image(训练时直接使用))
生活随笔
收集整理的這篇文章主要介紹了
Dataset之图片数据增强:基于TF实现图片数据增强(原始的训练图片reshaped_image→数据增强→distorted_image(训练时直接使用))
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
Dataset之圖片數據增強:基于TF實現圖片數據增強(原始的訓練圖片reshaped_image→數據增強→distorted_image(訓練時直接使用))
?
?
目錄
數據增強步驟
數據增強實現代碼
?
?
?
數據增強步驟
1、對reshaped_image隨機裁剪圖片:從原始32×32裁剪到24×24小塊進行訓練,因為小塊可以取在圖像的任何位置,所以僅此一步就可以大大增加訓練、集的樣本數目。
2、對裁剪后的小塊進行水平翻轉:隨機翻轉圖片。每張圖片有50%的概率被水平左右翻轉,另有50%的概率保持不變
3、隨機改變亮度和對比度:對得到的圖片進行亮度和對比度的隨機改變。
?
數據增強實現代碼
#TF實現數據增強。原始的訓練圖片是reshaped_image ,最后會得到一個數據增強后的訓練樣本distorted_image。#訓練時,直接使用distorted_image 進行訓練即可。# Randomly crop a [height, width] section of the image.#1、對reshaped_image隨機裁剪圖片,從原始32×32裁剪到24×24小塊進行訓練,因為小塊可以取在圖像的任何位置,所以僅此一步就可以大大增加訓練、集的樣本數目。distorted_image = tf.random_crop(reshaped_image, [height, width, 3])# Randomly flip the image horizontally.#2、對裁剪后的小塊進行水平翻轉。隨機翻轉圖片。每張圖片有50%的概率被水平左右翻轉,另有50%的概率保持不變distorted_image = tf.image.random_flip_left_right(distorted_image)# Because these operations are not commutative, consider randomizing# the order their operation.#3、隨機改變亮度和對比度:對得到的圖片進行亮度和對比度的隨機改變。distorted_image = tf.image.random_brightness(distorted_image,max_delta=63)distorted_image = tf.image.random_contrast(distorted_image,lower=0.2, upper=1.8)?
?
?
?
?
總結
以上是生活随笔為你收集整理的Dataset之图片数据增强:基于TF实现图片数据增强(原始的训练图片reshaped_image→数据增强→distorted_image(训练时直接使用))的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: TF:利用TF读取数据操作,将CIFAR
- 下一篇: Python命令行解析:IDE内点击Ru