# Problem Resnet in pytorch

``````class ResidualBlock(nn.Module):
def __init__(self, in_channels, out_channels, stride=1, downsample=None):
super(ResidualBlock, self).__init__()
self.conv1 = nn .Conv2d(1, 10, 1)
self.bn1 = nn.BatchNorm2d(10)
self.relu = nn.ReLU(inplace=True)
self.conv2 = nn.Conv2d(10, 10, 1)
self.bn2 = nn.BatchNorm2d(10)
self.downsample = downsample

def forward(self, x):
residual = x
out = self.conv1(x)
out = self.bn1(out)
out = self.relu(out)
out = self.conv2(out)
out = self.bn2(out)
if self.downsample:
residual = self.downsample(x)
out += residual
out = self.relu(out)
return out
class ResNet34(nn.Module):
def __init__(self):
super(ResNet34,self).__init__()

self.block1 = nn.Sequential(
nn.BatchNorm2d(10),
nn.ReLU(True)
)

self.block2 = nn.Sequential(
nn.MaxPool2d(1,1),
ResidualBlock(64,64),
ResidualBlock(64,64,2)
)

self.block3 = nn.Sequential(
ResidualBlock(64,128),
ResidualBlock(128,128,2)
)

self.block4 = nn.Sequential(
ResidualBlock(128,256),
ResidualBlock(256,256,2)
)
self.block5 = nn.Sequential(
ResidualBlock(256,512),
ResidualBlock(512,512,2)
)

self.avgpool = nn.AvgPool2d(2)
# vowel_diacritic
self.fc1 = nn.Linear(512,11)
# grapheme_root
self.fc2 = nn.Linear(512,168)
# consonant_diacritic
self.fc3 = nn.Linear(512,7)

def forward(self,x):
x = self.block1(x)
x = self.block2(x)
x = self.block3(x)
x = self.block4(x)
x = self.block5(x)
x = self.avgpool(x)
x = x.view(x.size(0),-1)
x = self.fc1(x)
x = self.fc2(x)
x = self.fc3(x)
return x

``````

problem : RuntimeError: Given groups=1, weight of size [10, 1, 1, 1], expected input[26891, 10, 5, 5] to have 1 channels, but got 10 channels instead

In your custom `ResidualBlock` implementation you are passing `in_channels` as well as `out_channels` as arguments, but are never using them and are hard-coding the channels instead as `1` input channel and `10` output channels.
Based on this, I would guess that `self.block2` will raise the shape mismatch as it would expect to get an input with `1` input channel while the incoming activation (coming from `self.block1`) would have `10` channels.
Also, you are trying to set the `in_/out_channels` in `block2` to `64, 64`, which will also not work (as I previously described these values are not used currently but if they were they would also raise a shape mismatch).