ptrblck:

uction='none' while creating the loss function. Afterwards you could multiply this unreduced loss with a mask to set the missing losses to zero, and reduce it e.g. vi


Hi. I am doing exactly this for my application: calculating the unreduced loss and applying a mask to zero-out some of the values. The values I want to mask depend on the set of grount-truth labels, meaning that the masked values are different in each sample of a batch. Is calling .mean() on the masked tensor or should I somehow ignore the zero values when calculating the mean? I tried doing this
https://discuss.pytorch.org/t/use-tensor-mean-method-but-ignore-0-values/60170
but got worse results. Thanks!