머신러닝
Keras - Early Stopping 최적 모델 저장하기 / history 저장하기
브라이언7
2019. 8. 12. 01:11
http://blog.naver.com/cjh226/221468928164
https://keras.io/callbacks/#earlystopping
최적 모델 저장 시 epoch 수 구하기.
- 아래와 같이 파일명에 epoch 수를 포함시킬 수 있다.
[출처] https://snowdeer.github.io/machine-learning/2018/01/09/find-best-model/
from keras.callbacks import ModelCheckpoint
import os
# ...
MODEL_SAVE_FOLDER_PATH = './model/'
if not os.path.exists(MODEL_SAVE_FOLDER_PATH):
os.mkdir(MODEL_SAVE_FOLDER_PATH)
model_path = MODEL_SAVE_FOLDER_PATH + '{epoch:02d}-{val_loss:.4f}.hdf5'
cb_checkpoint = ModelCheckpoint(filepath=model_path, monitor='val_loss',
verbose=1, save_best_only=True)
# ...
model.fit(X, Y, validation_split=0.2, epochs=200, batch_size=200, verbose=0,
callbacks=[cb_checkpoint])
model을 fit한 결과 history를 저장하기.
https://stackoverflow.com/questions/41061457/keras-how-to-save-the-training-history
https://stackoverflow.com/questions/49969006/save-and-load-keras-callbacks-history
https://tykimos.github.io/2017/07/09/Training_Monitoring/