Model Checkpoint and Callback in Keras
5.7 هزار بار بازدید -
2 سال پیش
-
ModelCheckpoint callback is used in
ModelCheckpoint callback is used in conjunction with training using model. fit() to save a model or weights (in a checkpoint file) at some interval, so the model or weights can be loaded later to continue the training from the state saved.
from tensorflow.keras.callbacks import ModelCheckpoint
Checkpoint to save best model per epoch
model_filepath = "/content/drive/My Drive/model-{epoch:02d}-{val_accuracy:.4f}.hdf5"
checkpoint = ModelCheckpoint(
filepath=model_filepath,
monitor='val_accuracy',
mode='max',
save_best_only=True,
verbose=1
)
history=model.fit(
train_ds,
validation_data=val_ds,
epochs=50,callbacks=[checkpoint]
)
from tensorflow.keras.callbacks import ModelCheckpoint
Checkpoint to save best model per epoch
model_filepath = "/content/drive/My Drive/model-{epoch:02d}-{val_accuracy:.4f}.hdf5"
checkpoint = ModelCheckpoint(
filepath=model_filepath,
monitor='val_accuracy',
mode='max',
save_best_only=True,
verbose=1
)
history=model.fit(
train_ds,
validation_data=val_ds,
epochs=50,callbacks=[checkpoint]
)
2 سال پیش
در تاریخ 1401/07/21 منتشر شده
است.
5,796
بـار بازدید شده