Hi i try to run avg_pool2d() and this error pop up not sure how to fix it can anyone help
my modle
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)
m = nn.AvgPool2d(3, 2)
self.Avgpoo = m(oup)
#self.maxP = x
def forward(self, x):
x = self.conv(x)
x = self.bn(x)
x=self.prelu(x)
x=self.Avgpoo(x)
error this is my code to run this model
class gface(nn.Module):
def __init__(self, bottleneck_setting=MobiFace_bottleneck_setting, final_linear=False):
super(gface, self).__init__()
self.final_linear = final_linear
self.conv1 = ConvBlock(3, 64, 3, 2, 1)# in,out,3*3,kernel_size,stride
self.dw_conv1 = ConvBlock(64, 64, 3, 1, 1, dw=True)
#self.conv2 = ConvBlock1(64, 64, 3, 2, 1)
self.dw_conv2 = ConvBlock1(64, 64, 3, 1, 1)
self.inplanes = 64
block = Bottleneck
self.blocks = self._make_layer(block, bottleneck_setting)
self.conv2 = ConvBlock(256, 512, 1, 1, 0, linear=True)
self.linear1 = nn.Linear(7*7*512, 512)
self.prelu1 = nn.PReLU()
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 _make_layer(self, block, setting):
layers = []
for t, c, n, s in setting:
for i in range(n):
if i == 0:
layers.append(block(self.inplanes, c, s, t))
else:
layers.append(block(self.inplanes, c, 1, t))
self.inplanes = c
return nn.Sequential(*layers)
def forward(self, x):
x = self.conv1(x)
x = self.dw_conv1(x)
x = self.dw_conv2(x)
x = self.blocks(x)
x = self.conv2(x)
x = x.view(x.size(0), -1)
x = self.linear1(x)
if self.final_linear is False:
x = self.prelu1(x)
return x```
1 if name == βmainβ:
2 input = Variable(torch.FloatTensor(2, 3, 112, 96))
----> 3 net = gface()
4 print(net)
3 frames
/usr/local/lib/python3.6/dist-packages/torch/nn/modules/pooling.py in forward(self, input)
597 def forward(self, input: Tensor) -> Tensor:
598 return F.avg_pool2d(input, self.kernel_size, self.stride,
β> 599 self.padding, self.ceil_mode, self.count_include_pad, self.divisor_override)
600
601
TypeError: avg_pool2d(): argument βinputβ (position 1) must be Tensor, not int