pip install virtualenv
virtualenv -p python ./tf2
cd tf2\Scripts
activate
pip install --upgrade pip
TensorFlow CPU版本:
pip install tensorflow==2.6.0
TensorFlow GPU版本:
-
安裝顯示卡驅動器(450.x 以上版本)。驅動程式
-
安裝 TensorFlow 支援 CUDA® 11.2 (TensorFlow 2.5.0 以上版本)。CUDA
-
下載cuDNN SDK 8.1.0並將其解壓縮至
C:\tools\cuda
。cuDNN -
設定環境變數
C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v11.2\bin C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v11.2\extras\CUPTI\lib64 C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v11.2\include C:\tools\cuda\bin
安裝TensorFlow-GPU
pip install tensorflow-gpu==2.6.0
測試:
python -c "import tensorflow as tf;print(tf.reduce_sum(tf.random.normal([1000, 1000])))"
輸出:
2021-10-07 23:14:08.671984: I tensorflow/core/platform/cpu_feature_guard.cc:142] This TensorFlow binary is optimized with oneAPI Deep Neural Network Library (oneDNN) to use the following CPU instructions in performance-critical operations: AVX AVX2
To enable them in other operations, rebuild TensorFlow with the appropriate compiler flags.
2021-10-07 23:14:09.502332: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1510] Created device /job:localhost/replica:0/task:0/device:GPU:0 with 8963 MB memory: -> device: 0, name: GeForce RTX 2080 Ti, pci bus id: 0000:26:00.0, compute capability: 7.5
tf.Tensor(1267.9038, shape=(), dtype=float32)
如果出現以下錯誤訊息:
2021-07-07 00:07:20.567760: W tensorflow/stream_executor/platform/default/dso_loader.cc:64] Could not load dynamic library 'cusolver64_11.dll'; dlerror: cusolver64_11.dll not found
將C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v11.0\bin\cusolver64_10.dll
改成C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v11.0\bin\cusolver64_11.dll
sudo apt install virtualenv
virtualenv -p python3 ./tf2
source tf2/bin/activate
pip install --upgrade pip
TensorFlow CPU版本:
pip install tensorflow==2.6.0
TensorFlow GPU版本:
安裝CUDA
# Add NVIDIA package repositories
wget https://developer.download.nvidia.com/compute/cuda/repos/ubuntu1804/x86_64/cuda-ubuntu1804.pin
sudo mv cuda-ubuntu1804.pin /etc/apt/preferences.d/cuda-repository-pin-600
sudo apt-key adv --fetch-keys https://developer.download.nvidia.com/compute/cuda/repos/ubuntu1804/x86_64/7fa2af80.pub
sudo add-apt-repository "deb https://developer.download.nvidia.com/compute/cuda/repos/ubuntu1804/x86_64/ /"
sudo apt-get update
wget http://developer.download.nvidia.com/compute/machine-learning/repos/ubuntu1804/x86_64/nvidia-machine-learning-repo-ubuntu1804_1.0.0-1_amd64.deb
sudo apt install ./nvidia-machine-learning-repo-ubuntu1804_1.0.0-1_amd64.deb
sudo apt-get update
wget https://developer.download.nvidia.com/compute/machine-learning/repos/ubuntu1804/x86_64/libnvinfer7_7.1.3-1+cuda11.0_amd64.deb
sudo apt install ./libnvinfer7_7.1.3-1+cuda11.0_amd64.deb
sudo apt-get update
# Install development and runtime libraries (~4GB)
sudo apt-get install --no-install-recommends \
cuda-11-0 \
libcudnn8=8.0.4.30-1+cuda11.0 \
libcudnn8-dev=8.0.4.30-1+cuda11.0
# Reboot. Check that GPUs are visible using the command: nvidia-smi
# Install TensorRT. Requires that libcudnn8 is installed above.
sudo apt-get install -y --no-install-recommends libnvinfer7=7.1.3-1+cuda11.0 \
libnvinfer-dev=7.1.3-1+cuda11.0 \
libnvinfer-plugin7=7.1.3-1+cuda11.0
安裝TensorFlow-GPU
pip install tensorflow-gpu==2.6.0