RuntimeError: Input type (torch.FloatTensor) and weight type (torch.cuda.FloatTensor) should be the same
This problem occurs because the tensor of the input model is loaded in the CPU, while the model is loaded on CUDA.
Solution: load the input tensor into CUDA or load the model into CPU
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
model = model.to(device)
img = img.to(device)
output = model(img)
Or:
model = model.cuda()
img = img.cuda()
Read More:
- RuntimeError: reciprocal is not implemented for type torch.cuda.LongTensor
- RuntimeError: NCCL error in: /pytorch/torch/lib/c10d/ProcessGroupNCCL.cpp:784 torch
- Build your own resnet18 network and load torch vision’s own weight
- ValueError: Expected more than 1 value per channel when training, got input size torch.Size([1, 256,
- torch.cuda.is_ Available() returns false
- RuntimeError: Couldn‘t open shared file mapping: <torch_16716_3565374679>, error code: <1455>
- [Solved] RuntimeError: Expected object of scalar type Float but got scalar type Double for argument #2 ‘mat1‘
- Solve the runtimeerror in RNN: expected scalar type long but found float error
- How to use torch.sum()
- (26)RuntimeError: Error(s) in loading state_dict for YoloBody:size mismatch for yolo_head3.1.weight
- RuntimeError: ‘lengths’ argument should be a 1D CPU int64 tensor, but got 1D cuda:0 Long tensor
- torch.nn.BCELoss are unsafe to autocast [How to Solve]
- To solve the problem of increasing video memory when training network (torch)
- After introducing sass into Vue project, start to report error typeerror [err]_ INVALID_ ARG_ Type]: the “path” argument must be of type string
- Copying a param with shape torch. Size ([262, 2048]), parameter size does not match
- Elmentui form. When setting input type = number, remove the up and down arrows
- AttributeError: module ‘torch’ has no attribute’_six’ [The problem is solved after restart]
- Matlab prompts undefined operator ‘*’ for input arguments of type ‘cell’
- Error in installing torch vision or pilot on Linux or Jetson nano: the headers or library files could not be found for JPEG
- Runtimeerror using Python training model: CUDA out of memory error resolution