首页 文章

tensorflow:AttributeError:'module'对象没有属性'mul'

提问于
浏览
63

我已经使用了tensorflow一天,但是有一些麻烦,当我导入tensorflow时,会出现AttributeError:'module'对象没有属性'XXXXXX'

环境

我使用ubuntu14.04,python2.7,CUDA工具包8.0和CuDNN v5 . 我的六个和protobuf的版本是:名称:六个版本:1.10.0位置:/usr/local/lib/python2.7/dist-packages需要:名称:protobuf版本:3.2.0位置:/ usr / local / lib / python2.7 / dist-packages需要:six,setuptools

这是我的测试代码:

import tensorflow as tf
a = tf.placeholder(tf.int16)
b = tf.placeholder(tf.int16)
add = tf.add(a, b)
mul = tf.mul(a, b)
with tf.Session() as sess:
    # Run every operation with variable input
    print "Addition with variables: %i" % sess.run(add, feed_dict={a: 2, b: 3})
    print "Multiplication with variables: %i" % sess.run(mul, feed_dict={a: 2, b: 3})

我得到这个输出:

enter image description here

tensorflow安装有问题吗?还是其他任何问题?

3 回答

  • 3

    根据tensorflow 1.0.0 release notes

    不推荐使用tf.mul,tf.sub和tf.neg来支持tf.multiply,tf.subtract和tf.negative .

    您需要将 tf.mul 替换为 tf.multiply .

  • -4

    此操作以前在0.x版本中可用 . 随着release of TF 1.0 they introduced breaking changes to the API . 此外

    不推荐使用tf.mul,tf.sub和tf.neg来支持tf.multiply,tf.subtract和tf.negative

    通过以下理由重命名和更改了许多其他功能:

    几个python API调用已经更改为更接近NumPy .

    因此,您在网络或书籍中找到的许多脚本都无法使用 . 好的是,他们中的大多数可以通过他们的迁移来修复script . 它可以使用 tf_upgrade.py --infile foo.py --outfile foo-upgraded.py 运行 . 它无法解决所有问题(限制列于here),但会为您节省大量工作 .

  • 168

    在python-3中使用 tf.multiply 而不是 tf.mul .

相关问题