Source code:
device = torch.device("cuda:0" if torch.cuda.is_available() else "cpu")
model = torchvision.models.resnet18(pretrained=None)
model.fc = nn.Linear(512, 10)
summary(model, input_size=[(3, 224, 224)], batch_size=256, device="cuda")
Error Messages: RuntimeError: Input type (torch.cuda.FloatTensor) and weight type (torch.FloatTensor) should be the same
Solution:
device = torch.device("cuda:0" if torch.cuda.is_available() else "cpu")
model = torchvision.models.resnet18(pretrained=None)
model.fc = nn.Linear(512, 10)
model = model.to(device) # add this line will be OK
summary(model, input_size=[(3, 224, 224)], batch_size=256, device="cuda")
Read More:
- [Solved] RuntimeError: Input type (torch.FloatTensor) and weight type (torch.cuda.FloatTensor) should be the
- [Solved] RuntimeError: cublas runtime error : resource allocation failed at
- urllib.error.URLError: <urlopen error [Errno -3] Temporary failure in name resolution>
- ‘InceptionOutputs‘ object has no attribute ‘log_softmax‘
- Pytorch torch.cuda.FloatTensor Error: RuntimeError: one of the variables needed for gradient computation has…
- Pytorch ValueError: Expected more than 1 value per channel when training, got input size [1, 768
- [Solved] RuntimeError: gather(): Expected dtype int64 for index
- Pytorch directly creates a tensor on the GPU error [How to Solve]
- Python RuntimeError: Expected 4-dimensional input for 4-dimensional weight [32, 1, 5, 5]
- [Solved] RuntimeError: unexpected EOF, expected 73963 more bytes. The file might be corrupted.
- [Solved] bushi RuntimeError: version_ <= kMaxSupportedFileFormatVersion INTERNAL ASSERT FAILED at /pytorch/caffe2/s
- RuntimeError: CUDA error: an illegal memory access was encountered
- [Solved] RuntimeError: function ALSQPlusBackward returned a gradient different than None at position 3, but t
- [Solved] RuntimeError: Error(s) in loading state_dict for Net:
- [Solved] RuntimeError: expected scalar type Long but found Float
- [Solved] RuntimeError: ProcessGroupNCCL is only supported with GPUs, no GPUs found
- Python custom convolution kernel weight parameters
- [Solved] RuntimeError: cuda runtime error (100) : no CUDA-capable device is detected at
- Pytorch Loading model error: RuntimeError: Error(s) in loading state_dict for Model: Missing key(s) in state_dict
- Pytorch Error: RuntimeError: value cannot be converted to type float without overflow: (0.00655336,-0.00