--- date: Dec 11, 2021 id: 21-12-002 tags: AI, tensorflow --- # 安裝tensorflow-gpu ## 前置說明 安裝tensordlow(tf)套件前, 需要先搞清楚硬體裝置, 從而決定所有軟體版本配置 (特別麻煩 ...) 幸好網路上有很多先進分享了心得, 推薦可以參考[K_程式人 的分享](https://jennaweng0621.pixnet.net/blog/post/403507751-windows10%E5%AE%89%E8%A3%9DTensorflow-GPU%E7%89%88%E6%9C%AC%E8%A8%AD%E7%BD%AE) ## 安裝調適 筆者以自己的筆電(GTX1650)舉例(建議讀者可以依著順序去調整)採用了**第六組配置**, 即 1. CUDA toolkit v10.1 update 2 註: 網路上有說需要先安裝v10.0版本不然會出錯, 但筆者親測直接安裝v10.1 update 2是沒問題的, 安裝流程較繁瑣另外摘要於[CUDA安裝與版本設定](https://hackmd.io/@ken52/21-12-001) ![nvcc -V查詢畫面](https://drive.google.com/uc?export=view&id=1-XzbvCO4uc-AvG2-W_THvb_-UiQBGHj-) 2. cuDNN v7.6.4 安裝指令`conda install -c anaconda cudnn=7.6.4` ![cudnn安裝畫面](https://drive.google.com/uc?export=view&id=1-W54VeilzO2RmvkkAb6Zl3_exT9Fnudj) 3. python v3.8.12 ![python --version](https://drive.google.com/uc?export=view&id=1-X6xlX3wnLQxLZeZQCfWlngV4C8vP4KT) 4. tensorflow-gpu v2.3.0 [可以參考這個網誌](https://blog.csdn.net/K1052176873/article/details/114526086) 安裝指令`pip install tensorflow-gpu==2.3.0` |Version|Python version|Compiler|Build tools|cuDNN|CUDA| |---|---|---|---|---|---| |tensorflow_gpu-2.3.0|3.5-3.8|MSVC 2019|Bazel 3.1.0|7.6|10.1| ## Tensorflow測試 採用下方指令碼可用於測試tf是否正常運行, 以及是否有GPU支援 ``` python import tensorflow as tf print(tf.__version__) print(tf.test.is_gpu_available()) gpus = tf.config.experimental.list_physical_devices(device_type='GPU') cpus = tf.config.experimental.list_physical_devices(device_type='CPU') print(gpus, '\n', cpus) ``` 結果顯示如果沒有報錯, 且看到相關GPU資訊, 基本就沒問題了 ![tensorflow gpu測試畫面](https://drive.google.com/uc?export=view&id=1-WwhTSRi5XFASjPJ78jsllPHCs4t7uoj) ... the end 祝君 **武運昌隆**