亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

如何提高深度學習的準確性和驗證準確性

如何提高深度學習的準確性和驗證準確性

一只名叫tom的貓 2023-09-05 17:20:08
我正在用自己的數據訓練 CNN,我在相同的數據上嘗試了 resnet50 和 resnet101 以及我自己的模型,準確度為 63,驗證準確度為 0.08。我知道問題出在我的數據上,我想在拆分數據之前嘗試對數據進行洗牌,但我的數據分為 26 個不同的類,如何在將數據拆分為訓練集和驗證集之前對數據進行洗牌。我的數據集超過 36K 圖像。(trainX, testX, trainY, testY) = train_test_split(data, labels,    test_size=0.25, stratify=labels, random_state=42)# initialize the training data augmentation objecttrainAug = ImageDataGenerator(    rotation_range=30,    zoom_range=0.15,    width_shift_range=0.2,    height_shift_range=0.2,    shear_range=0.15,    horizontal_flip=True,    fill_mode="nearest")# initialize the validation/testing data augmentation object (which# we'll be adding mean subtraction to)valAug = ImageDataGenerator()# define the ImageNet mean subtraction (in RGB order) and set the# the mean subtraction value for each of the data augmentation# objectsmean = np.array([123.68, 116.779, 103.939], dtype='float32')trainAug.mean = meanvalAug.mean = meanmodel = Sequential()# The first two layers with 32 filters of window size 3x3model.add(Conv2D(32, (5, 5), padding='same', activation='relu', input_shape=(224, 224, 3)))model.add(Conv2D(32, (5, 5), activation='relu'))model.add(MaxPooling2D(pool_size=(2, 2)))model.add(Dropout(0.25))model.add(Conv2D(64, (5, 5), padding='same', activation='relu'))model.add(Conv2D(64, (5, 5), activation='relu'))model.add(MaxPooling2D(pool_size=(2, 2)))model.add(Dropout(0.25))model.add(Conv2D(128, (3, 3), padding='same', activation='relu'))model.add(Conv2D(128, (3, 3), activation='relu'))model.add(MaxPooling2D(pool_size=(2, 2)))model.add(Dropout(0.25))model.add(Flatten())model.add(Dense(512, activation='relu'))model.add(Dropout(0.5))model.add(Dense(labels, activation='softmax'))
查看完整描述

1 回答

?
qq_笑_17

TA貢獻1818條經驗 獲得超7個贊

您可以使用 ImageDataGenerator 的驗證 split 關鍵字自動拆分訓練數據和測試數據。


train_datagen = ImageDataGenerator(rescale=1./255,

    shear_range=0.2,

    zoom_range=0.2,

    horizontal_flip=True,

    validation_split=0.2) # set validation split


train_generator = train_datagen.flow_from_directory(

    train_data_dir,

    target_size=(img_height, img_width),

    batch_size=batch_size,

    class_mode='binary',

    subset='training') # set as training data


validation_generator = train_datagen.flow_from_directory(

    train_data_dir, # same directory as training data

    target_size=(img_height, img_width),

    batch_size=batch_size,

    class_mode='binary',

    subset='validation') # set as validation data


model.fit_generator(

    train_generator,

    steps_per_epoch = train_generator.samples // batch_size,

    validation_data = validation_generator, 

    validation_steps = validation_generator.samples // batch_size,

    epochs = nb_epochs)

當ImageDataGenerator自動打亂您的輸入數據時,您使用ImageDataGenerator的數據會被打亂和分割。


在你的情況下,你需要flow而不是flow_from_directory


查看完整回答
反對 回復 2023-09-05
  • 1 回答
  • 0 關注
  • 99 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號