验证准确性和验证损失开始迅速下降,然后随着CNN和批量标准化开始迅速增加



验证精度在几个时期内开始快速增加,然后在向代码添加Batchnormalization后开始降低。

我的代码是

model = Sequential()
model.add(layers.Conv2D(32,kernel_size=(3,3),activation='relu',input_shape=(224,224,3)))
model.add(tf.keras.layers.BatchNormalization())
model.add(layers.Conv2D(64,(3,3),activation='relu'))
model.add(tf.keras.layers.BatchNormalization())
model.add(layers.MaxPooling2D(pool_size=(2,2)))
model.add(layers.Conv2D(64,(3,3),activation='relu'))
model.add(tf.keras.layers.BatchNormalization())
model.add(layers.MaxPooling2D(pool_size=(2,2)))
model.add(layers.Conv2D(128,(3,3),activation='relu'))
model.add(tf.keras.layers.BatchNormalization())
model.add(layers.MaxPooling2D(pool_size=(2,2)))
model.add(layers.Flatten())
model.add(layers.Dense(256,activation='relu'))
model.add(tf.keras.layers.BatchNormalization())
model.add(layers.Dropout(0.5))
model.add(layers.Dense(3,activation='softmax'))

如果这种行为是,请指导我,我应该检查更多的划时代,或者我在这里做错了什么

输出为:

Epoch 13/200
433/433 - 2220s - loss: 0.3787 - categorical_accuracy: 0.8591 - auc: 0.9604 - val_loss: 0.3948 - val_categorical_accuracy: 0.8529 - val_auc: 0.9584
Epoch 14/200
433/433 - 2206s - loss: 0.4009 - categorical_accuracy: 0.8495 - auc: 0.9559 - val_loss: 1.0093 - val_categorical_accuracy: 0.6535 - val_auc: 0.8175
Epoch 15/200
433/433 - 2205s - loss: 0.3705 - categorical_accuracy: 0.8590 - auc: 0.9622 - val_loss: 1.9217 - val_categorical_accuracy: 0.4865 - val_auc: 0.6711
Epoch 16/200
433/433 - 2208s - loss: 0.3483 - categorical_accuracy: 0.8725 - auc: 0.9661 - val_loss: 1.7980 - val_categorical_accuracy: 0.5639 - val_auc: 0.7213
Epoch 17/200
433/433 - 2213s - loss: 0.3396 - categorical_accuracy: 0.8735 - auc: 0.9676 - val_loss: 10.1333 - val_categorical_accuracy: 0.1929 - val_auc: 0.4038
Epoch 18/200
433/433 - 2223s - loss: 0.3364 - categorical_accuracy: 0.8759 - auc: 0.9684 - val_loss: 0.5666 - val_categorical_accuracy: 0.7819 - val_auc: 0.9228
Epoch 19/200
433/433 - 2249s - loss: 0.3292 - categorical_accuracy: 0.8782 - auc: 0.9695 - val_loss: 0.3376 - val_categorical_accuracy: 0.8699 - val_auc: 0.9686
Epoch 20/200
433/433 - 2216s - loss: 0.3155 - categorical_accuracy: 0.8834 - auc: 0.9718 - val_loss: 1.3117 - val_categorical_accuracy: 0.6213 - val_auc: 0.7883

当模型开始过拟合时会发生这种情况。为了防止这种情况,我们必须在relu激活层之后添加一个丢弃层。防止过拟合的另一种方法是在model.fit()中添加Early Stopping回调

from keras.callbacks import EarlyStopping
es = EarlyStopping(monitor='val_loss', mode='min', verbose=1)
history = model.fit(trainX, trainy, validation_data=(testX, testy), epochs=400, verbose=0, callbacks=[es])

相关内容

  • 没有找到相关文章

最新更新