Conv1d diffuclties

I have read the other similar posts but have not been able to solve the issue and get Conv1d to work.

Initially I was getting this error: Runtime error: Expected object of type torch.DoubleTensor but found type torch.FloatTensor for argument #2 ‘weight’.

I tried adding a .double() at the end of my nn.Conv1d line but that changed the errror message to: RuntimeError: Expected object of type torch.FloatTensor but found type torch.DoubleTensor for argument #2 ‘target’

This latter error was being triggered later on in the code. I tried to cast the tensor x = x.type(torch.FloatTensor) but I got the same error. How can i solve this issue?


class Net(nn.Module):

def __init__ (self):
    super(Net, self).__init__()
    self.conv1 = nn.Conv1d(2, 10, 5).double() #.double
    self.fc1 = nn.Linear(10*95, 100)
    self.fc2 = nn.Linear(100, 99)
def forward(self, x):
    x = F.relu(self.conv1(x))
    x = x.view(-1, 10 * 95)
    x = F.relu(self.fc1(x))
    x = self.fc2(x)
    x = x.type(torch.FloatTensor) # I tried adding this line in multiple places to no avail
    return x

net = Net()

Your target seems to be still a torch.DoubleTensor. Could you cast it to .float() and try it again?

1 Like

Thank you! I should have realized the error. I had to cast both the X and Y with float. I didn’t even need .double()