0 votes
1 view
in Machine Learning by (11.5k points)

Currently, I use the following code:

callbacks = [EarlyStopping(monitor='val_loss', patience=2, verbose=0),ModelCheckpoint(kfold_weights_path, monitor='val_loss', save_best_only=True, verbose=0),

]

model.fit(X_train.astype('float32'), Y_train, batch_size=batch_size,

nb_epoch=nb_epoch, shuffle=True, verbose=1,validation_data=(X_valid, Y_valid), callbacks=callbacks)

It tells Keras to stop training when loss didn't improve for 2 epochs. But I want to stop training after loss became smaller than some constant "THR":

if val_loss < THR: break

I've seen in the documentation there is a possibility to make your own callback: http://keras.io/callbacks/But nothing found how to stop the training process. I need advice.

1 Answer

0 votes
by (33.2k points)

Keras is an open-source neural network library written in Python. There are many classes in Keras. Keras supports the early stopping of training via a callback called EarlyStopping. You can use

tf.keras.callbacks.EarlyStopping

For example:

#python implementation

callbacks = [ EarlyStoppingByLossVal(monitor='val_loss', value=0.00001, verbose=1)

ModelCheckpoint(kfold_weights_path, monitor='val_loss', save_best_only=True, verbose=0), ] model.fit(X_train.astype('float32'),

Y_train, batch_size=batch_size, nb_epoch=nb_epoch, shuffle=True, verbose=1, validation_data=(X_valid, Y_valid), callbacks=callbacks)

It stops training when a monitored quantity(threshold value) has stopped improving. This callback allows you to specify the performance measure to monitor the trigger, and once triggered, it will stop the training process. The EarlyStopping callback is configured when instantiated via arguments. You can find more here.

Welcome to Intellipaat Community. Get your technical queries answered by top developers !


Categories

...