Danesh-A:

Is there a way to assign weights to dice loss? For example I want foreground predictions to have a higher impact since it is rarer in a dataset. Im having issues where the model simply predicts background for every image after some training time.



You can give higher weight to classes by pretending the pixels where these are the ground truth are there multiple times (i.e. TP and FN are multiplied and also the total number of pixels is adjusted).
So if you have very few “interesting” pixels in a large number of uninteresting ones, you essentially have a heavily imbalanced problem. In my experience, balancing the training data might work even better than applying weights to the losses. When training the U-Net in our book in chapter 13, we take care that we have enough slices with nodules fed into the U-Net. A very brief discussion is in section 13.5.5 (Designing our training and validation data).

Best regards
Thomas