windows Tensorflow cpu版 指令集加速

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/jacke121/article/details/82051214

问题原因

在macOS通过pip3 install 安装tensorflow(CPU版)后,运行示例代码

import tensorflow as tf
hello = tf.constant('Hello, TensorFlow!')
sess = tf.Session()
print(sess.run(hello).decode())
  •  

运行之后可以正常输出

“Hello, TensorFlow!”

但是有一个警告警告提示:

I tensorflow/core/platform/cpu_feature_guard.cc:140] Your CPU supports instructions that this TensorFlow binary was not compiled to use: AVX2 FMA

原因是没有支持avx2指令加速:

解决Tensorflow 使用时cpu编译时不支持的警告

使用TensorFlow模块时,弹出错误Your CPU supports instructions that this TensorFlow binary was not compiled to use: AVX AVX2

原因是下载TensorFlow的版本不支持cpu的AVX2编译。

扫描二维码关注公众号,回复: 2918301 查看本文章

可能是因为安装时使用的pip install tensorflow ,这样默认会下载X86_64的SIMD版本。

有两种解决办法:

1.忽略这个警告,不看它!

 
  1. import os  

  2. os.environ["TF_CPP_MIN_LOG_LEVEL"]='1' # 这是默认的显示等级,显示所有信息  

  3. os.environ["TF_CPP_MIN_LOG_LEVEL"]='2' # 只显示 warning 和 Error   

  4. os.environ["TF_CPP_MIN_LOG_LEVEL"]='3' # 只显示 Error

我们用第二个就可以了。

2.彻底解决,换成支持cpu用AVX2编译的TensorFlow版本。

首先,卸载原来版本的TensorFlow

pip uninstall tensorflow

完成后可以用pip list查看一下所有库,检查是否成功卸载。

然后去github下载正确的tf版本,Windows点这里下载。其他操作系统可以点这里找到对应的版本。

https://github.com/fo40225/tensorflow-windows-wheel

博主用的win10,python3.6,所以选择如下图:

对应的path在上边的找到对应的.whl下载即可。

然后安装:

pip install tensorflow-1.6.0-cp36-cp36m-win_amd64.whl

成功安装后,再次运行TensorFlow就不会报错啦~

猜你喜欢

转载自blog.csdn.net/jacke121/article/details/82051214