解決報錯: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\avx2 VS2017 15.9 No AVX2 Python 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\avx2 VS2019 16.1 No AVX2 Python 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

按照警告項進行相應的處理,就沒問題了。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章