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

 

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章