我正在训练我的第一个迁移学习模型(耶!),当验证损失在 3 个以上的时期内变化不超过 0.1 时,我无法让模型停止训练。
这是相关的代码块
early_stopping = tf.keras.callbacks.EarlyStopping(monitor='val_loss', patience=3, min_delta = 0.1)
model.compile(optimizer='adam',
loss='sparse_categorical_crossentropy',
metrics=['accuracy'],
callbacks=[early_stopping])
EPOCHS = 100
history = model.fit(training_batches,
epochs=EPOCHS,
validation_data=validation_batches)
以下是一些日志:
Epoch 32/100
155/155 [==============================] - 21s 134ms/step - loss: 0.0042 - accuracy: 0.9998 - val_loss: 0.3407 - val_accuracy: 0.9012
Epoch 33/100
155/155 [==============================] - 21s 133ms/step - loss: 0.0040 - accuracy: 0.9998 - val_loss: 0.3443 - val_accuracy: 0.9000
Epoch 34/100
155/155 [==============================] - 21s 134ms/step - loss: 0.0037 - accuracy: 0.9998 - val_loss: 0.3393 - val_accuracy: 0.9019
Epoch 35/100
155/155 [==============================] - 21s 135ms/step - loss: 0.0031 - accuracy: 1.0000 - val_loss: 0.3396 - val_accuracy: 0.9000
Epoch 36/100
155/155 [==============================] - 21s 134ms/step - loss: 0.0028 - accuracy: 1.0000 - val_loss: 0.3390 - val_accuracy: 0.9000
Epoch 37/100
155/155 [==============================] - 21s 133ms/step - loss: 0.0026 - accuracy: 1.0000 - val_loss: 0.3386 - val_accuracy: 0.9025
Epoch 38/100
155/155 [==============================] - 21s 133ms/step - loss: 0.0024 - accuracy: 1.0000 - val_loss: 0.3386 - val_accuracy: 0.8994
Epoch 39/100
155/155 [==============================] - 21s 133ms/step - loss: 0.0022 - accuracy: 1.0000 - val_loss: 0.3386 - val_accuracy: 0.9019
问题:
- 当我将 EarlyStopping 回调设置为监控 val_loss 时,为什么训练没有在 Epoch 37 停止?
- 我可以做更复杂的 EarlyStopping 回调吗?类似于“如果 val_accuracy > 0.90 && val_loss 在 3 个 Epochs 中变化不超过 0.1”。如果可以的话,我可以得到一个教程的链接吗?