Avg_pool2d(): argument 'input' (position 1) must be Tensor, not int

Archy_dragon: <p>Hi i try to run  avg_pool2d() and this error pop up not sure how to fix it can anyone help<br>
my modle</p>
<pre><code class="lang-auto">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)
</code></pre>
<p>error <code>this is my code to run this model </code></p>
<pre><code class="lang-auto">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```
</code></pre>
<p>1 if <strong>name</strong> == “<strong>main</strong>”:<br>
2     input = Variable(torch.FloatTensor(2, 3, 112, 96))<br>
----&gt; 3     net = gface()<br>
4     print(net)</p>
<p>3 frames<br>
/usr/local/lib/python3.6/dist-packages/torch/nn/modules/pooling.py in forward(self, input)<br>
597     def forward(self, input: Tensor) -&gt; Tensor:<br>
598         return F.avg_pool2d(input, self.kernel_size, self.stride,<br>
–&gt; 599                             self.padding, self.ceil_mode, self.count_include_pad, self.divisor_override)<br>
600<br>
601</p>
<p>TypeError: avg_pool2d(): argument ‘input’ (position 1) must be Tensor, not int</p>
<pre><code class="lang-auto"></code></pre>

RaLo4: <p><code>torch.nn.AvgPool2d</code> does not need out_channels. See <a href="https://pytorch.org/docs/stable/generated/torch.nn.AvgPool2d.html#avgpool2d" rel="noopener nofollow ugc">here</a><br>
So this line gives you your error:</p>
<aside class="quote no-group" data-username="Archy_dragon" data-post="1" data-topic="93199">
<div class="title">
<div class="quote-controls"></div>
<img loading="lazy" alt="" width="24" height="24" src="https://discuss.pytorch.org/user_avatar/discuss.pytorch.org/archy_dragon/48/27582_2.png" class="avatar"> Archy_dragon:</div>
<blockquote>
<p><code>self.Avgpoo = m(oup) </code></p>
</blockquote>
</aside>
<p>Just remove it and change</p>
<aside class="quote no-group" data-username="Archy_dragon" data-post="1" data-topic="93199">
<div class="title">
<div class="quote-controls"></div>
<img loading="lazy" alt="" width="24" height="24" src="https://discuss.pytorch.org/user_avatar/discuss.pytorch.org/archy_dragon/48/27582_2.png" class="avatar"> Archy_dragon:</div>
<blockquote>
<p><code>m = nn.AvgPool2d(3, 2)</code></p>
</blockquote>
</aside>
<p>to</p>
<pre><code class="lang-auto">self.Avgpoo = nn.AvgPool2d(3, 2)
</code></pre>

Archy_dragon: <aside class="quote no-group" data-username="RaLo4" data-post="2" data-topic="93199">
<div class="title">
<div class="quote-controls"></div>
<img loading="lazy" alt="" width="24" height="24" src="https://discuss.pytorch.org/letter_avatar_proxy/v4/letter/r/65b543/48.png" class="avatar"> RaLo4:</div>
<blockquote>
<p><code>self.Avgpoo = nn.AvgPool2d(3, 2)</code></p>
</blockquote>
</aside>
<p>I just wonder for forward do i need to add anthing there or that should be ok?</p>

RaLo4: <p>in the forward function your tensor will just get passed through like normally.</p>
<aside class="quote no-group" data-username="Archy_dragon" data-post="1" data-topic="93199">
<div class="title">
<div class="quote-controls"></div>
<img loading="lazy" alt="" width="24" height="24" src="https://discuss.pytorch.org/user_avatar/discuss.pytorch.org/archy_dragon/48/27582_2.png" class="avatar"> Archy_dragon:</div>
<blockquote>
<p><code>x=self.Avgpoo(x)</code></p>
</blockquote>
</aside>
<p>you can leave it as is</p>

Archy_dragon: <p>so am i correct forward is just replete the main method</p>