我在使用mmdetection修改neck.fpn的时候,遇到了以下报错:
1、RuntimeError: Input type (torch.cuda.FloatTensor) and weight type (torch.FloatTensor) should be the same, but I set model and data to cuda
2、NotImplementedError
网上很多建议第1个报错将网络和模型都部署到GPU,但是我的问题不在这,后来经过一番检索(StackOverflow网友建议)发现,应该是nn.ModuleList与nn.Sequential的使用问题,mmdetetion中,可能是由于注册方式的原因(具体原因没有深入了解),在修改网络的时候,需要尽量避免使用nn.Sequential,应当优先使用nn.ModuleList。同时使用nn.ModuleList后,需要在forward中实现,具体差别和使用方法可参考文章——详解PyTorch中的ModuleList和Sequential,nn.ModuleList实现如下,我直接复制过来