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.Conv2d(1,10,kernel_size=2,stride=2,padding=3,bias=False),
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