十分钟搞定win10 Conda装Detectron2(torch-gpu)

一、安装torch

way1 安装torch-cpu

conda create -n dectectron2py39_d  python=3.9
activate dectectron2py39_d
conda install -n dectectron2py39_d cudatoolkit=11.3
conda install -n dectectron2py39_d cudnn=8.2
conda install git
conda install pytorch==1.8.0 torchvision==0.9.0 torchaudio==0.8.0 cudatoolkit=11.2 -c pytorch -c conda-forge

way2 安装torch-gpu

conda create -n dectectron2py39 python=3.9.16 cudnn=8.4.1.50 cudatoolkit=11.3.1
conda activate dectectron2py39 

linux+win: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
way3 网速不行,可能需要离线
离线方法:https://blog.csdn.net/qq_18236971/article/details/131042637

#验证是否成功
import torch
torch.cuda.is_available()

在这里插入图片描述

conda install git

二、安装VS2022

安装VS2022社区版,勾选C++桌面开发
在这里插入图片描述

三、安装相关离线包

下载离线包
主要参考:https://blog.csdn.net/zzy153/article/details/120693321
在这里插入图片描述
(1) 安装cocoapi
点击https://github.com/philferriere/cocoapi下载,然后执行以下指令,另外还需要先安装Cython

pip install Cython -i https://pypi.tuna.tsinghua.edu.cn/simple
cd coco/PythonAPI
python setup.py build_ext --inplace
python setup.py build_ext install

(2) 安装fvcore
点击https://github.com/facebookresearch/fvcore下载,切换到setup.py所在目录,然后执行指令

python setup.py build --force develop

(3) 安装ninja

conda install ninja

四、安装detectron2

安装detectron2
下载https://github.com/facebookresearch/detectron2

python setup.py build develop

五 运行

安装成功
在这里插入图片描述
在这里插入图片描述

### 使用清华大学镜像源通过 Conda 安装 PyTorch-GPU 为了确保安装的是 GPU 版本的 PyTorch 而不是 CPU 版本,可以按照以下方式进行操作: #### 创建并激活新的虚拟环境 创建一个新的 Python 环境来隔离依赖项: ```bash conda create -n pytorch-gpu python=3.8 ``` 激活新创建的环境: ```bash conda activate pytorch-gpu ``` #### 设置清华源作为默认通道 为了避免从其他渠道获取软件包,设置清华源为默认通道。编辑 `.condarc` 文件或直接运行命令: ```bash conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/pytorch/ conda config --set show_channel_urls yes ``` #### 手动下载特定版本的 PyTorch 包 由于清华源可能无法自动匹配正确的 CUDA 和 cuDNN 版本组合,推荐手动指定要下载的具体文件名。对于 Linux 64-bit 用户来说,可以通过浏览器访问 [清华源](https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/pytorch/) 并查找适合系统的 tar.bz2 文件。 例如,如果目标是安装 PyTorch 1.13.1 对应于 Python 3.7, CUDA 11.7 及 cuDNN 8.5 的版本,则执行如下指令: ```bash wget https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/pytorch/linux-64/pytorch-1.13.1-py3.7_cuda11.7_cudnn8.5.0_0.tar.bz2 ``` 接着使用 `conda install` 命令安装已下载的本地文件: ```bash conda install ./pytorch-1.13.1-py3.7_cuda11.7_cudnn8.5.0_0.tar.bz2 ``` 注意:上述路径中的具体文件名称需根据实际需求调整[^1]。 #### 验证安装成功与否 完成以上步骤后,可通过导入 torch 库并在 Python 解释器内调用 `torch.cuda.is_available()` 函数验证是否正确配置了 GPU 支持。返回 True 表明已经成功启用了 GPU 加速功能。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值