Runtimeerror: input type in cuda but weight type not in cuda

~/miniconda3/envs/deep_mol/lib/python3.6/site-packages/torch/nn/modules/conv.py in forward(self, input)
    318     def forward(self, input):
    319         return F.conv2d(input, self.weight, self.bias, self.stride,
--> 320                         self.padding, self.dilation, self.groups)
    321 
    322 

RuntimeError: Input type (torch.cuda.FloatTensor) and weight type (torch.FloatTensor) should be the same

Hi, I got this error message above when I try to use GPU, but I have already put my network to cuda.
So there is something wrong with the conv2d?

Here is my network, I think there might be some bugs in my model

class Model(nn.Module):
    def __init__(self, in_channel, num_channel, out_class):
        super(QuickNAT, self).__init__()
        self.in_channel = in_channel
        self.num_channel = num_channel
        self.out_class = out_class
        
    def forward(self,x):
        encoder = Encoder(self.in_channel, self.num_channel)
        x5, x4, x3, x2, x1, idx1, idx2, idx3, idx4 = encoder(x)
        decoder = Decoder(self.num_channel, self.out_class, idx1, idx2, idx3, idx4, x4,x3,x2,x1)
        x = decoder(x5)
        return x
1 Like
class model(nn.Module):
    def __init__(self, in_channel, num_channel, out_class):
        super(QuickNAT, self).__init__()
        self.in_channel = in_channel
        self.num_channel = num_channel
        self.out_class = out_class
        self.encoder = Encoder(self.in_channel, self.num_channel)
        
    def forward(self,x):
        x5, x4, x3, x2, x1, idx1, idx2, idx3, idx4 = self.encoder(x)
        decoder = Decoder(self.num_channel, self.out_class, idx1, idx2, idx3, idx4, x4,x3,x2,x1)
        decoder = decoder.to(device)
        x = decoder(x5)
        return x

Change to this, the error fixed