解决报错:Your CPU supports instructions that this TensorFlow binary was not compiled to use: AVX AVX2

-----------------特此说明:全文废话连篇,但是“取经”路上的历程,慎看---------------------

tensorflow小白的我,在运行案例时报错如下图,且同此文:https://stackoverflow.com/questions/47068709/your-cpu-supports-instructions-that-this-tensorflow-binary-was-not-compiled-to-u?answertab=votes#tab-top

遇到了相同的问题(见倒数后两行):

WARNING:tensorflow:From D:\Application\Python\Anaconda3\lib\site-packages\tensorflow\contrib\learn\python\learn\estimators\dnn.py:378: multi_class_head (from tensorflow.contrib.learn.python.learn.estimators.head) is deprecated and will be removed in a future version.
Instructions for updating:
Please switch to tf.contrib.estimator.*_head.
WARNING:tensorflow:From D:\Application\Python\Anaconda3\lib\site-packages\tensorflow\contrib\learn\python\learn\estimators\estimator.py:1179: BaseEstimator.__init__ (from tensorflow.contrib.learn.python.learn.estimators.estimator) is deprecated and will be removed in a future version.
Instructions for updating:
Please replace uses of any Estimator from tf.contrib.learn with an Estimator from tf.estimator.*
WARNING:tensorflow:From D:\Application\Python\Anaconda3\lib\site-packages\tensorflow\contrib\learn\python\learn\estimators\estimator.py:427: RunConfig.__init__ (from tensorflow.contrib.learn.python.learn.estimators.run_config) is deprecated and will be removed in a future version.
Instructions for updating:
When switching to tf.estimator.Estimator, use tf.estimator.RunConfig instead.
WARNING:tensorflow:Using temporary folder as model directory: C:\Users\potato\AppData\Local\Temp\tmp78uhupo9
WARNING:tensorflow:From E:/Workspace/pyWork/data-model/riskmanagement/optimize/DNN_scorecard/DNN.py:388: SKCompat.__init__ (from tensorflow.contrib.learn.python.learn.estimators.estimator) is deprecated and will be removed in a future version.
Instructions for updating:
Please switch to the Estimator interface.
WARNING:tensorflow:From D:\Application\Python\Anaconda3\lib\site-packages\tensorflow\contrib\learn\python\learn\estimators\estimator.py:143: setup_train_data_feeder (from tensorflow.contrib.learn.python.learn.learn_io.data_feeder) is deprecated and will be removed in a future version.
Instructions for updating:
Please use tensorflow/transform or tf.data.
WARNING:tensorflow:From D:\Application\Python\Anaconda3\lib\site-packages\tensorflow\contrib\learn\python\learn\learn_io\data_feeder.py:96: extract_dask_data (from tensorflow.contrib.learn.python.learn.learn_io.dask_io) is deprecated and will be removed in a future version.
Instructions for updating:
Please feed input to tf.data to support dask.
WARNING:tensorflow:From D:\Application\Python\Anaconda3\lib\site-packages\tensorflow\contrib\learn\python\learn\learn_io\data_feeder.py:98: extract_dask_labels (from tensorflow.contrib.learn.python.learn.learn_io.dask_io) is deprecated and will be removed in a future version.
Instructions for updating:
Please feed input to tf.data to support dask.
WARNING:tensorflow:From D:\Application\Python\Anaconda3\lib\site-packages\tensorflow\contrib\learn\python\learn\learn_io\data_feeder.py:100: extract_pandas_data (from tensorflow.contrib.learn.python.learn.learn_io.pandas_io) is deprecated and will be removed in a future version.
Instructions for updating:
Please access pandas data directly.
WARNING:tensorflow:From D:\Application\Python\Anaconda3\lib\site-packages\tensorflow\contrib\learn\python\learn\learn_io\data_feeder.py:102: extract_pandas_labels (from tensorflow.contrib.learn.python.learn.learn_io.pandas_io) is deprecated and will be removed in a future version.
Instructions for updating:
Please access pandas data directly.
WARNING:tensorflow:From D:\Application\Python\Anaconda3\lib\site-packages\tensorflow\contrib\learn\python\learn\learn_io\data_feeder.py:159: DataFeeder.__init__ (from tensorflow.contrib.learn.python.learn.learn_io.data_feeder) is deprecated and will be removed in a future version.
Instructions for updating:
Please use tensorflow/transform or tf.data.
WARNING:tensorflow:From D:\Application\Python\Anaconda3\lib\site-packages\tensorflow\contrib\learn\python\learn\learn_io\data_feeder.py:340: check_array (from tensorflow.contrib.learn.python.learn.learn_io.data_feeder) is deprecated and will be removed in a future version.
Instructions for updating:
Please convert numpy dtypes explicitly.
WARNING:tensorflow:From D:\Application\Python\Anaconda3\lib\site-packages\tensorflow\python\framework\op_def_library.py:263: colocate_with (from tensorflow.python.framework.ops) is deprecated and will be removed in a future version.
Instructions for updating:
Colocations handled automatically by placer.
WARNING:tensorflow:From D:\Application\Python\Anaconda3\lib\site-packages\tensorflow\contrib\layers\python\layers\feature_column.py:1874: to_float (from tensorflow.python.ops.math_ops) is deprecated and will be removed in a future version.
Instructions for updating:
Use tf.cast instead.
WARNING:tensorflow:From D:\Application\Python\Anaconda3\lib\site-packages\tensorflow\python\keras\layers\core.py:143: calling dropout (from tensorflow.python.ops.nn_ops) with keep_prob is deprecated and will be removed in a future version.
Instructions for updating:
Please use `rate` instead of `keep_prob`. Rate should be set to `rate = 1 - keep_prob`.
WARNING:tensorflow:Casting <dtype: 'int64'> labels to bool.
WARNING:tensorflow:From D:\Application\Python\Anaconda3\lib\site-packages\tensorflow\python\ops\metrics_impl.py:788: div (from tensorflow.python.ops.math_ops) is deprecated and will be removed in a future version.
Instructions for updating:
Deprecated in favor of operator or tf.math.divide.
WARNING:tensorflow:Casting <dtype: 'int64'> labels to bool.
WARNING:tensorflow:Trapezoidal rule is known to produce incorrect PR-AUCs; please switch to "careful_interpolation" instead.
WARNING:tensorflow:Trapezoidal rule is known to produce incorrect PR-AUCs; please switch to "careful_interpolation" instead.
WARNING:tensorflow:From D:\Application\Python\Anaconda3\lib\site-packages\tensorflow\contrib\learn\python\learn\estimators\head.py:677: ModelFnOps.__new__ (from tensorflow.contrib.learn.python.learn.estimators.model_fn) is deprecated and will be removed in a future version.
Instructions for updating:
When switching to tf.estimator.Estimator, use tf.estimator.EstimatorSpec. You can use the `estimator_spec` method to create an equivalent one.
2019-08-07 16:09:38.154265: I tensorflow/core/platform/cpu_feature_guard.cc:141] Your CPU supports instructions that this TensorFlow binary was not compiled to use: AVX AVX2
2019-08-07 16:09:38.157425: I tensorflow/core/common_runtime/process_util.cc:71] Creating new thread pool with default inter op setting: 12. Tune using inter_op_parallelism_threads for best performance.

