確認顯卡支持 cuda
首先確認顯卡是否是 英偉達 NVIDIA 的,當然 AMD 也支持,但是不常用;
NVIDIA 顯卡有 GTX Geforce、Quadra 和 Tesla 三大系列,然后到如下網站查看是否支持 Cuda
https://developer.nvidia.com/cuda-gpus
點擊如下鏈接即可查看每個系列支持 cuda 的顯卡版本
安裝顯卡驅動
在安裝CUDA過程中,你可能各種嘗試,把顯卡驅動整壞了,可以重新安裝; 【我就是這樣,然后死活裝不上 cuda,后來重裝驅動,搞定】
在 https://www.nvidia.cn/Download/index.aspx?lang=cn 獲取自己顯卡的最新驅動版本;
下載,雙擊安裝;
安裝 cuda 驅動
訪問CUDA的下載網站:https://developer.nvidia.com/cuda-toolkit,可以看到CUDA目前的最新版本,可以通過選擇下面的“Legacy Releases”鏈接來下載舊版本的驅動;
建議選擇自定義安裝,然后只勾選cuda,建議安裝在默認文件路徑;
把 安裝路徑下的 bin 目錄設為環境變量:C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v9.0\bin
安裝 cudnn 庫
CuDNN庫(The NVIDIA CUDA® Deep Neural Network library)是CUDA針對深度神經網絡的更新包,TensorFlow會使用它用於加速NVidia GPU上的深度學習。可以從這里下載,見:https://developer.nvidia.com/cudnn。
首先要注冊一個NVidia開發者帳號,它是免費的。登錄后,您會看到各種CuDNN下載;
cuda 與 cudnn 版本要嚴格對應,對應關系見 https://developer.nvidia.com/rdp/cudnn-archive
下載下來的是一個包含了幾個文件夾的ZIP文件,每個文件夾包含CuDNN文件(一個DLL,一個頭文件和一個庫文件)。找到你的CUDA安裝目錄,這里應該是這樣的:
C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v9.0
可以看到從ZIP文件的目錄也在這個目錄,即有一個bin、一個include,一個lib等。將文件從ZIP復制到相關的目錄。
比如把cudnn64_7.dll文件拖拽到C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v9.0\bin目錄,其它相似。
安裝 tensorflow-gpu
首先安裝 python3.6
具體過程參考我的其他博客,這里只記錄重點
之前我講過 python 安裝不推薦 64 位的,所以我安裝的是 32 位的,但是死活裝不上 tf,報錯如下
Could not find a version that satisfies the requirement tensorflow-gpu(from versions: ) No matching distribution found for tensorflow-gpu
后來換成了 64 位,可以了,我也是醉了
然后使用 pip 安裝 tensorflow
python3 -m pip install tensorflow-gpu
如果安裝很慢,可以使用國內鏡像源
python3 -m pip install tensorflow-gpu -i http://pypi.douban.com/simple/ --trusted-host pypi.douban.com
其中 --trusted-host pypi.douban.com 的作用是獲得ssl證書的認證
驗證是否安裝成功
import tensorflow as tf print('GPU', tf.test.is_gpu_available()) # GPU True
顯示 GPU 可用,成功;
如果CUDA驅動程序有錯誤,就可能會顯示 cudart64_XX.dll 失敗,其中XX是版本號。
ImportError: Could not find 'cudart64_100.dll'. TensorFlow requires that this DLL be installed in a directory that is named in your %PATH% environment variable.
Download and install CUDA 10.0 from this URL: https://developer.nvidia.com/cuda-90-download-archive
按照提示,要下載 cuda 10.0,tf1.13 以上的版本需要 cuda 10.0 版本;
如果CUDA驅動程序正確,但CuDNN驅動程序有錯誤,就可能會顯示說 cudnn64_X.dll 缺少什么東西,其中X是一個版本號。
參考資料:
https://blog.csdn.net/hzk594512323/article/details/86082852 Python之pip安裝失敗----Could not find a version that satisfies the requirement xxxx(from versions: )
### 下面是 cuda 安裝教程
https://www.cnblogs.com/touch-skyer/p/8367706.html window10上安裝python+CUDA+CuDNN+TensorFlow 【主要參考】
https://www.cnblogs.com/fanfzj/p/8521728.html tensoflow-gpu安裝
https://blog.csdn.net/u014695788/article/details/93246548 python CUDA配置
https://zhuanlan.zhihu.com/p/29841665 用GPU加速深度學習: Windows安裝CUDA+TensorFlow教程
https://www.360kuai.com/pc/9290487ad261e50da?cota=4&tj_url=so_rec&sign=360_57c3bbd1&refer_scene=so_1 tensorflow版本與cuda cuDNN版本對應關系