环境配置指南
软件要求:
- Python 3.9: 推荐使用Python 3.9版本,确保与各类深度学习库的兼容性。
- Anaconda 2023: Anaconda是一个集成的Python发行版本,包含了众多科学计算和数据分析的工具。推荐使用Anaconda 2023版本。
添加镜像源
为了加速软件包的下载和安装,可以添加清华大学开源软件镜像站作为Conda的镜像源。以下是添加镜像源的命令:
# 添加清华大学镜像源
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/r
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/pro
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/msys2
# 显示检索路径
conda config --set show_channel_urls yes
# 显示当前配置的镜像通道
conda config --show channels
安装依赖库
1. 创建Python环境
首先,创建一个新的Conda环境,其中包含Python 3.9和相关的CUDA工具包,以确保深度学习库的兼容性。
conda create -n py39 python=3.9.16 cudnn=8.4.1.50 cudatoolkit=11.3.1 -c conda-forge
2. 激活环境
激活刚刚创建的环境,以便在该环境中安装和使用库。
conda activate py39
3. 安装PyTorch及相关库
使用以下命令安装指定版本的PyTorch、Torchvision和Torchaudio,这些库是深度学习和计算机视觉项目中的核心库。
pip install torch==1.12.1+cu113 torchvision==0.13.1+cu113 torchaudio==0.12.1 --extra-index-url https://download.pytorch.org/whl/cu113
如果遇到在线安装问题,您可以选择下载离线安装包并进行安装。
4. 离线安装库
如果在线安装库遇到问题,可以从以下网址下载PyTorch的离线包:
下载后,可以使用pip
命令安装这些包。以下是示例命令:
pip install E:\Downloads\torch-1.12.1+cu113-cp39-cp39-win_amd64.whl
pip install E:\Downloads\torchvision-0.13.1+cu113-cp39-cp39-win_amd64.whl
pip install E:\Downloads\torchaudio-0.12.1+cu113-cp39-cp39-win_amd64.whl
5. 安装其他常用库
除了深度学习库,还需要安装一些常用的Python库,如matplotlib
、tqdm
、opencv-python
和scikit-image
,用于数据处理、可视化和图像处理。
pip install matplotlib tqdm opencv-python scikit-image
至此,开发环境已经配置完成,可以开始进行深度学习的开发和实验。