Hi I try to create CNN network and this error pop up when i try to run it can anyone help
class gface(nn.Module):
def __init__(self, bottleneck_setting=MobiFace_bottleneck_setting, final=False):
super(gface, 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.conv3 = ConvBlock1(64, 64, 3, 1, 1, dw=True)
self.conv4= ConvBlock5(64,128,3, 1, 1)
self.conv5= ConvBlock5(128,256,3, 1, 1)
self.conv6= ConvBlock5(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)
self.prelu1 = nn.PReLU()
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
class ConvBlock5(nn.Module):
def __init__(self, inp, oup, k, s, p, dw=False, linear=False):
super(ConvBlock5, self).__init__()
self.linear = linear
self.conv1 = nn.Conv2d(inp, inp *2, 1, 1, 0, bias=False)
self.batch1 = nn.BatchNorm2d(inp * 2)
self.PRelu1=nn.PReLU(inp * 2)
self.max= nn.MaxPool2d((2, 2), 2)
self.dw_conv2=nn.Conv2d(inp * 2, inp * 2, k, s, p,groups=inp * 2, bias=False)
self.batch2=nn.BatchNorm2d(inp * 2)
self.PRelu2=nn.PReLU(inp * 2)
self.max1= nn.MaxPool2d((2, 2), 2)
self.conv3= nn.Conv2d(inp * 2, oup, 1, 1, 0, bias=False)
self.batch3=nn.BatchNorm2d(oup)
#self.maxP = x
def forward(self, x):
x = self.conv1(x)
x = self.batch1(x)
x=self.PRelu1(x)
x= self.max(x)
self.dw_conv2(x)
self.batch2(x)
self.PRelu2(x)
self.conv3(x)
self.batch3(x)
# self.max1(x)
#self.conv4(x)
#self.dw_conv3
# self.batch4(x)
class ConvBlock4(nn.Module):
def __init__(self, inp, oup, k, s, p, dw=False, linear=False):
super(ConvBlock4, self).__init__()
self.linear = linear
if dw:
self.conv = nn.Conv2d(inp, oup, k, s, p, 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 ConvBlock1(nn.Module):
def __init__(self, inp, oup, k, s, p, dw=False, linear=False):
super(ConvBlock1, self).__init__()
self.linear = linear
self.conv = nn.Conv2d(inp, oup, k, s, p, groups=inp, bias=False)
self.bn = nn.BatchNorm2d(oup)
#self.RELU=nn.ReLU(oup)
self.prelu = nn.PReLU(oup)
self.Avgpoo = nn.MaxPool2d((3,3), 2)
#self.maxP = x
def forward(self, x):
x = self.conv(x)
x = self.bn(x)
x=self.prelu(x)
x=self.Avgpoo(x)
this is when i try to run example
if __name__ == "__main__":
input = Variable(torch.FloatTensor(2, 3, 112, 96))
net = gface()
print(net)
x = net(input)
print(x.shape)
and this is error
<ipython-input-17-d11d5e404b1f> in <module>()
3 net = gface()
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:
TypeError: conv2d(): argument 'input' (position 1) must be Tensor, not NoneType