It is possible to compute IOU and Dice loss with more than two classes, but not with this implementation. Basically, you would compute the ratios for each class (except the background) individually before averaging them (weighted or not).