【问题标题】:How do I fix these TensorFlow errors? (Your CPU supports instructions that this TensorFlow binary was not compiled to use: AVX2 FMA)如何修复这些 TensorFlow 错误? (您的 CPU 支持未编译此 TensorFlow 二进制文件以使用的指令:AVX2 FMA)
【发布时间】:2020-02-27 09:40:21
【问题描述】:

我是 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


【解决方案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

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

【讨论】:

    猜你喜欢
    • 2018-12-28
    • 2019-01-11
    • 1970-01-01
    • 1970-01-01
    • 2018-04-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多