mmdetection中:RuntimeError:input is smaller than kernel(shape_check at mmdet/ops/dcn/src/deform_conv)
问题描述
RuntimeError:input is smaller than kernel(shape_check at mmdet/ops/dcn/src/deform_conv)
前提:在使用mmdetection(v 1.0.0的版本)中的可变形卷积操作时,遇到了这个问题。具体是在MSCOCO test-dev集下跑测试,如果在验证集跑测试的没有出现这个问题。
出现这个问题是在test-dev集的第7311张图片上,我们把图片的大小打出来:
有一张图片的size出现了2,torch.Size([1,256,2,11])
但是可变形卷积是3。这里就出现了上面出现的问题了。
但是在使用的可变形卷积中,已经用了padding=1的操作,按理说不应会出现问题。
所以只能查看源码,看是不是判断出了问题,或者padding=1没有用上?
在官方github的mmcv库中的mmcv/mmcv/ops/csrc/pytorch/deform_conv_cuda.cu
下找到了deform_conv_cuda.cu
这里直接判断输入的大小和核的大小了,所以问题就出现在这里!!!
解决方法
- 修改源码,重新编译(不会,也懒得百度,逃~)
- 就是在送入可变形卷积之前,把padding先加上input,然后把padding改为0。这样再源码里判断的时候就不会报错了,而且也没有改变图的大小。
- 不加可变形卷积
先padding
两种方法:
用ZeroPad2d()
用上面的方法重新测试训练好的模型,会报错
这是因为是用了nn.xxx
这个会改变原有的模型。导致模型不一样了。而使用下面的nn.functional.xxx
只是进行运算而已,不需要涉及到层的参数,也不会新建一个层
用pad()
用nn.functional带的pad操作
修改完后,就可以正常的在test-dev上测试了。