【发布时间】:2018-07-08 16:59:47
【问题描述】:
我想创建一个忽略标签值为 0 的值(=> 像素)的 L2 损失函数。张量 batch[1] 包含标签,而 output 是净输出的张量,两者都有(None,300,300,1) 的形状。
labels_mask = tf.identity(batch[1])
labels_mask[labels_mask > 0] = 1
loss = tf.reduce_sum(tf.square((output-batch[1])*labels_mask))/tf.reduce_sum(labels_mask)
我当前的代码屈服于TypeError: 'Tensor' object does not support item assignment(在第二行)。这样做的张量流方式是什么?我还尝试使用tf.reduce_sum(labels_mask) 使损失正常化,我希望它可以像这样工作。
【问题讨论】:
标签: python tensorflow machine-learning loss loss-function