Optimization based on validation and not training
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:


Create the model
Run as many epochs as you want during model training
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.