python - 属性错误 : 'Tensor' object has no attribute 'numpy' in custom loss function (Tensorflow 2. 1.0)

标签 python numpy tensorflow loss-function loss

我想用自定义损失函数训练模型,为此,我需要在下面的方法中将张量转换为 numpy 数组:

def median_loss_estimation(y_true, y_predicted):
    a = y_predicted.numpy()

但我有这个错误:
AttributeError: 'Tensor' object has no attribute 'numpy'

为什么?
如何将张量转换为 numpy 数组?

最佳答案

答案是:放run_eagerly=Truemodel.compile !

关于python - 属性错误 : 'Tensor' object has no attribute 'numpy' in custom loss function (Tensorflow 2. 1.0),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61064229/

相关文章:

Python-3x Unicode 打印与写入

python - TensorFlow: AttributeError: 'Session' 对象没有属性 '_session'

tensorflow - 在 flutter 中运行 tensorflow-lite 的最佳选择是什么?

python - 使用 Python 根据特殊字符将列表切片为嵌套列表

python - 为什么 python 不将标准输入输入作为字典读取?

python - 预测时如何处理测试数据onehoten编码后的类别不匹配?

numpy - 使用特定形式的损失梯度相对于其参数来最小化损失函数

python - 使用opengl4,可以将`uniform`变量映射到我的用户空间内存吗?

python - matplotlib 轮廓输入数组顺序

python - 如何在python中选择矩阵中的非零列