1

我正在尝试使用 def 'tf.losses.mean_squared_error'。但我越来越

NameError: name 'Reduction' is not defined

我正在使用 TF 1.13。这是一些导入问题还是 tf.losses.mean_squared_error 函数有任何更新?

我的代码如下。

def reg_loss(pred, GT):
    loss = tf.losses.mean_squared_error(
    labels = GT,
    predictions = pred,
    weights=1.0,
    scope=None,
    loss_collection=tf.GraphKeys.LOSSES,
    reduction=Reduction.SUM_BY_NONZERO_WEIGHTS)

    return reg_loss

谁能帮我解决这个问题?

4

2 回答 2

1

使用tf.losses.Reduction.SUM_BY_NONZERO_WEIGHTS 它解决了我的问题。

于 2019-11-21T06:26:03.990 回答
0

完整的类路径应该是这个文档

tf.compat.v1.losses.Reduction

所以解决方案可以是

import tensorflow as tf # optional alias
from tf.compat.v1.losses import Reduction
于 2021-12-31T09:10:10.957 回答