Hey guys! Could you all help me with this issue?
“RuntimeError: Input type (torch.cuda.DoubleTensor) and weight type (torch.cuda.FloatTensor) should be the same”
I am using this function to initialize the weights:
if type(model) in [nn.Conv2d, nn.Linear]:
And I am using this code to submit an image to the CNN layers:
for inputs, labels in images_loader:
inputs = inputs.to(device)
labels = labels.to(device)
inputs = inputs.unsqueeze(0)
outputs = model(inputs)
As the error says, your inputs (likely) are double (aka float64) while your weights are float32 (which is the standard in GPU computing).
inputs = inputs.to(device, dtype=torch.float32)
will help, but you could also see whether you want to provide the data as 32 bit floats to start with.
Solved the problem, but I got another one:
“conv_transpose2d(): argument ‘stride’ must be tuple of ints, but found element of type float at pos 1”
Is this because the tensor elements are in float type?
The configuration of my CNN layers is in this layout:
nn.Conv2d(in_channels = 1, out_channels = 64, kernel_size = 3, stride = 1, padding = 1, dilation = 1),
nn.Conv2d(in_channels = 64, out_channels = 64, kernel_size = 3, stride = 2, padding = 1, dilation = 1),
nn.BatchNorm2d(num_features = 64),
I solved here ahahahaha
I was passing stride with float value
Thanks for the help