【问题标题】:TensorFlow: AttributeError: 'Tensor' object has no attribute 'log10'TensorFlow:AttributeError:“张量”对象没有属性“log10”
【发布时间】:2017-06-09 03:41:56
【问题描述】:

我一直在使用支持 python3 的 tensorflow。我的代码中有一行会引发错误。

这里的错误:

return -10. * np.log10(K.mean(K.square(y_pred - y_true)))

AttributeError: 'Tensor' 对象没有属性 'log10'

【问题讨论】:

  • 什么是K?在 K.mean 和 K.square 中?
  • 我正在使用 Keras(已安装)我的代码中有.......from keras import backend as K
  • K.mean 返回什么?它似乎返回一个张量对象而不是一个 nummpy 数组
  • 是的,你是对的……实际上我把它改成了 Theano 后端,它开始工作了 :)
  • 我刚刚遇到了完全相同的问题,请您详细说明您的解决方案吗?

标签: python image-processing tensorflow python-3.5 keras


【解决方案1】:

你可以这样做:

return 10.0 * K.log(1.0 / (K.mean(K.square(y_pred - y_true)))) / K.log(10.0)

【讨论】:

  • 这对我很有用,但我认为你的意思是 -10。您能否详细说明为什么先前的代码在 Tensorflow 中不起作用?我假设它与 numpy 不知道如何处理 tensorflow 结果有关。
猜你喜欢
  • 2016-12-04
  • 2019-03-12
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-08-11
  • 2019-03-08
  • 2019-07-03
相关资源
最近更新 更多