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

Why can’t you stop buying 618?From the technical dimension to explore>>>

This error occurred while running torch

The error content probably means that the input type is CPU (torch. Floattensor), and the parameter type is GPU (torch. CUDA. Floattensor)
links to data types: Official links

First of all, please check whether CUDA is used correctly

We usually specify CUDA as follows:

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

In this way, input is converted into CUDA type

The correct way is to:

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

Reason:
tensor. To() is used to generate a new tensor without changing the original data

However, note that
module. To() is an “in place” method, while the tensor. To() function is not

undertake MATLAB, Python and C + + programming, machine learning, computer vision theory implementation and guidance, undergraduate and master can, salted fish trading, professional answer please go to know, for details, please contact QQ number 757160542, if you are the one

This article shares in the blog “Yu Xiaoyong” (CSDN).

Similar Posts: