Utility functions for deepflash2
test_eq(dice_score(mask, mask), 1)
test_eq(dice_score(mask, empty_mask), 0)
# Todo: add multiclass tests https://scikit-learn.org/stable/modules/generated/sklearn.metrics.jaccard_score.html
tst_lbl_a = label_mask(mask, min_pixel=0)
test_eq(tst_lbl_a.max(), 2)
test_eq(tst_lbl_a.min(), 0)
plt.imshow(tst_lbl_a);
tst_lbl_b = label_mask(mask, min_pixel=150)
test_eq(tst_lbl_b.max(), 1)
plt.imshow(tst_lbl_b);
ap, tp, fp, fn = get_instance_segmentation_metrics(mask, mask, is_binary=True)
test_eq(len(ap),10)
test_eq(tp[0],2)
ap, tp, fp, fn = get_instance_segmentation_metrics(mask, empty_mask, is_binary=True, thresholds=[.5])
test_eq(len(ap),1)
test_eq(fn[0],2)
path = export_roi_set(mask)
path.unlink()
test_eq(calc_iterations(100, 8, 4), 50)
def save_mask(mask, path, filetype='.png'):
mask = mask.astype(np.uint8) if np.max(mask)>1 else (mask*255).astype(np.uint8)
imageio.imsave(path.with_suffix(filetype), mask)
def save_unc(unc, path, filetype='.png'):
unc = (unc/unc.max()*255).astype(np.uint8)
imageio.imsave(path.with_suffix(filetype), unc)