完美解决Tensorflow不支持AVX2指令集问题|指令集加速
在pycharm中安装tensorflow后
![在这里插入图片描述](https://img-blog.csdnimg.cn/20200712190018795.png)运行如下测试代码:
1 | import tensorflow as tf |
发现会报一行错误Your CPU supports instructions that this TensorFlow binary was not compiled to use: AVX2
大概意思是安装的tensorflow版本不支持cpu的AVX2编译
可能是因为安装时使用的pip install tensorflow ,这样默认会下载X86_64的SIMD版本。
查找解决办法后,有以下两种办法:
1.忽略屏蔽这个警告
在代码最前面添加如下两行代码
import os
os.environ["TF_CPP_MIN_LOG_LEVEL"]='2' # 只显示 warning 和 Error
2.彻底解决,换成支持cpu用AVX2编译的TensorFlow版本。
首先卸载原来安装的tensorflow版本pip uninstall tensorflow
在这里下载对应版本的tensorflow:https://github.com/fo40225/tensorflow-windows-wheel,比如我需要的是CPU+AVX2+Python3.6,那么我就在下面的列表中选择这个:
Path | Compiler | CUDA/cuDNN | SIMD | Notes |
---|---|---|---|---|
2.2.0\py37\CPU+GPU\cuda102cudnn76sse2 | VS2019 16.5 | 10.2.89_441.22/7.6.5.32 | x86_64 | Python 3.7/Compute 3.0 |
2.2.0\py37\CPU+GPU\cuda102cudnn76avx2 | VS2019 16.5 | 10.2.89_441.22/7.6.5.32 | AVX2 | Python 3.7/Compute 3.0,3.5,5.0,5.2,6.1,7.0,7.5 |
2.1.0\py37\CPU+GPU\cuda102cudnn76sse2 | VS2019 16.4 | 10.2.89_441.22/7.6.5.32 | x86_64 | Python 3.7/Compute 3.0 |
2.1.0\py37\CPU+GPU\cuda102cudnn76avx2 | VS2019 16.4 | 10.2.89_441.22/7.6.5.32 | AVX2 | Python 3.7/Compute 3.0,3.5,5.0,5.2,6.1,7.0,7.5 |
2.0.0\py37\CPU\sse2 | VS2019 16.3 | No | x86_64 | Python 3.7 |
2.0.0\py37\CPU\avx2 | VS2019 16.3 | No | AVX2 | Python 3.7 |
2.0.0\py37\GPU\cuda101cudnn76sse2 | VS2019 16.3 | 10.1.243_426.00/7.6.4.38 | x86_64 | Python 3.7/Compute 3.0 |
2.0.0\py37\GPU\cuda101cudnn76avx2 | VS2019 16.3 | 10.1.243_426.00/7.6.4.38 | AVX2 | Python 3.7/Compute 3.0,3.5,5.0,5.2,6.1,7.0,7.5 |
1.15.0\py37\CPU+GPU\cuda101cudnn76sse2 | VS2019 16.3 | 10.1.243_426.00/7.6.4.38 | x86_64 | Python 3.7/Compute 3.0 |
1.15.0\py37\CPU+GPU\cuda101cudnn76avx2 | VS2019 16.3 | 10.1.243_426.00/7.6.4.38 | AVX2 | Python 3.7/Compute 3.0,3.5,5.0,5.2,6.1,7.0,7.5 |
1.14.0\py37\CPU\sse2 | VS2019 16.1 | No | x86_64 | Python 3.7 |
1.14.0\py37\CPU\avx2 | VS2019 16.1 | No | AVX2 | Python 3.7 |
1.14.0\py37\GPU\cuda101cudnn76sse2 | VS2019 16.1 | 10.1.168_425.25/7.6.0.64 | x86_64 | Python 3.7/Compute 3.0 |
1.14.0\py37\GPU\cuda101cudnn76avx2 | VS2019 16.1 | 10.1.168_425.25/7.6.0.64 | AVX2 | Python 3.7/Compute 3.0,3.5,5.0,5.2,6.1,7.0,7.5 |
1.13.1\py37\CPU\sse2 | VS2017 15.9 | No | x86_64 | Python 3.7 |
1.13.1\py37\CPU\avx2 | VS2017 15.9 | No | AVX2 | Python 3.7 |
1.13.1\py37\GPU\cuda101cudnn75sse2 | VS2017 15.9 | 10.1.105_418.96/7.5.0.56 | x86_64 | Python 3.7/Compute 3.0 |
1.13.1\py37\GPU\cuda101cudnn75avx2 | VS2017 15.9 | 10.1.105_418.96/7.5.0.56 | AVX2 | Python 3.7/Compute 3.0,3.5,5.0,5.2,6.1,7.0,7.5 |
1.12.0\py36\CPU\sse2 | VS2017 15.8 | No | x86_64 | Python 3.6 |
1.12.0\py36\CPU\avx2 | VS2017 15.8 | No | AVX2 | Python 3.6 |
1.12.0\py36\GPU\cuda100cudnn73sse2 | VS2017 15.8 | 10.0.130_411.31/7.3.1.20 | x86_64 | Python 3.6/Compute 3.0 |
1.12.0\py36\GPU\cuda100cudnn73avx2 | VS2017 15.8 | 10.0.130_411.31/7.3.1.20 | AVX2 | Python 3.6/Compute 3.0,3.5,5.0,5.2,6.1,7.0,7.5 |
1.12.0\py37\CPU\sse2 | VS2017 15.8 | No | x86_64 | Python 3.7 |
1.12.0\py37\CPU\avx2 | VS2017 15.8 | No | AVX2 | Python 3.7 |
1.12.0\py37\GPU\cuda100cudnn73sse2 | VS2017 15.8 | 10.0.130_411.31/7.3.1.20 | x86_64 | Python 3.7/Compute 3.0 |
1.12.0\py37\GPU\cuda100cudnn73avx2 | VS2017 15.8 | 10.0.130_411.31/7.3.1.20 | AVX2 | Python 3.7/Compute 3.0,3.5,5.0,5.2,6.1,7.0,7.5 |
1.11.0\py36\CPU\sse2 | VS2017 15.8 | No | x86_64 | Python 3.6 |
1.11.0\py36\CPU\avx2 | VS2017 15.8 | No | AVX2 | Python 3.6 |
1.11.0\py36\GPU\cuda100cudnn73sse2 | VS2017 15.8 | 10.0.130_411.31/7.3.0.29 | x86_64 | Python 3.6/Compute 3.0 |
1.11.0\py36\GPU\cuda100cudnn73avx2 | VS2017 15.8 | 10.0.130_411.31/7.3.0.29 | AVX2 | Python 3.6/Compute 3.0,3.5,5.0,5.2,6.1,7.0,7.5 |
1.11.0\py37\CPU\sse2 | VS2017 15.8 | No | x86_64 | Python 3.7 |
1.11.0\py37\CPU\avx2 | VS2017 15.8 | No | AVX2 | Python 3.7 |
1.11.0\py37\GPU\cuda100cudnn73sse2 | VS2017 15.8 | 10.0.130_411.31/7.3.0.29 | x86_64 | Python 3.7/Compute 3.0 |
1.11.0\py37\GPU\cuda100cudnn73avx2 | VS2017 15.8 | 10.0.130_411.31/7.3.0.29 | AVX2 | Python 3.7/Compute 3.0,3.5,5.0,5.2,6.1,7.0,7.5 |
1.10.0\py36\CPU\sse2 | VS2017 15.8 | No | x86_64 | Python 3.6 |
1.10.0\py36\CPU\avx2 | VS2017 15.8 | No | AVX2 | Python 3.6 |
1.10.0\py36\GPU\cuda92cudnn72sse2 | VS2017 15.8 | 9.2.148.1/7.2.1.38 | x86_64 | Python 3.6/Compute 3.0 |
1.10.0\py36\GPU\cuda92cudnn72avx2 | VS2017 15.8 | 9.2.148.1/7.2.1.38 | AVX2 | Python 3.6/Compute 3.0,3.5,5.0,5.2,6.1,7.0 |
1.10.0\py27\CPU\sse2 | VS2017 15.8 | No | x86_64 | Python 2.7 |
1.10.0\py27\CPU\avx2 | VS2017 15.8 | No | AVX2 | Python 2.7 |
1.10.0\py27\GPU\cuda92cudnn72sse2 | VS2017 15.8 | 9.2.148.1/7.2.1.38 | x86_64 | Python 2.7/Compute 3.0 |
1.10.0\py27\GPU\cuda92cudnn72avx2 | VS2017 15.8 | 9.2.148.1/7.2.1.38 | AVX2 | Python 2.7/Compute 3.0,3.5,5.0,5.2,6.1,7.0 |
1.9.0\py36\CPU\sse2 | VS2017 15.7 | No | x86_64 | Python 3.6 |
1.9.0\py36\CPU\avx2 | VS2017 15.7 | No | AVX2 | Python 3.6 |
1.9.0\py36\GPU\cuda92cudnn71sse2 | VS2017 15.7 | 9.2.148/7.1.4 | x86_64 | Python 3.6/Compute 3.0 |
1.9.0\py36\GPU\cuda92cudnn71avx2 | VS2017 15.7 | 9.2.148/7.1.4 | AVX2 | Python 3.6/Compute 3.0,3.5,5.0,5.2,6.1,7.0 |
1.9.0\py27\CPU\sse2 | VS2017 15.7 | No | x86_64 | Python 2.7 |
1.9.0\py27\CPU\avx2 | VS2017 15.7 | No | AVX2 | Python 2.7 |
1.9.0\py27\GPU\cuda92cudnn71sse2 | VS2017 15.7 | 9.2.148/7.1.4 | x86_64 | Python 2.7/Compute 3.0 |
1.9.0\py27\GPU\cuda92cudnn71avx2 | VS2017 15.7 | 9.2.148/7.1.4 | AVX2 | Python 2.7/Compute 3.0,3.5,5.0,5.2,6.1,7.0 |
1.8.0\py36\CPU\sse2 | VS2017 15.4 | No | x86_64 | Python 3.6 |
1.8.0\py36\CPU\avx2 | VS2017 15.4 | No | AVX2 | Python 3.6 |
1.8.0\py36\GPU\cuda91cudnn71sse2 | VS2017 15.4 | 9.1.85.3/7.1.3 | x86_64 | Python 3.6/Compute 3.0 |
1.8.0\py36\GPU\cuda91cudnn71avx2 | VS2017 15.4 | 9.1.85.3/7.1.3 | AVX2 | Python 3.6/Compute 3.0,3.5,5.0,5.2,6.1,7.0 |
1.8.0\py27\CPU\sse2 | VS2017 15.4 | No | x86_64 | Python 2.7 |
1.8.0\py27\CPU\avx2 | VS2017 15.4 | No | AVX2 | Python 2.7 |
1.8.0\py27\GPU\cuda91cudnn71sse2 | VS2017 15.4 | 9.1.85.3/7.1.3 | x86_64 | Python 2.7/Compute 3.0 |
1.8.0\py27\GPU\cuda91cudnn71avx2 | VS2017 15.4 | 9.1.85.3/7.1.3 | AVX2 | Python 2.7/Compute 3.0,3.5,5.0,5.2,6.1,7.0 |
1.7.0\py36\CPU\sse2 | VS2017 15.4 | No | x86_64 | Python 3.6 |
1.7.0\py36\CPU\avx2 | VS2017 15.4 | No | AVX2 | Python 3.6 |
1.7.0\py36\GPU\cuda91cudnn71sse2 | VS2017 15.4 | 9.1.85.3/7.1.2 | x86_64 | Python 3.6/Compute 3.0 |
1.7.0\py36\GPU\cuda91cudnn71avx2 | VS2017 15.4 | 9.1.85.3/7.1.2 | AVX2 | Python 3.6/Compute 3.0,3.5,5.0,5.2,6.1,7.0 |
1.7.0\py27\CPU\sse2 | VS2017 15.4 | No | x86_64 | Python 2.7 |
1.7.0\py27\CPU\avx2 | VS2017 15.4 | No | AVX2 | Python 2.7 |
1.7.0\py27\GPU\cuda91cudnn71sse2 | VS2017 15.4 | 9.1.85.3/7.1.2 | x86_64 | Python 2.7/Compute 3.0 |
1.7.0\py27\GPU\cuda91cudnn71avx2 | VS2017 15.4 | 9.1.85.3/7.1.2 | AVX2 | Python 2.7/Compute 3.0,3.5,5.0,5.2,6.1,7.0 |
1.6.0\py36\CPU\sse2 | VS2017 15.4 | No | x86_64 | Python 3.6 |
1.6.0\py36\CPU\avx2 | VS2017 15.4 | No | AVX2 | Python 3.6 |
1.6.0\py36\GPU\cuda91cudnn71sse2 | VS2017 15.4 | 9.1.85.3/7.1.1 | x86_64 | Python 3.6/Compute 3.0 |
1.6.0\py36\GPU\cuda91cudnn71avx2 | VS2017 15.4 | 9.1.85.3/7.1.1 | AVX2 | Python 3.6/Compute 3.0,3.5,5.0,5.2,6.1,7.0 |
1.6.0\py27\CPU\sse2 | VS2017 15.4 | No | x86_64 | Python 2.7 |
1.6.0\py27\CPU\avx2 | VS2017 15.4 | No | AVX2 | Python 2.7 |
1.6.0\py27\GPU\cuda91cudnn71sse2 | VS2017 15.4 | 9.1.85.2/7.1.1 | x86_64 | Python 2.7/Compute 3.0 |
1.6.0\py27\GPU\cuda91cudnn71avx2 | VS2017 15.4 | 9.1.85.2/7.1.1 | AVX2 | Python 2.7/Compute 3.0,3.5,5.0,5.2,6.1,7.0 |
1.5.0\py36\CPU\avx | VS2017 15.4 | No | AVX | Python 3.6 |
1.5.0\py36\CPU\avx2 | VS2017 15.4 | No | AVX2 | Python 3.6 |
1.5.0\py36\GPU\cuda91cudnn7avx2 | VS2017 15.4 | 9.1.85/7.0.5 | AVX2 | Python 3.6/Compute 3.0,3.5,5.0,5.2,6.1,7.0 |
1.5.0\py27\CPU\sse2 | VS2017 15.4 | No | x86_64 | Python 2.7 |
1.5.0\py27\CPU\avx | VS2017 15.4 | No | AVX | Python 2.7 |
1.5.0\py27\CPU\avx2 | VS2017 15.4 | No | AVX2 | Python 2.7 |
1.5.0\py27\GPU\cuda91cudnn7sse2 | VS2017 15.4 | 9.1.85/7.0.5 | x86_64 | Python 2.7/Compute 3.0 |
1.5.0\py27\GPU\cuda91cudnn7avx2 | VS2017 15.4 | 9.1.85/7.0.5 | AVX2 | Python 2.7/Compute 3.0,3.5,5.0,5.2,6.1,7.0 |
1.4.0\py36\CPU\avx | VS2017 15.4 | No | AVX | Python 3.6 |
1.4.0\py36\CPU\avx2 | VS2017 15.4 | No | AVX2 | Python 3.6 |
1.4.0\py36\GPU\cuda91cudnn7avx2 | VS2017 15.4 | 9.1.85/7.0.5 | AVX2 | Python 3.6/Compute 3.0,3.5,5.0,5.2,6.1,7.0 |
1.3.0\py36\CPU\avx | VS2015 Update 3 | No | AVX | Python 3.6 |
1.3.0\py36\CPU\avx2 | VS2015 Update 3 | No | AVX2 | Python 3.6 |
1.3.0\py36\GPU\cuda8cudnn6avx2 | VS2015 Update 3 | 8.0.61.2/6.0.21 | AVX2 | Python 3.6/Compute 3.0,3.5,5.0,5.2,6.1 |
1.2.1\py36\CPU\avx | VS2015 Update 3 | No | AVX | Python 3.6 |
1.2.1\py36\CPU\avx2 | VS2015 Update 3 | No | AVX2 | Python 3.6 |
1.2.1\py36\GPU\cuda8cudnn6avx2 | VS2015 Update 3 | 8.0.61.2/6.0.21 | AVX2 | Python 3.6/Compute 3.0,3.5,5.0,5.2,6.1 |
1.1.0\py36\CPU\avx | VS2015 Update 3 | No | AVX | Python 3.6 |
1.1.0\py36\CPU\avx2 | VS2015 Update 3 | No | AVX2 | Python 3.6 |
1.1.0\py36\GPU\cuda8cudnn6avx2 | VS2015 Update 3 | 8.0.61.2/6.0.21 | AVX2 | Python 3.6/Compute 3.0,3.5,5.0,5.2,6.1 |
1.0.0\py36\CPU\sse2 | VS2015 Update 3 | No | x86_64 | Python 3.6 |
1.0.0\py36\CPU\avx | VS2015 Update 3 | No | AVX | Python 3.6 |
1.0.0\py36\CPU\avx2 | VS2015 Update 3 | No | AVX2 | Python 3.6 |
1.0.0\py36\GPU\cuda8cudnn51sse2 | VS2015 Update 3 | 8.0.61.2/5.1.10 | x86_64 | Python 3.6/Compute 3.0 |
1.0.0\py36\GPU\cuda8cudnn51avx2 | VS2015 Update 3 | 8.0.61.2/5.1.10 | AVX2 | Python 3.6/Compute 3.0,3.5,5.0,5.2,6.1 |
0.12.0\py35\CPU\avx | VS2015 Update 3 | No | AVX | Python 3.5 |
0.12.0\py35\CPU\avx2 | VS2015 Update 3 | No | AVX2 | Python 3.5 |
0.12.0\py35\GPU\cuda8cudnn51avx2 | VS2015 Update 3 | 8.0.61.2/5.1.10 | AVX2 | Python 3.5/Compute 3.0,3.5,5.0,5.2,6.1 |
找到对应的.whl文件
下载该文件,我用google浏览器下载一直显示无法访问
后来选用Edge浏览器打开就好啦,直接就下载成功了。
此处放上tensorflow-1.12.0-cp36-cp36m-win_amd64.whl的下载链接:
链接:https://pan.baidu.com/s/1CvKUtmM1zHyJyJk87eFEUA
提取码:o85f
然后用activate 进入自己创建的虚拟环境
运行pip install tensorflow-1.12.0-cp36-cp36m-win_amd64.whl
命令安装
最后用conda list
命令看安装了那些包
然后再次运行代码,就不会报AVX2的错误啦