pytorch-summary
pytorch-summary copied to clipboard
model.cuda() needs to be called for summary
The code or the documentation should have a check/notice about having to call model.cuda()
summary(D, (3, 32, 32))
RuntimeError: Input type (torch.cuda.FloatTensor) and weight type (torch.FloatTensor) should be the same
But this works ok:
summary(D.cuda(), (3, 32, 32))
try it summary(D, (3, 32, 32), device="cpu")
How and where do you fix this? I added:
network = Network()
network.cuda()
And it says the error is on:
19 # (2) 1st hidden conv layer
---> 20 t = self.conv1(t)**
21 t = F.relu(t)
22 t = F.max_pool2d(t, kernel_size=3, stride=1)
...
RuntimeError: Input type (torch.FloatTensor) and weight type (torch.cuda.FloatTensor) should be the same
hi @joehoeller , did you manage to fix this ? I'm having the same problem just now.
@Dicko87 yes check my solutions/examples here, you’ll have to do it in various parts of the code:
- https://github.com/joehoeller/Computer-Vision-Facial-Key-Point-Detection/blob/master/app/facial-keypoint-detection/2.%20Define%20the%20Network%20Architecture.ipynb
See blocks [3], [9], [12], [14], in following order:
device = torch.device('cuda:0' if torch.cuda.is_available() else 'cpu')
net = Net().to(device)
# convert images to CUDA Tensors
images = images.type(torch.cuda.FloatTensor)
key_pts = key_pts.type(torch.cuda.FloatTensor)
Converting back to CPU from GPU:
image = image.cpu().numpy() # convert to numpy array from a Tensor
#images = images.to(device)
images = images.type(torch.cuda.FloatTensor)
- https://github.com/joehoeller/Computer-Vision-Facial-Key-Point-Detection/blob/master/app/unit_tests/CPU-GPU-Support.ipynb