But ClassificationInterpretation of the learner object will fail:
RuntimeError: Expected object of backend CPU but got backend CUDA for argument #3 'weight'
However, if I use torch.FloatTensor instead of torch.cuda.FloatTensor for the weights, I will get the inverse error when trying to train the model (“expecting backend CUDA but got backend CPU”).
It’s also not entirely clear to me if I should set the loss function when I create the data object, the learner object, or both.
That’s an interesting bug. It comes from the fact we stack the predictions after passing them on the CPU in get_preds to avoid out of memory errors on the GPU. Not sure how to solve this but will look at it. In the meantime, you can change the loss function of the learner after training it (to force the weights on the CPU) by calling: learn.loss_func = ...
Thanks for confirming it, is there a reason why data does not simply takes loss_func from learner but need to have a separate loss_func attribute. What is the usage of loss_func for DataBunch without a Learner?
You are taking this the wrong way: data offers a default loss function to the learner that is suitable for this kind of target (cross entropy for classification, mse for regression…)
RuntimeError: Expected object of backend CPU but got backend CUDA for argument #2 ‘weight’
im trying to grab the activations from a vgg16_bn:
vgg_m = vgg16_bn(True).features.cuda().eval()
requires_grad(vgg_m, False)
vgg_m = nn.Sequential(*children(vgg_m)[:37])
i have an image and its tensor is of size:
torch.Size([3, 288, 288])
i get the error when i try to pass the tensor of the image through the model and havent been able to get passed it:
vgg_m(image_tensor[None])
I havent defined a loss function a loss function yet.
the final runtime error is coming from here:
torch\nn\modules\conv.py in forward(self, input)
318 def forward(self, input):
319 return F.conv2d(input, self.weight, self.bias, self.stride,
–> 320 self.padding, self.dilation, self.groups)