-
Notifications
You must be signed in to change notification settings - Fork 585
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
RuntimeError: Given groups=1, weight of size [128, 512, 1, 1], expected input[4, 2048, 1, 1] to have 512 channels, but got 2048 channels instead #189
Comments
我也是初学者,试着回答一下,不对的话请大神指正,nn.Conv2d第一个参数是输入通道数,这个输入通道数是不可改变的,是由你的图片通道数决定的 |
但是代码里本来是这么写的: |
|
好的,太感谢了老哥!我回头试试 |
大神你好,我是个初学者,在用voc训练psp的时候默认设置可以跑通,但是我想把Ci弄小一点,于是改成了:
class _PSPHead(nn.Module):
def init(self, nclass, norm_layer=nn.BatchNorm2d, norm_kwargs=None, **kwargs):
super(_PSPHead, self).init()
self.psp = _PyramidPooling(512, norm_layer=norm_layer, norm_kwargs=norm_kwargs)
self.block = nn.Sequential(
nn.Conv2d(1024, 128, 3, padding=1, bias=False),#Ci,Co,kernelsize
norm_layer(128, **({} if norm_kwargs is None else norm_kwargs)),
nn.ReLU(True),
nn.Dropout(0.1),
nn.Conv2d(128, nclass, 1)
)
运行就报错了:
Traceback (most recent call last):
File "./train.py", line 335, in
trainer.train()
File "./train.py", line 224, in train
outputs = self.model(images)
File "/usr/local/lib/python3.6/dist-packages/torch/nn/modules/module.py", line 727, in _call_impl
result = self.forward(*input, **kwargs)
File "/home/cse/lza/awesome-semantic-segmentation-pytorch/core/models/pspnet.py", line 51, in forward
x = self.head(c4)
File "/usr/local/lib/python3.6/dist-packages/torch/nn/modules/module.py", line 727, in _call_impl
result = self.forward(*input, **kwargs)
File "/home/cse/lza/awesome-semantic-segmentation-pytorch/core/models/pspnet.py", line 113, in forward
x = self.psp(x)
File "/usr/local/lib/python3.6/dist-packages/torch/nn/modules/module.py", line 727, in _call_impl
result = self.forward(*input, **kwargs)
File "/home/cse/lza/awesome-semantic-segmentation-pytorch/core/models/pspnet.py", line 87, in forward
feat1 = F.interpolate(self.conv1(self.avgpool1(x)), size, mode='bilinear', align_corners=True)
File "/usr/local/lib/python3.6/dist-packages/torch/nn/modules/module.py", line 727, in _call_impl
result = self.forward(*input, **kwargs)
File "/usr/local/lib/python3.6/dist-packages/torch/nn/modules/container.py", line 117, in forward
input = module(input)
File "/usr/local/lib/python3.6/dist-packages/torch/nn/modules/module.py", line 727, in _call_impl
result = self.forward(*input, **kwargs)
File "/usr/local/lib/python3.6/dist-packages/torch/nn/modules/conv.py", line 423, in forward
return self._conv_forward(input, self.weight)
File "/usr/local/lib/python3.6/dist-packages/torch/nn/modules/conv.py", line 420, in _conv_forward
self.padding, self.dilation, self.groups)
RuntimeError: Given groups=1, weight of size [128, 512, 1, 1], expected input[4, 2048, 1, 1] to have 512 channels, but got 2048 channels instead
调了好久都是同类型的错,请问我该如何让Ci变小呢?
The text was updated successfully, but these errors were encountered: