this is my code.
class ResNet9(nn.Module):
def __init__(self, in_channels, out_channels):
super().__init__()
#1st Block
self.conv1 = conv_block(in_channels, 64)
self.conv2 = conv_block(64, 128, True)
#Residual layer
self.res1 = nn.Sequential(conv_block(128,128), conv_block(128,128))
#2nd Block
self.conv3 = conv_block(128, 256, True)
self.conv4 = conv_block(256, 512, True)
#Residual layer
self.res2 = nn.Sequential(conv_block(512,512), conv_block(512,512))
#Linear Network
self.linear = nn.Sequential(
nn.MaxPool2d(16),
nn.Flatten(),
nn.Linear(512, 128),
nn.ReLU(),
nn.Linear(128, out_channels),
nn.LogSoftmax()
)
def forward(self,x):
#Block-1
out = self.conv1(x)
out = self.conv2(x)
res1 = self.res1(out) + out
#Block-1
out = self.conv3(x)
out = self.conv4(x)
res2 = self.res2(out) + out
#Linear network
out = self.Linear(res2)
return out
model = ResNet9(1,2).to(device)
im trying to give in a batch of img data with size [100,1,128,128], but it gives this error.
---------------------------------------------------------------------------
RuntimeError Traceback (most recent call last)
<ipython-input-20-1aacca183d36> in <module>()
----> 1 model(x.to(device))
6 frames
/usr/local/lib/python3.6/dist-packages/torch/nn/modules/module.py in __call__(self, *input, **kwargs)
548 result = self._slow_forward(*input, **kwargs)
549 else:
--> 550 result = self.forward(*input, **kwargs)
551 for hook in self._forward_hooks.values():
552 hook_result = hook(self, input, result)
<ipython-input-12-6ed96ba919e0> in forward(self, x)
28 #Block-1
29 out = self.conv1(x)
---> 30 out = self.conv2(x)
31 res1 = self.res1(out) + out
32
/usr/local/lib/python3.6/dist-packages/torch/nn/modules/module.py in __call__(self, *input, **kwargs)
548 result = self._slow_forward(*input, **kwargs)
549 else:
--> 550 result = self.forward(*input, **kwargs)
551 for hook in self._forward_hooks.values():
552 hook_result = hook(self, input, result)
/usr/local/lib/python3.6/dist-packages/torch/nn/modules/container.py in forward(self, input)
98 def forward(self, input):
99 for module in self:
--> 100 input = module(input)
101 return input
102
/usr/local/lib/python3.6/dist-packages/torch/nn/modules/module.py in __call__(self, *input, **kwargs)
548 result = self._slow_forward(*input, **kwargs)
549 else:
--> 550 result = self.forward(*input, **kwargs)
551 for hook in self._forward_hooks.values():
552 hook_result = hook(self, input, result)
/usr/local/lib/python3.6/dist-packages/torch/nn/modules/conv.py in forward(self, input)
351
352 def forward(self, input):
--> 353 return self._conv_forward(input, self.weight)
354
355 class Conv3d(_ConvNd):
/usr/local/lib/python3.6/dist-packages/torch/nn/modules/conv.py in _conv_forward(self, input, weight)
348 _pair(0), self.dilation, self.groups)
349 return F.conv2d(input, weight, self.bias, self.stride,
--> 350 self.padding, self.dilation, self.groups)
351
352 def forward(self, input):
RuntimeError: Given groups=1, weight of size [128, 64, 3, 3], expected input[100, 1, 128, 128] to have 64 channels, but got 1 channels instead