Both are done by using Keras callbacks.