【神经网络八股扩展】:数据增强
生活随笔
收集整理的這篇文章主要介紹了
【神经网络八股扩展】:数据增强
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
課程來源:人工智能實踐:Tensorflow筆記2
文章目錄
- 前言
- TensorFlow2數(shù)據(jù)增強函數(shù)
- 數(shù)據(jù)增強+網(wǎng)絡(luò)八股代碼:
- 總結(jié)
前言
本講目標:數(shù)據(jù)增強,增大數(shù)據(jù)量
關(guān)于我們?yōu)楹我褂脭?shù)據(jù)增強以及常用的幾種數(shù)據(jù)增強的手法,可以看看下面的文章,雖說是翻譯的,但仍有可鑒之處:
數(shù)據(jù)增強(Data Augmentation)
TensorFlow2數(shù)據(jù)增強函數(shù)
對圖像的增強就是對圖像的簡單形變,用來應(yīng)對因為拍照角度不同引起的圖片形變。
TensorFlow2給出了數(shù)據(jù)增強函數(shù)
劃紅線的部分為需要注意的地方:
數(shù)據(jù)增強+網(wǎng)絡(luò)八股代碼:
import tensorflow as tf from tensorflow.keras.preprocessing.image import ImageDataGeneratorfashion = tf.keras.datasets.fashion_mnist (x_train, y_train), (x_test, y_test) = fashion.load_data() x_train, x_test = x_train / 255.0, x_test / 255.0x_train = x_train.reshape(x_train.shape[0], 28, 28, 1) # 給數(shù)據(jù)增加一個維度,使數(shù)據(jù)和網(wǎng)絡(luò)結(jié)構(gòu)匹配image_gen_train = ImageDataGenerator(rescale=1. / 1., # 如為圖像,分母為255時,可歸至0~1rotation_range=45, # 隨機45度旋轉(zhuǎn)width_shift_range=.15, # 寬度偏移height_shift_range=.15, # 高度偏移horizontal_flip=True, # 水平翻轉(zhuǎn)zoom_range=0.5 # 將圖像隨機縮放閾量50% ) image_gen_train.fit(x_train)model = tf.keras.models.Sequential([tf.keras.layers.Flatten(),tf.keras.layers.Dense(128, activation='relu'),tf.keras.layers.Dense(10, activation='softmax') ])model.compile(optimizer='adam',loss=tf.keras.losses.SparseCategoricalCrossentropy(from_logits=False),metrics=['sparse_categorical_accuracy'])model.fit(image_gen_train.flow(x_train, y_train, batch_size=32), epochs=5, validation_data=(x_test, y_test),validation_freq=1) model.summary()
隨著迭代輪數(shù)增加,準確率不斷提高。但從數(shù)據(jù)集上不能看出數(shù)據(jù)增強的效果,要在實際應(yīng)用中去使用。
總結(jié)
課程鏈接:MOOC人工智能實踐:TensorFlow筆記2
總結(jié)
以上是生活随笔為你收集整理的【神经网络八股扩展】:数据增强的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 生三胎罚多少钱啊?
- 下一篇: 【神经网络扩展】:断点续训和参数提取