mmSegmentation的单GPU训练和测试

mmSegmentation的使用

参考:
  1. github
mmseg安装:
1. 安装依赖包:
python==3.6, 3.7
1.1.2<=mmcv<=1.2.0
torch==1.5.0 
torchvision==0.6.0
2. mmcv 安装
CUDAtorch 1.6torch 1.5torch 1.4torch 1.3
10.2OOXX
10.1OOOO
9.2OOOO
cpuOOOO
pip install mmcv-full==latest+torch1.6.0+cu102 -f https://openmmlab.oss-accelerate.aliyuncs.com/mmcv/dist/index.html
pip install mmcv-full==latest+torch1.5.0+cu102 -f https://openmmlab.oss-accelerate.aliyuncs.com/mmcv/dist/index.html
pip install mmcv-full==latest+torch1.6.0+cu101 -f https://openmmlab.oss-accelerate.aliyuncs.com/mmcv/dist/index.html
pip install mmcv-full==latest+torch1.5.0+cu101 -f https://openmmlab.oss-accelerate.aliyuncs.com/mmcv/dist/index.html
pip install mmcv-full==latest+torch1.4.0+cu101 -f https://openmmlab.oss-accelerate.aliyuncs.com/mmcv/dist/index.html
pip install mmcv-full==latest+torch1.3.0+cu101 -f https://openmmlab.oss-accelerate.aliyuncs.com/mmcv/dist/index.html
pip install mmcv-full==latest+torch1.6.0+cu92 -f https://openmmlab.oss-accelerate.aliyuncs.com/mmcv/dist/index.html
pip install mmcv-full==latest+torch1.6.0+cpu -f https://openmmlab.oss-accelerate.aliyuncs.com/mmcv/dist/index.html
# 安装mmcv-full build时间较长
pip isntall -r requirements.txt
MMCV_WITH_OPS=1 pip install -e .
3.mmseg安装
pip install -r requirements/build.txt
pip install -e .
mmseg 训练
1. 单GPU

需要注意问题:

https://github.com/open-mmlab/mmdetection/issues/847.  SyncBN only works with distributed environment, you may either use tools/dist_test.sh or modify SyncBN to BN manually during testing.

修改方法:
将configs/_base_中的参数设置 SyncBN修改为BN

2. 多GPU

参考:github

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
PyTorch是一个流行的深度学习框架,支持使用GPU或多个GPUs进行训练测试。在使用GPU时,需要将模型和数据加载到GPU上。使用GPU进行训练测试的示例代码如下: 示例代码如下: ```python #将模型加载到GPU device = torch.device('cuda:0') #选择第一个GPU model.to(device) #将数据加载到GPU x = x.to(device) y = y.to(device) #在GPU上进行前向传播 y_pred = model(x) #计算损失 loss = criterion(y_pred, y) #在GPU上进行反向传播 loss.backward() #更新权重 optimizer.step() ``` 使用多个GPU可以加快训练测试的速度。PyTorch提供了两种多GPU的方法:DataParallel和DistributedDataParallel(DDP)。其中,DataParallel是在台机器上使用多个GPU的方法,而DDP是在多台机器上使用多个GPU的方法。 使用DataParallel时,可以将模型和数据加载到GPU上,然后使用torch.nn.DataParallel将模型复制到其他GPU上。使用DataParallel进行训练测试的示例代码如下: 示例代码如下: ```python #将模型加载到GPU device = torch.device('cuda:0') #选择第一个GPU model.to(device) #使用DataParallel将模型复制到其他GPU上 if torch.cuda.device_count() > 1: model = nn.DataParallel(model) #将数据加载到GPU x = x.to(device) y = y.to(device) #在GPU上进行前向传播 y_pred = model(x) #计算损失 loss = criterion(y_pred, y) #在GPU上进行反向传播 loss.backward() #更新权重 optimizer.step() ``` 使用DDP时,需要在多台机器上安装PyTorch和NCCL库,并按照官方文档中的说明进行配置。使用DDP进行训练测试的示例代码如下: ```python #在每个进程中选择一个GPU device = torch.device('cuda', rank % torch.cuda.device_count()) #使用DistributedDataParallel初始化模型 model = nn.parallel.DistributedDataParallel(model, device_ids=[device]) #在GPU上进行前向传播 y_pred = model(x) #计算损失 loss = criterion(y_pred, y) #在GPU上进行反向传播 loss.backward() #更新权重 optimizer.step() ``` 以上就是PyTorch使用GPU和多个GPU进行训练测试的方法。具体使用哪种方法,需要根据硬件和应用场景的要求进行选择。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值