Debug RefineDet pytorch

https://github.com/lzx1413/PytorchSSD#pytorch-41-is-suppoted-on-branch-04-now

环境配置问题:

libstdc++.so.6: version `GLIBCXX_3.4.22' not found
解决:
https://blog.csdn.net/pursuit_zhangyu/article/details/79450027
https://blog.csdn.net/u011961856/article/details/79644342


from torch._C import * 
ImportError: numpy.core.multiarray failed to import 
解决:
https://github.com/pytorch/pytorch/issues/2731
安装numpy-1.13.1

运行问题:

UserWarning: volatile was removed and now has no effect. Use `with torch.no_grad():` instead.
  targets = [Variable(anno.cuda(),volatile=True) for anno in targets]

解决:
        if args.cuda:
            images = Variable(images.cuda())
            # targets = [Variable(anno.cuda(),volatile=True) for anno in targets]
            targets = [Variable(anno.cuda()) for anno in targets]
        else:
            images = Variable(images)
            # targets = [Variable(anno, volatile=True) for anno in targets]
            targets = [Variable(anno) for anno in targets]
/PytorchSSD/layers/modules/l2norm.py:17: UserWarning: nn.init.constant is now deprecated in favor of nn.init.constant_.
  init.constant(self.weight,self.gamma)
解决:
    def reset_parameters(self):
        # init.constant(self.weight, self.gamma)
        init.constant_(self.weight, self.gamma)
UserWarning: volatile was removed and now has no effect. Use `with torch.no_grad():` instead.
  priors = Variable(priorbox.forward(), volatile=True)
解决:
# priors = Variable(priorbox.forward(), volatile=True)
with torch.no_grad():
    priors = Variable(priorbox.forward())
RuntimeError:one of the variables needed for gradient computation has been modified by an inplace operation

# https://github.com/lzx1413/PytorchSSD/issues/72
# in layers/modules/l2norm.py      
# 原因:0.4.0把Varible和Tensor融合为一个Tensor,inplace操作,之前对Varible能用,但现在对Tensor,就会出错了,所以找到模型中所有的inplace操作,换成非inplace的写法就行
    def forward(self, x):
        norm = x.pow(2).sum(dim=1, keepdim=True).sqrt()+self.eps
        # x /= norm
        x = x / norm
        out = self.weight.unsqueeze(0).unsqueeze(2).unsqueeze(3).expand_as(x) * x
        return out
  File "/media/M_fM__VM_0M_eM__JM__M_eM__MM_7/PytorchSSD/refinedet_train_test.py", line 306, in train
    mean_arm_loss_c += arm_loss_c.data[0]
IndexError: invalid index of a 0-dim tensor. Use tensor.item() to convert a 0-dim tensor to a Python number

解决:
# mean_arm_loss_c += arm_loss_c.data[0]
# mean_arm_loss_l += arm_loss_l.data[0]
# mean_odm_loss_c += odm_loss_c.data[0]
# mean_odm_loss_l += odm_loss_l.data[0]
# 修改后
mean_arm_loss_c += arm_loss_c.item()
mean_arm_loss_l += arm_loss_l.item()
mean_odm_loss_c += odm_loss_c.item()
mean_odm_loss_l += odm_loss_l.item()
  File "/media/M_fM__VM_0M_eM__JM__M_eM__MM_7/PytorchSSD/layers/modules/refine_multibox_loss.py", line 114, in forward
    loss_c[pos] = 0 # filter out pos boxes for now
IndexError: The shape of the mask [1, 6375] at index 0 does not match the shape of the indexed tensor [6375, 1] at index 0
解决:
# loss_c[pos] = 0 # filter out pos boxes for now
# loss_c = loss_c.view(num, -1)
# 修改为
loss_c = loss_c.view(num, -1)
loss_c[pos] = 0 # filter out pos boxes for now

 

 

你可能感兴趣的:(pytorch)