我在使用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实现如下,我直接复制过来
class net_modlist(nn.Module):
def __init__(self):
super(net_modlist, self).__init__()

在使用mmdetection框架修改neck.fpn时遇到RuntimeError,错误指出输入和权重类型不一致。问题根源可能在于nn.ModuleList与nn.Sequential的使用不当。解决方案是尽量使用nn.ModuleList并在forward中正确实现,以避免输入类型不匹配。这个问题在尝试增加fpn结构时尤为明显,错误也可能源于未正确实现nn.ModuleList。此博客分享了解决经验,并提供相关资源链接。
最低0.47元/天 解锁文章
4498

被折叠的 条评论
为什么被折叠?



