การหยุดการเทรนโมเดลด้วย Early Stopping
Early stopping callback มีประโยชน์มาก เพราะช่วยหยุดการเทรนโมเดลโดยอัตโนมัติเมื่อประสิทธิภาพไม่ดีขึ้นหลังจากผ่านไปหลาย epoch ในการใช้งานฟีเจอร์นี้ ให้ส่ง callback ในรูปแบบ list ไปยังพารามิเตอร์ callback ของโมเดลใน .fit()
โมเดล model ที่สร้างไว้สำหรับตรวจจับธนบัตรปลอมได้ถูกโหลดมาให้แล้ว คราวนี้จะเทรนโดยใช้ early stopping นอกจากนี้ยังมี X_train, y_train, X_test และ y_test พร้อมให้ใช้งาน
แบบฝึกหัดนี้เป็นส่วนหนึ่งของหลักสูตร
Deep Learning เบื้องต้นด้วย Keras
คำแนะนำการฝึกหัด
- Import
EarlyStoppingcallback จากtensorflow.keras.callbacks - กำหนด callback โดยติดตาม
'val_accuracy'และตั้งค่าpatienceไว้ที่ 5 epoch - เทรนโมเดลโดยใช้ early stopping callback
แบบฝึกหัดเชิงโต้ตอบแบบลงมือทำ
ลองทำแบบฝึกหัดนี้โดยเติมโค้ดตัวอย่างนี้ให้สมบูรณ์
# Import the early stopping callback
from tensorflow.____.____ import ____
# Define a callback to monitor val_accuracy
monitor_val_acc = ____(monitor=____,
patience=____)
# Train your model using the early stopping callback
model.____(____, ____,
epochs=1000, validation_data=____,
callbacks= ____)