【发布时间】:2021-01-31 07:41:13
【问题描述】:
我在 TF 2.3 中编写了自定义损失函数,其中损失由几个子损失组成,因为我想跟踪我使用 tf.print 打印它们的子损失:
def custom_loss_envelop(model_inputs, model, num_bound,model_outputs,lambda_, ener):
def custom_loss(y_true,y_pred):
l1 = ....
l2 = ....
l3 = ....
tf.print("l1:",tf.math.round(l1 * 100)/100,", l2:", tf.math.round(l2 * 100) / 100,
", l3:", tf.math.round(l3 * 100) / 100,
", l4:", tf.math.round(l4 * 100) / 100)
loss = l1 + l2 + l3 + l4
return loss
return custom_loss
问题是这段代码每批都打印损失,而我只希望每个时期都打印。 有什么办法吗?
【问题讨论】: