一个卡了我很久的bug,翻遍google跟中文社区都没找到解决方案……有人说数据并行在优化器后面,但MMdetection3D框架顺序规定好了。
初衷就是在模型中插入了一个模块,然后疯狂报这个错,最后定位到了这几行代码上
elif norm_fn == 'batch':
self.norm1 = nn.BatchNorm2d(planes)
self.norm2 = nn.BatchNorm2d(planes)
if not stride == 1:
self.norm3 = nn.BatchNorm2d(planes)
开始时以为是nn.BatchNorm2d里面的参数引起了优化器底层报错,所以尝试加了
nn.BatchNorm2d(planes, affine=False)
和
nn.BatchNorm2d(planes,track_running_stats=False)
这样虽然能跑起来不再报错,但是模型的参数少了running_mean跟running_var
最后定位到了后面的代码块:
...
elif norm_fn == 'batch':
self.norm1 = nn.BatchNorm2d(planes)
self.norm2 = nn.BatchNorm2d(planes)
if not stride == 1:
self.norm3 = nn.BatchNorm2d(planes)
...
self.downsample