MCPcopy Create free account
hub / github.com/SLDGroup/EMCAD / get_binary_metrics

Function get_binary_metrics

test_polyp.py:36–54  ·  view source on GitHub ↗
(pred, gt)

Source from the content-addressed store, hash-verified

34 return (intersection + smooth) / (union + smooth)
35
36def get_binary_metrics(pred, gt):
37 tp = (pred * gt).sum().item()
38 tn = ((1 - pred) * (1 - gt)).sum().item()
39 fp = (pred * (1 - gt)).sum().item()
40 fn = ((1 - pred) * gt).sum().item()
41
42 sensitivity = tp / (tp + fn + 1e-8)
43 specificity = tn / (tn + fp + 1e-8)
44 precision = tp / (tp + fp + 1e-8)
45
46 try:
47 if pred.sum() > 0 and gt.sum() > 0:
48 hd_val = hd95(pred.cpu().numpy(), gt.cpu().numpy())
49 else:
50 hd_val = 100.0
51 except:
52 hd_val = 100.0
53
54 return sensitivity, specificity, precision, hd_val
55
56def test(model, path, dataset, opt, save_base=None):
57 data_path = os.path.join(path, dataset)

Callers 1

testFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected