Setting indices to be ignored in new/custom segmentation losses

I’ve been experimenting with loss functions for semantic segmentation and seem to have hit a wall regarding this. In cross entropy and nll loss implementation, we can set a parameter to ignore a class value. How do we go about doing this for custom loss functions? What’s the prevailing technique?

Do you simply drop the ignore values? In my case, the ignore values are present for padding.

Appreciate any pointers.

You could mask the loss output by multiplying it with zeros for the ignored classes and ones for others.