#49 Add DBNet model for PyNative mode on GPU and Ascend

Merged
Erpim merged 5 commits from ziqi/MSAdapterModelZoo:master into master 6 months ago
ziqi commented 8 months ago
- Add DBNet model for PyNative mode on GPU and Ascend
Erpim reviewed 8 months ago
@@ -0,0 +153,4 @@
n = m.kernel_size[0] * m.kernel_size[1] * m.out_channels
m.weight.data.normal_adapter(0, math.sqrt(2. / n))
elif isinstance(m, BatchNorm2d):
m.weight.data.fill_(1)
Erpim commented 8 months ago
m.weight.data.fill_adapter(1) # for graph mode accelerating m.bias.data.zero_adapter() # for graph mode accelerating
ziqi marked this conversation as resolved
Erpim reviewed 8 months ago
@@ -0,0 +96,4 @@
self.conv3 = nn.Conv2d(planes, planes * 4, kernel_size=1, bias=False)
self.bn3 = BatchNorm2d(planes * 4)
self.relu = nn.ReLU(inplace=False) # for graph mode accelerating
# self.relu = nn.ReLU(inplace=True)
Erpim commented 8 months ago
默认用pynative的写法
ziqi marked this conversation as resolved
Erpim reviewed 8 months ago
@@ -0,0 +51,4 @@
return loss_dict['loss'], loss_dict['loss_shrink_maps'], loss_dict['loss_threshold_maps'], loss_dict['loss_binary_maps'], preds
# for graph mode accelerating
# def forward_fn(bimg, bsma, bsmas, btma, btms):
Erpim commented 8 months ago
model = self.model model.train()
Erpim commented 7 months ago
不需要修改
ziqi marked this conversation as resolved
Erpim reviewed 8 months ago
@@ -0,0 +54,4 @@
# def forward_fn(bimg, bsma, bsmas, btma, btms):
# preds = model(bimg)
# m_l, m_lsm, m_ltm, m_lbm = self.criterion(preds, bsma, bsmas, btma, btms)
# return m_l, m_lsm, m_ltm, m_lbm
Erpim commented 8 months ago
return m_l, preds, m_lsm, m_ltm, m_lbm
Erpim commented 7 months ago
不需要修改
ziqi marked this conversation as resolved
Erpim reviewed 7 months ago
@@ -0,0 +32,4 @@

loss_shrink_maps = self.bce_loss(shrink_maps, batch['shrink_map'], batch['shrink_mask'])
loss_threshold_maps = self.l1_loss(threshold_maps, batch['threshold_map'], batch['threshold_mask'])
metrics = dict(loss_shrink_maps=loss_shrink_maps, loss_threshold_maps=loss_threshold_maps)
Erpim commented 7 months ago
metrics = {'loss_shrink_maps':loss_shrink_maps, 'loss_threshold_maps':loss_threshold_maps} 图模式执行这个
ziqi marked this conversation as resolved
Erpim reviewed 7 months ago
@@ -0,0 +48,4 @@
self.with_cuda = True
# torch.backends.cudnn.benchmark = True
self.device = torch.device("cuda")
# torch.cuda.manual_seed(self.config['trainer']['seed']) # 为当前GPU设置随机种子
Erpim commented 7 months ago
所有注释改为英文
ziqi commented 7 months ago
这个DBNet的原始代码就是这么写的,需要改吗
Erpim reviewed 7 months ago
@@ -0,0 +63,4 @@
self.optimizer(grads)
return loss, loss_shrink_maps, loss_threshold_maps, loss_binary_maps, preds
# for graph mode accelerating
Erpim commented 7 months ago
删除这些适配代码
ziqi marked this conversation as resolved
Erpim commented 7 months ago
Collaborator
loss, loss_shrink_maps, loss_threshold_maps, loss_binary_maps, preds = train_step(batch=mindspore.mutable(batch)) 图模式执行这个
Erpim merged commit f48a059606 into master 6 months ago
The pull request has been merged as f48a059606.
Sign in to join this conversation.
No reviewers
No Label
No Milestone
No Assignees
2 Participants
Notifications
Due Date

No due date set.

Dependencies

This pull request currently doesn't have any dependencies.

Loading…
There is no content yet.