TypeError : new() received an invalid combination of arguments

username: a_d
cooked: <p>Hello all,<br>
I have been dealing with a baffling error for a few days…<br>
The error message is as follows -</p>
<pre><code class="lang-auto">    self.weight = Parameter(torch.Tensor(
TypeError: new() received an invalid combination of arguments - got (float, int, int), but expected one of:
 * (*, torch.device device)
 * (torch.Storage storage)
 * (Tensor other)
 * (tuple of ints size, *, torch.device device)
      didn't match because some of the arguments have invalid types: (float, int, int)
 * (object data, *, torch.device device)
      didn't match because some of the arguments have invalid types: (float, int, int)

</code></pre>
<p>This error message generates from calling a Residual Block<br>
which is being called as -</p>
<pre><code class="lang-auto">ResidualBlock(32, 64)
</code></pre>
<p>and the definition of the ResidualBlock is as follows -</p>
<pre><code class="lang-auto">
class ResidualBlock(nn.Module):
    def __init__(self, in_Channels, out_channels):
        super(ResidualBlock, self).__init__()
        self.bn1 = nn.BatchNorm1d(in_Channels)
        self.downsample = nn.Conv1d(in_Channels, out_channels / 4, kernel_size=1, stride=1, bias=False)
        self.bn2 = nn.BatchNorm1d(out_channels / 4)
        self.residual_conv = nn.Conv1d(in_channels=out_channels / 4, out_channels=out_channels / 4, kernel_size=3,
                                       stride=1, padding=1)
        self.upsample = nn.Conv1d(in_channels=out_channels / 4, out_channels=out_channels, kernel_size=1, stride=1)
        self.direct_conv = nn.Conv1d(in_channels=in_Channels, out_channels=out_channels, kernel_size=1, stride=1)

    def forward(self, x):
        out = self.bn1(x)
        out1 = nn.functional.relu(out)

        out = self.downsample(out1)
        out = self.bn2(out)
        out = nn.functional.relu(out)

        out = self.residual_conv(out)
        out = self.bn2(out)
        out = nn.functional.relu(out)

        out = self.upsample(out)
        residual = self.upsample(out1)

        return out + residual
</code></pre>
<p>It might be a quite simple mistake but I am not able to figure it out.<br>
I am using pytorch 1.6 (1.6.0.dev20200522’) if it matters…<br>
TIA</p>

username: Nikronic
cooked: <p>Hi,</p>
<p>The error says you have float input for channel size in conv layers. Note that in python, <code>int/int=float</code>. So whenever you used <code>channel / 4</code> the output is <code>16.0</code> not <code>16</code> and that is not a valid value for channel size in conv layers.</p>
<aside class="quote no-group" data-username="a_d" data-post="1" data-topic="83095">
<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/a/e19b73/48.png" class="avatar"> a_d:</div>
<blockquote>
<p><code>got (float, int, int)</code></p>
</blockquote>
</aside>
<p>To solve this issue, just use <code>//</code> instead of <code>/</code> or convert to int explicitly using <code>int(channel / 4)</code>.</p>
<p>Bests</p>

username: a_d
cooked: <p><a class="mention" href="/u/nikronic">@Nikronic</a> Thanks a lot for your help</p>