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:
- Python: CUDA error: an illegal memory access was accounted for
- Solve the runtimeerror in RNN: expected scalar type long but found float error
- CUBLAS_STATUS_ALLOC_FAILED
- How to use torch.sum()
- ValueError: Expected more than 1 value per channel when training, got input size torch.Size([1, 256,
- RuntimeError: ‘lengths’ argument should be a 1D CPU int64 tensor, but got 1D cuda:0 Long tensor
- pytorch raise RuntimeError(‘Error(s) in loading state_dict for {}:\n\t{}‘.format
- CheXNet-master: CUDA out of memery [How to Solve]
- Build your own resnet18 network and load torch vision’s own weight
- (26)RuntimeError: Error(s) in loading state_dict for YoloBody:size mismatch for yolo_head3.1.weight
- The difference of. Pt,. PTH,. Pkl and the way to save the model
- Runtimeerror using Python training model: CUDA out of memory error resolution
- PyTorch CUDA error: an illegal memory access was encountered
- Python learning notes (5) — cross entropy error runtimeerror: 1D target tensor expected, multi target not supported
- Solve runtimeerror: reduce failed to synchronize: device side assert triggered problem
- Pytorch RuntimeError CuDNN error CUDNN_STATUS_SUCCESS (How to Fix)
- RuntimeError: cuDNN error: CUDNN_STATUS_EXECUTION_FAILED
- TypeError: __array__() takes 1 positional argument but 2 were given
- RuntimeError: cuda runtime error (801) : operation not supported at ..
- RuntimeError: reciprocal is not implemented for type torch.cuda.LongTensor