我如何解决这些TensorFlow错误? (您的CPU支持该TensorFlow二进制文件未编译为使用的指令:AVX2 FMA)

问题描述 投票:-1回答:2

我是TensorFlow的新手,今天我试图安装它并使它全部在PyCharm中运行。我使用了我在网上找到的普通“ pip3 install TensorFlow”。当我在PyCharm中导入TensorFlow时,没有出现任何导入错误,但是我无法使示例代码正常运行。 有人知道我该如何解决这个问题,或者有TensorFlow的任何非常好的完整教程吗?

顺便说一下,我在macOS Catalina上使用MacBook Pro,并运行Python 3.7.4。我对使用PyCharm也很陌生。

代码

# Import `tensorflow`
import tensorflow as tf

# Initialize two constants
x1 = tf.constant([1, 2, 3, 4])
x2 = tf.constant([5, 6, 7, 8])
hello = tf.constant("Hello World!")

# Multiply
result = tf.multiply(x1, x2)

# Intialize the Session
sess = tf.Session()
# Print the result
print(sess.run(hello))
print(sess.run(result))

# Close the session
sess.close()

输出

/Users/anttesoriero/PycharmProjects/TensorTest/venv/bin/python /Users/anttesoriero/PycharmProjects/TensorTest/venv/main.py
2019-10-31 22:06:28.027494: I tensorflow/core/platform/cpu_feature_guard.cc:142] Your CPU supports instructions that this TensorFlow binary was not compiled to use: AVX2 FMA
2019-10-31 22:06:28.052950: I tensorflow/compiler/xla/service/service.cc:168] XLA service 0x7f9ca1b4fa30 executing computations on platform Host. Devices:
2019-10-31 22:06:28.052970: I tensorflow/compiler/xla/service/service.cc:175]   StreamExecutor device (0): Host, Default Version
Traceback (most recent call last):
  File "/Users/anttesoriero/PycharmProjects/TensorTest/venv/main.py", line 13, in <module>
    sess = tf.Session()
AttributeError: module 'tensorflow' has no attribute 'Session'

Process finished with exit code 1

我还将在下面附上所有代码和输出的屏幕截图。TensorFlow code and error output

python tensorflow pycharm
2个回答
1
投票

可能您正在使用Tensorflow-2,并且您的代码仅与tensorflow-1兼容,因为tf-2中没有Session。

您需要从tf-2切换到tf-1才能运行代码。

关于此消息-

Your CPU supports instructions that this TensorFlow binary was not compiled to use: AVX2 FMA

这只是警告而不是错误,这意味着当您通过编译二进制文件而不是像使用pip那样安装预编译的TensorFlow来安装TensorFlow时,将获得性能提升。>


0
投票

也许您应该检查tensorflow的依赖关系。我认为如果依赖关系不完善,tensorflow将无法正常工作。使用pip3 list检查tensorflow的版本,然后找到其依赖项。顺便说一下,我也是TF的新手。

© www.soinside.com 2019 - 2024. All rights reserved.