系统要求 📦
- 操作系统:Ubuntu 18.04/20.04(推荐)或 Windows 10/11
- GPU:NVIDIA GPU(需支持CUDA)
- 驱动:NVIDIA驱动版本 ≥ 418.34
- CUDA:版本 ≥ 11.2(建议与TensorFlow版本匹配)
- cuDNN:版本 ≥ 8.1(需与CUDA版本对应)
安装步骤 🔧
- 安装NVIDIA驱动
- 使用命令:
sudo apt update && sudo apt install nvidia-driver-<版本>
- 验证驱动:
nvidia-smi
(显示GPU信息 ✅)
- 使用命令:
- 安装CUDA Toolkit
- 访问 CUDA_Version 下载对应版本
- 添加环境变量:
export PATH=/usr/local/cuda-<版本>/bin:$PATH
- 安装cuDNN
- 从 cuDNN_Version 获取库文件
- 解压并复制到CUDA目录:
cp -r cuda/include/* /usr/local/cuda-<版本>/include/
- 安装TensorFlow GPU版本
- 使用pip:
pip install tensorflow-gpu
- 或Conda:
conda install -c conda-forge tensorflow-gpu
- 使用pip:
验证安装 🧪
- 运行测试代码:
import tensorflow as tf print("GPU可用:", tf.test.is_built_with_cuda())
- 查看设备信息:
print("GPU设备:", tf.config.list_physical_devices('GPU'))
常见问题 ❓
- 驱动不匹配:检查 NVIDIA驱动兼容性
- CUDA安装失败:参考 CUDA安装教程
- 版本冲突:请确保CUDA/cuDNN与TensorFlow版本一致 🔄
如需进一步了解TensorFlow安装选项,可访问 安装概述。