RuntimeError: Given groups=1, weight of size [16, 64, 3, 3], expected input[32, 512, 38, 38] to have 64 channels, but got 512 channels instead
SSD跑自制数据集,单类,黑白图片
def _conv_forward(self, input: Tensor, weight: Tensor, bias: Optional[Tensor]):
if self.padding_mode != 'zeros':
return F.conv2d(F.pad(input, self._reversed_padding_repeated_twice, mode=self.padding_mode),
weight, bias, self.stride,
_pair(0), self.dilation, self.groups)
return F.conv2d(input, weight, bias, self.stride,
self.padding, self.dilation, self.groups)
File "C:\Users\huayuan001.conda\envs\pyqxr\lib\site-packages\torch\nn\modules\conv.py", line 396, in _conv_forward
self.padding, self.dilation, self.groups)
RuntimeError: Given groups=1, weight of size [16, 64, 3, 3], expected input[16, 512, 38, 38] to have 64 channels, but got 512 channels instead
解决方法1:使用debug找到通道不匹配的地方进行修改
解决方法2:是不是黑白图片通道数和voc数据集彩色图片通道数不一样
解决此错误
维度不匹配。
他希望你该层的输入为[32, 512, 38, 38],32位batch size,512为通道数,后面两位是H和W,但是你的卷积之后的通道数在该层只有64通道,16 batch size,h和w只有3,这就是通道数匹配不上