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] Using summary to View network parameters Error: RuntimeError: Input type (torch.cuda.FloatTensor)
- Pytorch torch.cuda.FloatTensor Error: RuntimeError: one of the variables needed for gradient computation has…
- Python RuntimeError: Expected 4-dimensional input for 4-dimensional weight [32, 1, 5, 5]
- [Solved] RuntimeError: Numpy is not available (Associated Torch or Tensorflow)
- RuntimeError: Failed to register operator torchvision::_new_empty_tensor_op. +torch&torchversion Version Matching
- [Solved] RuntimeError: cuda runtime error (100) : no CUDA-capable device is detected at
- [Solved] RuntimeError: expected scalar type Long but found Float
- Pytorch Error: RuntimeError: value cannot be converted to type float without overflow: (0.00655336,-0.00
- [Solved] Pytorch Error: RuntimeError: expected scalar type Double but found Float
- [Solved] Torch Build Module Error: NotImplementedError
- Python: Torch.nn.functional.normalize() Function
- Here is the difference and connection of Torch. View (), Transpose (), and Permute ()
- torch.nn.functional.normalize() Function Interpretation
- [Solved] Backtrader_plotting Error: RuntimeError: Unexpected data type
- Pytorch Error: runtimeerror: expected scalar type double but found float
- How to Solve Pychart configuration import torch error
- [Solved] Pytorch-geometric Error: No module named torch_sparse
- RuntimeError: CUDA error: an illegal memory access was encountered
- [Solved] RuntimeError: cuda runtime error (801) : operation not supported at