I read this https://www.tensorflow.org/guide/keras/custom_callback, but I don't know how I could get all the other parameters.
This is my code
(hits, ndcgs) = evaluate_model(model, testRatings, testNegatives, topK, evaluation_threads)
hr, ndcg, loss = np.array(hits).mean(), np.array(ndcgs).mean(), hist.history['loss'][0]
print('Iteration %d [%.1f s]: HR = %.4f, NDCG = %.4f, loss = %.4f [%.1f s]'
% (epoch, t2-t1, hr, ndcg, loss, time()-t2))
if hr > best_hr:
best_hr, best_ndcg, best_iter = hr, ndcg, epoch
if args.out > 0:
model.save(model_out_file, overwrite=True)
As you can see I need model, hist and model.save.
Is there a way to use these three parameters in a custom callback?
So that I can write all of this into a custom callback.
class CustomCallback(keras.callbacks.Callback):
def on_epoch_end(self, logs=None):
keys = list(logs.keys())
print("Stop training; got log keys: {}".format(keys))