pytorch 安装
Anaconda 下载
官网:https://www.anaconda.com/
1 2 3 4 5
| conda info --envs
conda activate 环境名
|
anaconda换源
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
| conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/msys2/ 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/free/ conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/pytorch/ conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main/ conda config --set show_channel_urls yes
conda config --add channels https://mirrors.ustc.edu.cn/anaconda/pkgs/main/ conda config --add channels https://mirrors.ustc.edu.cn/anaconda/pkgs/free/ conda config --add channels https://mirrors.ustc.edu.cn/anaconda/cloud/conda-forge/ conda config --add channels https://mirrors.ustc.edu.cn/anaconda/cloud/msys2/ conda config --add channels https://mirrors.ustc.edu.cn/anaconda/cloud/bioconda/ conda config --add channels https://mirrors.ustc.edu.cn/anaconda/cloud/menpo/ conda config --set show_channel_urls yes
conda config --show
conda config --remove-key channels
|
pytorch下载
官网:https://pytorch.org/
previous-versions:https://pytorch.org/get-started/previous-versions/
如果要下载torch-GPU版本,必须要找到对应的cu、cp版本,cu为CUDA版本,cp为python版本
GPU版本下载地址:https://download.pytorch.org/whl/torch/
1 2 3 4 5
| pip install https://download.pytorch.org/whl/cu117/torch-2.0.0%2Bcu117-cp38-cp38-win_amd64.whl#sha256=64c176ebff6904155aa6f72b0f996c9ea17f29b8af7aa9afeee8bff726f91ef3
pip install https://download.pytorch.org/whl/cu102/torch-1.8.1%2Bcu102-cp38-cp38-win_amd64.whl#sha256=b320a39980c5871801ab1c33749f744a1efbf187fbef12f251cb4577ec66fd24
|
CUDA与CUDNN安装
win+R
,输入 cmd
打开命令行
- 输入
nvidia-smi
查询可以安装的驱动版本,查找下载对应版本CUDA
CUDA下载地址:https://developer.nvidia.com/cuda-toolkit-archive
CUDNN下载地址:https://developer.nvidia.com/rdp/cudnn-archive
- 将下载的cudnn文件解压,复制到CUDA安装目录中。
- 手动添加CUDA安装目录下
\lib\x64
、\include
、\extras\CUPTI\lib64
到环境变量。
使用nvcc --version
查看CUDA版本。
验证torch是否能使用GPU
1 2 3 4 5 6 7 8 9 10 11 12 13
|
import torch
print(torch.__version__) print(torch.cuda.is_available()) print(torch.cuda.device(0)) print(torch.cuda.device_count()) print(torch.cuda.get_device_name(0))
|
YOLOv5
创建环境
1 2 3 4 5 6 7 8 9 10
| conda create -n yolov5 python=3.8
conda activate yolov5
python -m pip install --upgrade pip pip config set global.index-url https://pypi.tuna.tsinghua.edu.cn/simple
pip3 install torch==1.8.2 torchvision==0.9.2 torchaudio==0.8.2 --extra-index-url https://download.pytorch.org/whl/lts/1.8/cu111
|
YOLOv5
github:https://github.com/ultralytics/yolov5
v7.0:https://github.com/ultralytics/yolov5/releases/tag/v7.0
设置 Pillow == 8.3.0
、numpy == 1.20.3
1
| pip install -r requirements.txt
|
测试
jupyter Notebook
Pycharm配置 jupyter Notebook
1 2 3 4 5 6 7 8
| pip install jupyter notebook
jupyter notebook password
jupyter notebook
|
复制 URL 地址
填入 设置 - 语言与框架 - Jupyter - Jupyter服务器 - 配置的服务器。
运行代码,输入密码登录即可。
在jupyter notebook中添加conda创建的环境
1 2 3 4 5 6 7 8 9 10
| conda activate transformers
pip install ipykernel
python -m ipykernel install --name transformers --display-name "transformers"
|