I’m doing semantic segmentation of 3D tensors. I’m using a standard 3D UNet and DiceLoss()/BCELoss(). I’m using a standard IoU (Intersection over Union) measure to calculate the accuracy/error of the network.
def dice_error(input, target):
    _, result_ = input.max(1)
    result_ = torch.squeeze(result_)
    if input.is_cuda:
        result = torch.cuda.FloatTensor(result_.size())
        target_ = torch.cuda.FloatTensor(target.size())
    else:
        result = torch.FloatTensor(result_.size())
        target_ = torch.FloatTensor(target.size())
    result.copy_(result_.data)
    target_.copy_(target.data)
    target = torch.squeeze(target_)
    intersect = torch.dot(result.view(-1), target.view(-1))

    result_sum = torch.sum(result)
    target_sum = torch.sum(target)
    union = result_sum + target_sum + 2*eps
    IoU = intersect / union
    return 2*IoU

This function continues to return a value of 0, when given the network output and target tensor, both of the shape [1,1,32,128,128]. The target tensor has 0 for background and 1 for points of interest. So the function should find somke interset eventually. But even after many thousand iterations the error returned is 0, although the loss decreases.
Is there any reason I am not getting any actual value and although the loss is decreasing, there is still no intersection between the network output and target??
Thanks