【发布时间】:2022-10-25 21:35:44
【问题描述】:
我在张量流中写了一个成本损失函数。但是某事出错了,因为错误大于 1,这是不可能的。所以我想查找 y_predicted 和 y_true 的值以及新的计算损失。但我不知道如何获得这些值。 y_pred 和 y_true 都是 <class 'tensorflow.python.framework.ops.Tensor' 类型
这是我的自定义损失函数:
def square_loss_invalid_pixel(y_true,y_pred):
print("type ",type(y_true),type(y_pred))
print("y_true: ", y_true)
print("max:_ ",(tf.reduce_max(y_true)))
print("min:_ ",(tf.reduce_min(y_pred)))
loss = square_loss(y_true, y_pred) # (b, h, w)
print("max:_ ",(tf.reduce_max(loss)))
print("min:_ ",(tf.reduce_min(loss)))
loss = tf.reduce_sum(loss)
return loss
输出是:
y_true: Tensor("IteratorGetNext:2", shape=(None, None, None, None), dtype=float32)
max:_ Tensor("square_loss_invalid_pixel/Max:0", shape=(), dtype=float32)
min:_ Tensor("square_loss_invalid_pixel/Min:0", shape=(), dtype=float32)
max:_ Tensor("square_loss_invalid_pixel/Max_1:0", shape=(), dtype=float32)
min:_ Tensor("square_loss_invalid_pixel/Min_1:0", shape=(), dtype=float32)
如您所见,我没有从中获得太多信息。你知道如何获得正确的价值观吗? 我有批量大小 8 。我从生成器 fct 获得输入。
提前致谢! 此致
【问题讨论】:
-
尝试使用
tf.print而不是print
标签: python tensorflow loss-function