I am trying to achieve the segmentation of the bone on the cross sectional area of MRI images with the Unet I found here. The label is a binary png image which I intend to compare to my prediction. For the frames, I wrote my own data loader for my DICOM MRI files. There is a class imbalance, since the bone is a small area on the image
I am using the following dice loss in keras
def DiceLoss(targets, inputs, smooth=1e-6):
#flatten label and prediction tensors inputs = K.flatten(inputs) targets = K.flatten(targets)
intersection = K.sum(K.dot(targets, inputs)) dice = (2*intersection + smooth) / (K.sum(targets) + K.sum(inputs) + smooth) return 1 - dice
I have seen it in kaggle among other similar implementations in Keras that I found out there.
But the DICE loss is always too small (10^-4) even though there is no overlap between the prediction and the label. Why is this? should I first convert my prediction to a binary mask? if so, How can I do this in keras? I tried to convert targets to a numpy array by doing targets.numpy()
and then apply a threshold, but it throws a "tensor does not have attribute numpy" error. Do you have any other idea?