【发布时间】:2020-12-15 08:01:19
【问题描述】:
我阅读了这个https://www.tensorflow.org/guide/keras/custom_callback,但我不知道如何获取所有其他参数。
这是我的代码
(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)
如您所见,我需要 model、hist 和 model.save。
有没有办法在自定义回调中使用这三个参数?
这样我就可以将所有这些写入自定义回调中。
class CustomCallback(keras.callbacks.Callback):
def on_epoch_end(self, logs=None):
keys = list(logs.keys())
print("Stop training; got log keys: {}".format(keys))
【问题讨论】:
标签: python tensorflow keras callback