在Win10/11 建立Tensorflow GPU訓練環境20230605
Windows GPU設定 2023.06最新
安裝tensorflow很簡單
但要讓tensorflow吃到windows中的GPU很困難
尤其在windows很久才裝一次…然後每次裝都會卡很久(因為版本更新)
這篇記錄2023年安裝筆記
供需要的人參考
總共花了4天try…
網路上一堆教學都已經過時
感謝最後參考[1]的神救援
參考
[1] https://magicjackting.pixnet.net/blog/post/225214893
[2] https://www.youtube.com/watch?v=0S81koZpwPA
Tensorflow 2.11(含)以後Windows版本不支援GPU (未來要透過WSL2了 可以參考[2])
所以最多裝到2.10
需要
Image Not Showing
Possible Reasons
- The image was uploaded to a note which you don't have access to
- The note which the image was originally uploaded to has been deleted
Learn More →
Image Not Showing
Possible Reasons
- The image was uploaded to a note which you don't have access to
- The note which the image was originally uploaded to has been deleted
Learn More →
先安裝Cuda, 安裝的時候Cuda會跟著安裝顯卡driver…
但如果懶得移除顯卡driver的
先試著安裝Cuda 11.8試試
https://developer.nvidia.com/cuda-toolkit-archive
Image Not Showing
Possible Reasons
- The image was uploaded to a note which you don't have access to
- The note which the image was originally uploaded to has been deleted
Learn More →
若沒有移除顯卡driver
先從下面這張表查詢Cuda對應Driver表
Image Not Showing
Possible Reasons
- The image was uploaded to a note which you don't have access to
- The note which the image was originally uploaded to has been deleted
Learn More →
可以從cmd測試 nvidia-smi看自己的dirver version是否符合
Image Not Showing
Possible Reasons
- The image was uploaded to a note which you don't have access to
- The note which the image was originally uploaded to has been deleted
Learn More →
接著安裝Cudnn
https://developer.nvidia.com/rdp/cudnn-archive
選擇支援11.x的
Image Not Showing
Possible Reasons
- The image was uploaded to a note which you don't have access to
- The note which the image was originally uploaded to has been deleted
Learn More →
Cudnn裝法
解壓縮後直接覆蓋到Cuda資料夾中(預設目錄C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v11.8)
cudnn-windows-x86_64-8.9.1.23_cuda11-archive.zip的內容:
Image Not Showing
Possible Reasons
- The image was uploaded to a note which you don't have access to
- The note which the image was originally uploaded to has been deleted
Learn More →
直接覆蓋進來
Image Not Showing
Possible Reasons
- The image was uploaded to a note which you don't have access to
- The note which the image was originally uploaded to has been deleted
Learn More →
Why安裝11.x
因為從tensorflow官方網站
https://www.tensorflow.org/install/source?hl=zh-tw#gpu
目前看起來只支援到11.x
PS這張表有點久沒更新了 今日(2023/06)TF最新版的是2.12 但他居然只列到2.6
Image Not Showing
Possible Reasons
- The image was uploaded to a note which you don't have access to
- The note which the image was originally uploaded to has been deleted
Learn More →
完成硬體driver安裝後就可以安裝軟體了
先安裝Miniconda 或 anaconda
https://docs.conda.io/en/latest/miniconda.html
https://www.anaconda.com/download
已經有的可以建立新環境
conda新增環境指定Python版本
conda create -n DL python=3.9
啟用環境
conda activate DL
安裝Tensorflow最後一版支援windows版本(2.10)
pip install tensorflow==2.10.1
測試安裝是否成功
一樣在命令提示字元下
輸入python
輸入from tensorflow.python.client import device_lib
輸入print(device_lib.list_local_devices())
此時會看到是否有列出GPU的資訊,若有表示安裝成功
Image Not Showing
Possible Reasons
- The image was uploaded to a note which you don't have access to
- The note which the image was originally uploaded to has been deleted
Learn More →
移除環境指令
conda移除環境
conda deactivate
conda remove --name ENV_NAME --all
常用套件安裝
pip install pandas
pip install scikit-learn
查看安裝套件
conda list
GPU Cuda Python版本對應表
https://www.tensorflow.org/install/source?hl=zh-tw#gpu