深度学习环境配置

当我们在训练模型的时候,发现模型训练十分缓慢,使用下面代码测试我们是否利用上gpu

import torch

# 检查 CUDA 是否可用
if torch.cuda.is_available():
    print("CUDA is available! Training on GPU ...")


    # ... 其余的代码 ...
else:
    print("CUDA is not available. Training on CPU ...")

经过检查,发现cuda不可用。

所以我们重装环境

# 创建虚拟环境rtDetr
conda create -n rtDetr python==3.8
#激活环境
conda activate rtDetr
#安装cuda版本的torch以及torchvision
pip install torch==2.0.1 torchvision==0.15.2 --index-url https://download.pytorch.org/whl/cu118
#安装好cuda版本的torch再装其他环境
pip install -r requirements.txt	//requirement.txt
# 运行训练脚本
python tools/train.py

其中要重视的主要是我们需要的torch版本以及其配套的torchvision版本。不能分开装,否则会报错。还有就是不能直接pip install torch,否则装上的是cpu版本。

具体代码寻找:

在网址:https://pytorch.org/get-started/previous-versions/
在previous pytorch version里面:
pip install torch==2.1.2 torchvision==0.16.2 torchaudio==2.1.2 --index-url https://download.pytorch.org/whl/cu118

至此成功安装

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值