(说明:本人笔记本为“戴尔XPS15 八代i9处理器”具体CPU和GPU型号可查)

我确实是通过pip install tensorflow方式安装的,按照上文文中网友的说法,也就是使用的是CPU版tensorflow。另外,我在cmd上查看GPU,发现无运行中的进程,如下图。然而pycharm中程序打完上面的日志后没有任何信息了且程序一直保持运行中。

另有网友:https://blog.csdn.net/Fourierrr_/article/details/79749899,其给出了如何直接安装“支持cpu用AVX2编译的TensorFlow版本”,不过此博主所谓的“彻底解决,换成支持cpu用AVX2编译的TensorFlow版本”恐怕不妥,因为本文文首stackoverflow文中网友评论了很多,我很想知道到底如何安装支持GPU的TensorFlow,不过stackoverflow文中Wesam网友说应“编写代​​码以利用CPU和GPU协同工作”,经查原因如文中:https://blog.csdn.net/u014380165/article/details/77340765,其所讲“GPU和CPU的主要差异”。
网友:https://blog.csdn.net/Nicholas_Wong/article/details/70215127,其给出了自己编译以生成CPU版的TensorFlow,我将按照此文的方式试图编译以生成GPU版的TensorFlow。因此在此记录一下
综上所述,解决方案归结于如何选择安装适合“自己硬件”的TensorFlow!!!

下文:https://github.com/fo40225/tensorflow-windows-wheel,在README.md中列出了各种版本的对应关系表。

由于找不到对应github上与自己的CUDA相对应的版本,又考虑到自己笔记本上未找到VS(如上图所示)和python3.7.3版本问题,遂决定用下面这个版本:

1.13.1\py37\CPU\avx2VS2017 15.9NoAVX2Python 3.7

结果卸载TensorFlow又出现幺蛾子了:

如上图所示,使用pip uninstall tensorflow,然后输入y后提示有进程正在使用或按Ctr+C,最后关闭此Console,在上图的Interpreter上进行卸载(点击“-”号),结果报错,从图中Event Log上看到的日志如下:

以前在此处通过点击“+”进行安装时也报这种错误。经过反复尝试,最后通过命令为pip uninstall tensorflow -y可以进行卸载:

pip uninstall tensorflow -y
Uninstalling tensorflow-1.14.0:
  Successfully uninstalled tensorflow-1.14.0
Note: you may need to restart the kernel to use updated packages.
pip uninstall tensorflow-estimator -y
Uninstalling tensorflow-estimator-1.14.0:
  Successfully uninstalled tensorflow-estimator-1.14.0
Note: you may need to restart the kernel to use updated packages.
pip uninstall tensorflow -y
Uninstalling tensorflow-1.13.1:
  Successfully uninstalled tensorflow-1.13.1
