Class Imbalance in Pytorch CNN Segmentation

I have a model for segmentation using MRI images. Here is a graph of the dice loss during training. There are constant steps where the loss is equal to 1 where i am assuming the model is predicting the image to be all background. I am not sure how to improve these results. Any suggestions?