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

handle zero denominator

parent 118379de
......@@ -100,8 +100,15 @@ def fmeasure_deft2018(model, loader, classes, device):
fp += torch.sum(~expected_bin & predicted_bin).item()
fn += torch.sum(expected_bin & ~predicted_bin).item()
recall = tp / (tp + fn)
precision = tp / (tp + fp)
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)
return tp, fp, fn, recall, precision, fm
......@@ -138,8 +145,15 @@ 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()
recall = tp / (tp + fn)
precision = tp / (tp + fp)
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)
return tp, fp, fn, recall, precision, fm
......@@ -177,8 +191,15 @@ def fmeasure_deft2018_t2(model, loader, classes, device):
fp += torch.sum(~expected_bin & predicted_bin).item()
fn += torch.sum(expected_bin & ~predicted_bin).item()
recall = tp / (tp + fn)
precision = tp / (tp + fp)
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)
return tp, fp, fn, recall, precision, fm
Markdown is supported
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