Note: you may need to restart the kernel to use updated packages.
pip uninstall tensorflow-estimator -y
Uninstalling tensorflow-estimator-1.13.0:
  Successfully uninstalled tensorflow-estimator-1.13.0
Note: you may need to restart the kernel to use updated packages.
pip uninstall tensorflow -y
Skipping tensorflow as it is not installed.
Note: you may need to restart the kernel to use updated packages.
pip uninstall tensorboard -y
Uninstalling tensorboard-1.14.0:
  Successfully uninstalled tensorboard-1.14.0
Note: you may need to restart the kernel to use updated packages.
pip uninstall tensorboard -y
Uninstalling tensorboard-1.13.1:
  Successfully uninstalled tensorboard-1.13.1
Note: you may need to restart the kernel to use updated packages.
pip uninstall tensorflow -y
Skipping tensorflow as it is not installed.
Note: you may need to restart the kernel to use updated packages.

发现1.13.1始终无法卸载

于是只能安装

1.14.0\py37\CPU\avx2VS2019 16.1NoAVX2Python 3.7

好吧。。。。。。。。。。。。。。。。以上全是废话连篇。。。。。。。。。。

安装tensorflow-1.14.0(CPU版)命令:

pip install https://github.com/fo40225/tensorflow-windows-wheel/blob/master/1.14.0/py37/CPU/avx2/tensorflow-1.14.0-cp37-cp37m-win_amd64.whl

报错:zipfile.BadZipFile: File is not a zip file。按照网友的提示,但没有找到C:\Users\用户名\.keras\datasets这个路径,我的只有.keras目录下只有keras.json文件。

干脆手动下载后放在桌面上,使用命令:pip install C:\User\XXX(你的计算机名字)\Desktop\tensorflow-1.14.0-cp37-cp37m-win_amd64.whl

安装tensorflow-1.14.0(GPU版):

经查此文:https://blog.csdn.net/marvel1014/article/details/84452560,其描述的

可从上面我的“NV控制面板”图中得知,我的GTX1050Ti对应NVIDIA CUDA 9.2.127 driver。为避免再次踩坑,可以选择此文:https://blog.csdn.net/xinxuyang123/article/details/83743229,进行安装CUDA和CUDNN。

但我决定最终尝试:https://www.jianshu.com/p/fff0b90fff77,按其教程安装VS2017、CUDA9.2、cuDNN v7.1.4(May 16, 2018),for CUDA 9.2三个软件

额,小版本号不一样,我的127而要求148。纳闷,使用下图方式经过折腾,最终也没有成功升级cuda。

相同型号和配置相同的笔记本别人却可以“意外”升级到cuda10.1.135版本,如下图所示:

接下来正式开始安装

小记:cuda9.2白天从官网下载:https://developer.nvidia.com/cuda-toolkit-archive,老是失败,于是使用的是上文博主百度网盘中的,安装失败;cuda9.1和cuda9.0全是从官网下载的,安装报错如上。晚上趁公司网速快,再次从官网下载cuda9.2(注意和博主网盘上的是同一个版本号),却发现可以安装,下图开始各项操作:

上图可发现,我笔记本上确实没有安装过VS,在安装上文博主所提供的VS时,注意:VS2017-Community安装时在“组件”中选C++的桌面开发组件就行,安装过程一直点默认就ok。

选择“自定义安装”,默认这些都勾上的,别动

下图此两项是默认勾选的,只需点击“关闭”即可

上图的下一个页面就是下图,可以发现GE3.14.1为打游戏设计的相应功能。(珍惜生命时间,远离游戏)~这话是我欠揍所说。

预准备配置“环境变量”,下图是上面安装后自动添加的环境变量。

按照上文博主的教程(注意上文博主有小错误),正确的全部配置如下:

在用户变量Path下添加:C:\ProgramData\NVIDIA GPU Computing Toolkit\v9.2

在系统变量中添加如下几个变量:

 CUDA_SDK_PATH = C:\ProgramData\NVIDIA Corporation\CUDA Samples\v9.2(注意:他的错误在此)

 CUDA_LIB_PATH = %CUDA_PATH%\lib\x64 

CUDA_BIN_PATH = %CUDA_PATH%\bin 

CUDA_SDK_BIN_PATH = %CUDA_SDK_PATH%\bin\win64 

CUDA_SDK_LIB_PATH = %CUDA_SDK_PATH%\common\lib\x64

安装cudnn,即把右图全选复制后粘贴到左图位置。亲测

安装tensorflow-gpu-1.14.0

运行程序报错:ImportError: Could not find 'cudart64_100.dll',如下图。按照此文:https://yq.aliyun.com/articles/706919?type=2

通过pip list发现我并未安装tensorflow-1.14.0,在pycharm中查看解释器确实看到的还是tensorflow-1.13.1,于是安装tensorflow-1.14.0:

再次运行程序,可以运行,但tensorflow.contrib.learn.python.learn.estimators.*有警告:

(from tensorflow.contrib.learn.python.learn.estimators.*) is deprecated and will be removed in a future version.
Instructions for updating:
xxx

按照警告项进行相应的处理,就没问题了。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值