About precision and recall during training
Ghost0405 opened this issue · comments
鬼鬼 commented
Mahmoud El Hussieny commented
class EdgeAccuracy(nn.Module):
"""
Measures the accuracy of the edge map
"""
def __init__(self, threshold=0.5):
super(EdgeAccuracy, self).__init__()
self.threshold = threshold
def __call__(self, inputs, outputs):
labels = (inputs > self.threshold)
outputs = (outputs > self.threshold)
relevant = torch.sum(labels.float())
selected = torch.sum(outputs.float())
if relevant == 0 and selected == 0:
return torch.tensor(1), torch.tensor(1)
true_positive = ((outputs == labels) * labels).float()
recall = torch.sum(true_positive) / (relevant + 1e-8)
precision = torch.sum(true_positive) / (selected + 1e-8)
return precision, recall
according to this the relevant and selective must have a value greater than zero to get result. I thing the edge you have generated had values below threshold. make sure edges to have only values of 0 and 1