Saving best model in keras

后端 未结 3 1070
隐瞒了意图╮
隐瞒了意图╮ 2020-12-29 20:22

I use the following code when training a model in keras

from keras.callbacks import EarlyStopping

model = Sequential()
model.add(Dense(100, activation=\'rel         


        
3条回答
  •  自闭症患者
    2020-12-29 21:12

    EarlyStopping's restore_best_weights argument will do the trick:

    restore_best_weights: whether to restore model weights from the epoch with the best value of the monitored quantity. If False, the model weights obtained at the last step of training are used.

    So not sure how your early_stopping_monitor is defined, but going with all the default settings and seeing you already imported EarlyStopping you could do this:

    early_stopping_monitor = EarlyStopping(
        monitor='val_loss',
        min_delta=0,
        patience=0,
        verbose=0,
        mode='auto',
        baseline=None,
        restore_best_weights=True
    )
    

    And then just call model.fit() with callbacks=[early_stopping_monitor] like you already do.

提交回复
热议问题