# IOU and dice_coef exceed 100% in multi task learning

Im doing a multi task learning for road and center line extraction (2 classes) I used IOU and dice_coef as a metrics :

def dice_coef(actual, predicted, eps=1e-3):

y_true_f = K.flatten(actual)
y_pred_f = K.flatten(predicted)
intersection = K.sum(y_true_f * y_pred_f)
return (2. * intersection + eps) / (K.sum(y_true_f) + K.sum(y_pred_f) + eps)

def iou(actual, predicted):

actual = K.flatten(actual)
predicted = K.flatten(predicted)
intersection = K.sum(actual * predicted)
union = K.sum(actual) + K.sum(predicted) - intersection
print(intersection, type(intersection))
print(union, type(union))
return 1. * intersection / union


I used Radam as an optimizer and weighted binary cross entropy as loss function, the IOU and Dice_coef for the second class(centerline) was more than 1, but for the first class (road)was within the normal range as shown here , the accuracy was within the normal range also for both classes.
I Found this discussion here and they mentioned that, should used an image dice not a batch dice, when i followed the same implementation of the image dice for IOU and dice_coef, nothing has changed still the metrics exceed 100%, my batch size =2, image size(224,224,3), my y_ture is between (0,1). but even with this strange result Ive got a good predictions for both classes and

I should mentioned that I used the same first implementation for the IOU and dice_coef. for single task and it worked perfectly. I dont know why Ive got this strange results, even when I used different implementation for the mentioned metrics.

Please any kind of help will be appreciated.