Hi I try to make network and there is error pop up i know which part it go wrong it the part when i try to use dilation=(3, 1) but im not sure how to fix it can anyone help
class ConvBlock(nn.Module):
def __init__(self, inp, oup, k, s, p, dw=False, linear=False):
super(ConvBlock, self).__init__()
self.linear = linear
if dw:
self.conv = nn.Conv2d(inp, oup, k, s, p, dilation=(3, 1), groups=inp, bias=False)
else:
self.conv = nn.Conv2d(inp, oup, k, s, p, bias=False)
self.bn = nn.BatchNorm2d(oup)
if not linear:
self.prelu = nn.PReLU(oup)
def forward(self, x):
x = self.conv(x)
x = self.bn(x)
if self.linear:
return x
else:
return self.prelu(x)
class gface1(nn.Module):
def __init__(self, bottleneck_setting=MobiFace_bottleneck_setting, final=False):
super(gface1, self).__init__()
self.final = final
self.conv1 = ConvBlock(3, 64, 3, 2, 1)
self.dw_conv1 = ConvBlock(64, 64, 3, 1, 1, dw=True)
self.conv4= ConvBlock6(64,128,3, 1, 1)
self.conv5= ConvBlock6(128,256,3, 1, 1)
self.conv6= ConvBlock6(256,512,3, 1, 1)
self.conv7 = ConvBlock(512, 512, 1, 1, 0, linear=True)
#self.linear1 = nn.Linear(512*7*7, 512)
self.linear7 = ConvBlock4(512, 512, (7, 6), 1, 0, dw=True, linear=True)
self.linear1 = ConvBlock4(512, 128, 1, 1, 0, linear=True)
for m in self.modules():
if isinstance(m, nn.Conv2d):
n = m.kernel_size[0] * m.kernel_size[1] * m.out_channels
m.weight.data.normal_(0, math.sqrt(2. / n))
elif isinstance(m, nn.BatchNorm2d):
m.weight.data.fill_(1)
m.bias.data.zero_()
def forward(self, x):
x = self.conv1(x)
x = self.dw_conv1(x)
#x= self.conv3(x)
x=self.conv4(x)
x= self.conv5(x)
x=self.conv6(x)
x=self.conv7(x)
#x = x.view(x.size(0), -1)
#x = self.linear1(x)
#if self.final is False:
# x = self.prelu1(x)
x = self.linear7(x)
#x = self.linear1(x)
x = x.view(x.size(0), -1)
return x
if __name__ == "__main__":
input = Variable(torch.FloatTensor(2, 3, 112, 96))
net = gface1()
print(net)
x = net(input)
print(x.shape)
gface1(
(conv1): ConvBlock(
(conv): Conv2d(3, 64, kernel_size=(3, 3), stride=(2, 2), padding=(1, 1), bias=False)
(bn): BatchNorm2d(64, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
(prelu): PReLU(num_parameters=64)
)
(dw_conv1): ConvBlock(
(conv): Conv2d(64, 64, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), dilation=(3, 1), groups=64, bias=False)
(bn): BatchNorm2d(64, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
(prelu): PReLU(num_parameters=64)
)
(conv4): ConvBlock6(
(conv): Conv2d(64, 128, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), groups=64, bias=False)
(batch1): BatchNorm2d(128, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
(PRelu1): PReLU(num_parameters=128)
(dw_conv2): Conv2d(128, 128, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), groups=128, bias=False)
(batch2): BatchNorm2d(128, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
(PRelu2): PReLU(num_parameters=128)
(max2): MaxPool2d(kernel_size=(2, 2), stride=2, padding=0, dilation=1, ceil_mode=False)
(conv3): Conv2d(128, 128, kernel_size=(1, 1), stride=(1, 1), bias=False)
(batch3): BatchNorm2d(128, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
)
(conv5): ConvBlock6(
(conv): Conv2d(128, 256, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), groups=128, bias=False)
(batch1): BatchNorm2d(256, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
(PRelu1): PReLU(num_parameters=256)
(dw_conv2): Conv2d(256, 256, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), groups=256, bias=False)
(batch2): BatchNorm2d(256, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
(PRelu2): PReLU(num_parameters=256)
(max2): MaxPool2d(kernel_size=(2, 2), stride=2, padding=0, dilation=1, ceil_mode=False)
(conv3): Conv2d(256, 256, kernel_size=(1, 1), stride=(1, 1), bias=False)
(batch3): BatchNorm2d(256, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
)
(conv6): ConvBlock6(
(conv): Conv2d(256, 512, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), groups=256, bias=False)
(batch1): BatchNorm2d(512, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
(PRelu1): PReLU(num_parameters=512)
(dw_conv2): Conv2d(512, 512, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), groups=512, bias=False)
(batch2): BatchNorm2d(512, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
(PRelu2): PReLU(num_parameters=512)
(max2): MaxPool2d(kernel_size=(2, 2), stride=2, padding=0, dilation=1, ceil_mode=False)
(conv3): Conv2d(512, 512, kernel_size=(1, 1), stride=(1, 1), bias=False)
(batch3): BatchNorm2d(512, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
)
(conv7): ConvBlock(
(conv): Conv2d(512, 512, kernel_size=(1, 1), stride=(1, 1), bias=False)
(bn): BatchNorm2d(512, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
)
(linear7): ConvBlock4(
(conv): Conv2d(512, 512, kernel_size=(7, 6), stride=(1, 1), groups=512, bias=False)
(bn): BatchNorm2d(512, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
)
(linear1): ConvBlock4(
(conv): Conv2d(512, 128, kernel_size=(1, 1), stride=(1, 1), bias=False)
(bn): BatchNorm2d(128, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
)
)
---------------------------------------------------------------------------
RuntimeError Traceback (most recent call last)
<ipython-input-99-9d44146f9f58> in <module>()
3 net = gface1()
4 print(net)
----> 5 x = net(input)
6 print(x.shape)
6 frames
/usr/local/lib/python3.6/dist-packages/torch/nn/modules/conv.py in _conv_forward(self, input, weight)
414 _pair(0), self.dilation, self.groups)
415 return F.conv2d(input, weight, self.bias, self.stride,
--> 416 self.padding, self.dilation, self.groups)
417
418 def forward(self, input: Tensor) -> Tensor:
RuntimeError: Calculated padded input size per channel: (6 x 6). Kernel size: (7 x 6). Kernel size can't be greater than actual input size