Home > Net >  Continue training keras model on validation set
Continue training keras model on validation set

Time:11-04

I created keras model and fitted it on some part of training set with validation data. Then i was satisfied with model accuracy and i want to fit it on validation set as well for maximum performance on test data. How should i do that?

I have some guesses:

  1. Fit model with only validation set model.fit(val_ds)
  2. Fit model with full data (train validation) model.fit(full_ds)

CodePudding user response:

Model accuracy is not really the right measure for your models performance. You want your model to perform well on inputs it has not seen before. That is the purpose of creating a validation set. It sees how well your model extrapolates to classifying data it has not seen previously. Now you can optimize your model to achieve the lowest validation loss and use that model on your test set. Typically you can achieve a lower validation loss before over fitting occurs by:

1 - add one or more drop out layers in your model
2 - use kernel regularizers
3 - use an adjustable larning like keras reduce learning rate on plateau
4 - use keras callback early stopping 

Documentation on keras callbacks is here. Documentation of regularisers is here.. Some examples of the code I use is shown below

es=tf.keras.callbacks.EarlyStopping( monitor='val_loss', min_delta=0, patience=3,
    verbose=1,   mode='auto',  baseline=None,    restore_best_weights=True)
es=tf.keras.callbacks.EarlyStopping( monitor='val_loss', min_delta=0, patience=3,
    verbose=1,   mode='auto',  baseline=None,    restore_best_weights=True)
in model.fit set callbacks=[es]
----

if you have dense layers try the code below


x = Dense(256, kernel_regularizer = regularizers.l2(l = 0.016),activity_regularizer=regularizers.l1(0.006), bias_regularizer=regularizers.l1(0.006) ,activation='relu')(x)

CodePudding user response:

I don't think you should do that. The split into train-test sets is supposed to be a check for your model to see, if it generalizes to data that it hasn't seen yet. When you start fitting the data to the test set, you are skewing your results, basically getting rid of the reason you created the test set in the first place. Test sets are supposed the only be used "once". You only train on the training data. You can tune parameters with the "in-between" dev-set, but this is not for training either. Once you've done that, you can use the test set as a final validation.

  • Related