TypeError : new() received an invalid combination of arguments

Hello all,
I have been dealing with a baffling error for a few days…
The error message is as follows -

    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)

This error message generates from calling a Residual Block
which is being called as -

ResidualBlock(32, 64)

and the definition of the ResidualBlock is as follows -


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

It might be a quite simple mistake but I am not able to figure it out.
I am using pytorch 1.6 (1.6.0.dev20200522’) if it matters…
TIA

Hi,

The error says you have float input for channel size in conv layers. Note that in python, int/int=float. So whenever you used channel / 4 the output is 16.0 not 16 and that is not a valid value for channel size in conv layers.

To solve this issue, just use // instead of / or convert to int explicitly using int(channel / 4).

Bests

2 Likes

@Nikronic Thanks a lot for your help