Hello neural network programmers,

I am currently creating a neural network with keras, as I am not that familiar with tensorflow and it's a bit more difficult.

I want my optimization to optimize the validation loss and not the training loss/accuracy.

Ideally, I would want it to look something like this:

model.compile(optimizer=adam, loss='categorical_crossentropy', metrics=['val_accuray'])

but val_accuracy is not something I can eneter into metrics.

Any ideas on how I can implement that?



1 Answer 1


Welcome to the site! The optimization function in your model creation is not the best place to do what you want. What you should be doing is:

  1. Create the model
  2. Run as many epochs as you want during model training
  3. During the epochs create Keras callbacks that save the best model based on validation accuracy (as opposed to other metrics)

That will allow you to still create your model in an efficient way while ending up with an epoch training process that creates the model with the highest validation accuracy.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.