Hi,
There have been previous discussions on weighted BCELoss here but none of them give a clear answer how to actually apply the weight tensor and what will it contain?
I’m doing binary segmentation where the output is either foreground or background (1 and 0). But my dataset is highly imbalanced and there is way more background than foreground. (To be exact there is 95 times more background pixels than foreground). So I want to penalize the background by multiplying it with a small number.
I see that BCELoss has a weight parameter: https://pytorch.org/docs/stable/nn.html 88 which according to docs is to be of the size nbatch.
So if I have a batch of size 1, would the eight tensor be of size 1 as well? wont that just be a single float value?
ive read the discussion here: Binary cross entropy weights 83 but that does not answer what the weight tensor would look like for a batch size of 1?
Sorry if I’m rambling but I can’t seem to find anywhere how to use the weight parameter properly. If my output and label tensors are of the size [1, 1, 60, 40, 40] how would I make my weight parameter to penalize the background class (0)?