When I train a learner learn = unet_learner(data ,models.resnet50, metrics=metrics) with the default Loss function (FlattenedLoss), I have no error and the model trains fine. However, when I try to use another loss function, (e.g. learn.loss_func = nn.BCEWithLogitsLoss() ), I get the following error:
ValueError: Target size (torch.Size([2, 1, 64, 128])) must be the same as input size (torch.Size([2, 2, 64, 128]))
@rpdunne did you find a solution for this?@juvian i’m in a similar position, i think its because im trying to use the original camvid notebook modified for a binary classification problem. It’s working ok in terms of initial results however i wanted to change my loss function and now im running into a similar headache.
Should i be trying to change the "target = " part of the code or addressing this elsewhere?
Thanks @juvian - out of the box sounds much more in line with what i want to do. My next stupid question is where are you setting the classes to 2? I thought i already had done that implicitly by only having two classes in the code
I also found another function to try and debug from below, now i’m wondering is this a case that i’m not passing the masks in too? Or that my masks are greyscaled and it’s expecting RGB?
Actually, it is possible to load gray valued images as 3-channel images by duplicating the one channel. This way pre-trained image net can be used (and also enhances results).