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

歡迎訪問 生活随笔!

生活随笔

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

编程问答

【神经网络八股扩展】:数据增强

發布時間:2023/12/1 编程问答 34 豆豆
生活随笔 收集整理的這篇文章主要介紹了 【神经网络八股扩展】:数据增强 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

課程來源:人工智能實踐:Tensorflow筆記2

文章目錄

  • 前言
  • TensorFlow2數據增強函數
  • 數據增強+網絡八股代碼:
  • 總結


前言

本講目標:數據增強,增大數據量
關于我們為何要使用數據增強以及常用的幾種數據增強的手法,可以看看下面的文章,雖說是翻譯的,但仍有可鑒之處:
數據增強(Data Augmentation)


TensorFlow2數據增強函數

對圖像的增強就是對圖像的簡單形變,用來應對因為拍照角度不同引起的圖片形變。
TensorFlow2給出了數據增強函數

image_gen_train =tf.keras.preprocessing.image.ImageDataGenerator( rescale = 所有數據將乘以該數值 rotation_range =隨機旋轉角度數范圍 width_shift_range = 隨機寬度偏移量 height_shift_range =隨機高度偏移量 horizontal_flip =是否隨機水平翻轉 zoom_range =隨機縮放的范圍[1-n,1+n]) image_gen_train.fit(x_train) fit需要輸入4維數據,所以將x_train reshape為(60000,28,28,1) 這個1表示單通道灰度值 model.fit同步更新為.flow形式

劃紅線的部分為需要注意的地方:

數據增強+網絡八股代碼:

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) # 給數據增加一個維度,使數據和網絡結構匹配image_gen_train = ImageDataGenerator(rescale=1. / 1., # 如為圖像,分母為255時,可歸至0~1rotation_range=45, # 隨機45度旋轉width_shift_range=.15, # 寬度偏移height_shift_range=.15, # 高度偏移horizontal_flip=True, # 水平翻轉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()


隨著迭代輪數增加,準確率不斷提高。但從數據集上不能看出數據增強的效果,要在實際應用中去使用。

總結

課程鏈接:MOOC人工智能實踐:TensorFlow筆記2

總結

以上是生活随笔為你收集整理的【神经网络八股扩展】:数据增强的全部內容,希望文章能夠幫你解決所遇到的問題。

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