pypipython-3.x95% confidence\u2191 201

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

Full error message
This:

device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
model.to(device)

for data in dataloader:
    inputs, labels = data
    outputs = model(inputs)

Gives the error:

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

You get this error because your model is on the GPU, but your data is on the CPU. So, you need to send your input tensors to the GPU. inputs, labels = data # this is what you had inputs, labels = inputs.cuda(), labels.cuda() # add this line Or like this, to stay consistent with the rest of your code: device = torch.device("cuda:0" if torch.cuda.is_available() else "cpu") inputs, labels = inputs.to(device), labels.to(device) The same error will be raised if your input tensors are on the GPU but your model weights aren't. In this case, you need to send your model weights to the GPU. model = MyModel() if torch.cuda.is_available(): model.cuda() See the documentation for cuda(), and its opposite, cpu().

API access

Get this solution programmatically \u2014 free, no authentication.

curl https://depscope.dev/api/error/5f125460a235b3b49e4948291757035eec085092c6750551b9ccc9a2fc407757
hash \u00b7 5f125460a235b3b49e4948291757035eec085092c6750551b9ccc9a2fc407757
RuntimeError: Input type (torch.FloatTensor) and weight type… — DepScope fix | DepScope