繁体   English   中英

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

[英]tensorflow:AttributeError: 'module' object has no attribute 'mul'

我已经使用了一天的 tensorflow,但是遇到了一些麻烦,当我导入 tensorflow 时,会出现 AttributeError: 'module' object has no attribute '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 需要:六、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})

我得到这个输出:

在此处输入图片说明

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

根据tensorflow 1.0.0 发行说明

tf.multf.subtf.neg被弃用,取而代之的是tf.multiplytf.subtracttf.negative

你将需要更换tf.multf.multiply

此操作以前在 0.x 版本中可用。 随着TF 1.0发布,他们对 API 进行了重大更改 此外

tf.multf.subtf.neg被弃用,取而代之的是tf.multiplytf.subtracttf.negative

许多其他功能被重命名和更改,理由如下:

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

因此,您已经在网上或书中找到的许多脚本将无法使用。 好消息是它们中的大多数都可以通过迁移脚本来修复。 它可以与tf_upgrade.py --infile foo.py --outfile foo-upgraded.py一起运行。 它无法解决所有问题(此处列出限制),但会为您节省大量工作。

2.0 兼容答案

如果我们想从 Tensorflow 1.x 迁移到 2.x, tf.multiply的命令如下所示:

tf.compat.v1.math.multiply, tf.compat.v1.multiply, tf.compat.v2.math.multiply, tf.compat.v2.multiply

如果我们想从 Tensorflow 1.x 迁移到 2.x, tf.subtract的命令如下所示:

tf.compat.v1.math.subtract, tf.compat.v1.subtract, tf.compat.v2.math.subtract, tf.compat.v2.subtract

tf.negative的命令,如果我们想从 Tensorflow 1.x 迁移到 2.x,如下所示:

tf.compat.v1.math.negative, tf.compat.v1.negative, tf.compat.v2.math.negative, 
tf.compat.v2.negative

有关更多详细信息,请参阅此Tensorflow 迁移指南

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM