torch.nn.BCELoss documentation, it says that the
weight parameter, if given, has to be a Tensor of size nbatch. However, when I use weight of size nbatch, I got the following error:
The size of tensor a (200) must match the size of tensor b (36) at non-singleton dimension 3.
My tensors sizes are:
input = (36, 1, 200, 200)
target = (36, 1, 200, 200)
weight = (36,)
What I want to do is to have weights 0 or 1 in the weight array in order to ignore samples (since we don’t have ìgnore_index` parameter in the binary cross entropy loss) from the batch where we have 0 and include them where we have 1. What am I missing ?
Side note: I know I can use
NLLLoss and build a one-hot encoding for it, however, my problem is binary and for some other reasons isn’t feasible to do that.