I’m using a loss function available in PyTorch, however I get the following warning. I’m not sure what I would need to change to ensure they have the same size. I can’t find any reference of this error happening in fastai that proposes a solution to this.
/home/bob/anaconda3/envs/fastai/lib/python3.7/site-packages/fastai/basic_train.py:30: UserWarning: Using a target size (torch.Size([32])) that is different to the input size (torch.Size([32, 1])). This will likely lead to incorrect results due to broadcasting. Please ensure they have the same size.
loss = loss_func(out, *yb)
I assume your problem is solved by now. For everyone else having the same problem, here’s my take on debugging:
Create your own loss-function that does something with the tensors (like printing them to a file) before returning the loss. My approach looks like this (with the example of MSELoss, but this should be applicable universally):