Commit b1ab367f authored by Gaëtan Caillaut's avatar Gaëtan Caillaut
Browse files

handle zero denominator

parent 118379de
......@@ -100,7 +100,14 @@ def fmeasure_deft2018(model, loader, classes, device):
fp += torch.sum(~expected_bin & predicted_bin).item()
fn += torch.sum(expected_bin & ~predicted_bin).item()
if tp + fn == 0:
recall = 0
else:
recall = tp / (tp + fn)
if tp + fp == 0:
precision = 0
else:
precision = tp / (tp + fp)
fm = 2 * (recall * precision) / (recall + precision)
......@@ -138,7 +145,14 @@ def fmeasure_deft2018_t1(model, loader, device, truth_label=1):
fp += torch.sum(~expected_bin & predicted_bin).item()
fn += torch.sum(expected_bin & ~predicted_bin).item()
if tp + fn == 0:
recall = 0
else:
recall = tp / (tp + fn)
if tp + fp == 0:
precision = 0
else:
precision = tp / (tp + fp)
fm = 2 * (recall * precision) / (recall + precision)
......@@ -177,7 +191,14 @@ def fmeasure_deft2018_t2(model, loader, classes, device):
fp += torch.sum(~expected_bin & predicted_bin).item()
fn += torch.sum(expected_bin & ~predicted_bin).item()
if tp + fn == 0:
recall = 0
else:
recall = tp / (tp + fn)
if tp + fp == 0:
precision = 0
else:
precision = tp / (tp + fp)
fm = 2 * (recall * precision) / (recall + precision)
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment