본문 바로가기
python/tensorflow,keras

tensorflow.keras.callbacks

by wjwkddyd221001 2022. 10. 1.

1. EarlyStopping 

  • 일정 기준을 만족하면 학습을 정지함
  • model.fit(callbacks = [early_stopping])

2. ModelCheckpoint

  • 일정 기준을 만족하면 가중치를 저장함
from tensorflow.keras.callbacks import ModelCheckpoint, EarlyStopping

early_stopping = EarlyStopping(monitor = 'val_loss',
                               min_delta = 0,
                               patience = 3,
                               verbose = 1,
                               restore_best_weights = True)
checkpoint = ModelCheckpoint(monitor = "val_loss",
                             filepath = MODEL_PATH,
                             save_best_only= True,
                             verbose = 1)                       
                             
history = model.fit(train_generator, epochs = 1000, verbose = 1, 
                    validation_data = validation_generator,
                    callbacks = [early_stopping, checkpoint])

 

'python > tensorflow,keras' 카테고리의 다른 글

keras one-hot encoding  (0) 2022.10.05
학습한 모델 저장  (0) 2022.10.01
keras ImageDataGenerator  (0) 2022.10.01