diff --git a/bob/ip/binseg/utils/FreeMono.ttf b/bob/ip/binseg/utils/FreeMono.ttf new file mode 100644 index 0000000000000000000000000000000000000000..7485f9e4c84d5a372c81e11df2cd9f5e2eb2064a Binary files /dev/null and b/bob/ip/binseg/utils/FreeMono.ttf differ diff --git a/bob/ip/binseg/utils/plot.py b/bob/ip/binseg/utils/plot.py index 594b97f06f2391c2524104f74d751b28a6ffa7db..f69df6e0473f6f4e8149354d78741ff98a2c809a 100644 --- a/bob/ip/binseg/utils/plot.py +++ b/bob/ip/binseg/utils/plot.py @@ -6,7 +6,7 @@ import os import csv import pandas as pd import PIL -from PIL import Image +from PIL import Image,ImageFont, ImageDraw import torchvision.transforms.functional as VF import torch @@ -198,10 +198,10 @@ def plot_overview(outputfolders,title): def metricsviz(dataset ,output_path - ,tp_color= (128,128,128) - ,fp_color = (70, 240, 240) - ,fn_color = (245, 130, 48) - ): + ,tp_color= (0,255,0) # (128,128,128) Gray + ,fp_color = (0, 0, 255) # (70, 240, 240) Cyan + ,fn_color = (255, 0, 0) # (245, 130, 48) Orange + ,overlayed=True): """ Visualizes true positives, false positives and false negatives Default colors TP: Gray, FP: Cyan, FN: Orange @@ -253,6 +253,16 @@ def metricsviz(dataset # paste together tp_pil_colored.paste(fp_pil_colored,mask=fp_pil) tp_pil_colored.paste(fn_pil_colored,mask=fn_pil) + + if overlayed: + tp_pil_colored = PIL.Image.blend(img, tp_pil_colored, 0.4) + img_metrics = pd.read_csv(os.path.join(output_path,'results',name+'.csv')) + f1 = img_metrics[' f1_score'].max() + # add f1-score + fnt_size = tp_pil_colored.size[1]//25 + draw = ImageDraw.Draw(tp_pil_colored) + fnt = ImageFont.truetype('FreeMono.ttf', fnt_size) + draw.text((0, 0),"F1: {:.4f}".format(f1),(255,255,255),font=fnt) # save to disk overlayed_path = os.path.join(output_path,'tpfnfpviz') @@ -277,8 +287,8 @@ def overlay(dataset, output_path): gt = sample[2].byte() # byte tensor # read metrics - metrics = pd.read_csv(os.path.join(output_path,'results','Metrics.csv')) - optimal_threshold = metrics['threshold'][metrics['f1_score'].idxmax()] + #metrics = pd.read_csv(os.path.join(output_path,'results',name+'.csv')) + #f1 = metrics[' f1_score'].max() # read probability output pred = Image.open(os.path.join(output_path,'images',name)) @@ -286,6 +296,11 @@ def overlay(dataset, output_path): pred_green = PIL.ImageOps.colorize(pred, (0,0,0), (0,255,0)) overlayed = PIL.Image.blend(img, pred_green, 0.4) + # add f1-score + #fnt_size = overlayed.size[1]//25 + #draw = ImageDraw.Draw(overlayed) + #fnt = ImageFont.truetype('FreeMono.ttf', fnt_size) + #draw.text((0, 0),"F1: {:.4f}".format(f1),(255,255,255),font=fnt) # save to disk overlayed_path = os.path.join(output_path,'overlayed') if not os.path.exists(overlayed_path): os.makedirs(overlayed_path) diff --git a/doc/covdresults.rst b/doc/covdresults.rst index 9148f1ba2661d6ebdb4580b8fb6ea3f02c7fd3f1..680002d3c2975a454a6a6595de1af7b142ab41a4 100644 --- a/doc/covdresults.rst +++ b/doc/covdresults.rst @@ -11,27 +11,27 @@ F1 Scores F1 score together with standard deviation across test images. -+-------------------+--------+-----------------+---------+ -| F1 score | DRIU | DRIU BN | M2U-Net | -+-------------------+--------+-----------------+---------+ -| COVD-DRIVE | 0.7896 | 0.8000 (0.0182) | 0.7906 | -+-------------------+--------+-----------------+---------+ -| COVD-DRIVE SSL | 0.7870 | 0.8020 (0.0179) | 0.7938 | -+-------------------+--------+-----------------+---------+ -| COVD-STARE | 0.7979 | 0.8129 (0.0986) | 0.8120 | -+-------------------+--------+-----------------+---------+ -| COVD-STARE SSL | 0.8062 | 0.8221 (0.0784) | 0.8222 | -+-------------------+--------+-----------------+---------+ -| COVD-CHASEDB1 | 0.7979 | 0.7923 (0.0240) | 0.7898 | -+-------------------+--------+-----------------+---------+ -| COVD-CHASEDB1 SSL | 0.7976 | 0.7992 (0.0235) | 0.8000 | -+-------------------+--------+-----------------+---------+ -| COVD-HRF | 0.8013 | 0.8027 (0.0452) | 0.8036 | -+-------------------+--------+-----------------+---------+ -| COVD-HRF SSL | 0.8002 | | 0.7999 | -+-------------------+--------+-----------------+---------+ -| COVD-IOSTAR | 0.7934 | 0.7763 (0.0311) | 0.7953 | -+-------------------+--------+-----------------+---------+ -| COVD-IOSTAR SSL | 0.7995 | 0.7904 (0.0215) | 0.7868 | -+-------------------+--------+-----------------+---------+ ++-------------------+-----------------+-----------------+-----------------+ +| F1 score | DRIU | DRIU BN | M2U-Net | ++-------------------+-----------------+-----------------+-----------------+ +| COVD-DRIVE | 0.7896 (0.0178) | 0.8000 (0.0182) | 0.7906 (0.0179) | ++-------------------+-----------------+-----------------+-----------------+ +| COVD-DRIVE SSL | 0.7870 (0.0176) | 0.8020 (0.0179) | 0.7938 (0.0142) | ++-------------------+-----------------+-----------------+-----------------+ +| COVD-STARE | 0.7979 (0.1254) | 0.8129 (0.0986) | 0.8120 (0.0457) | ++-------------------+-----------------+-----------------+-----------------+ +| COVD-STARE SSL | 0.8062 (0.1033) | 0.8221 (0.0784) | 0.8222 (0.0441) | ++-------------------+-----------------+-----------------+-----------------+ +| COVD-CHASEDB1 | 0.7979 (0.0284) | 0.7923 (0.0240) | 0.7898 (0.0236) | ++-------------------+-----------------+-----------------+-----------------+ +| COVD-CHASEDB1 SSL | 0.7976 (0.0242) | 0.7992 (0.0235) | 0.8000 (0.0268) | ++-------------------+-----------------+-----------------+-----------------+ +| COVD-HRF | 0.8013 (0.0436) | 0.8027 (0.0452) | 0.8036 (0.0442) | ++-------------------+-----------------+-----------------+-----------------+ +| COVD-HRF SSL | 0.8002 (0.0421) | | 0.7987 (0.0436) | ++-------------------+-----------------+-----------------+-----------------+ +| COVD-IOSTAR | 0.7934 (0.0206) | 0.7763 (0.0311) | 0.7953 (0.0152) | ++-------------------+-----------------+-----------------+-----------------+ +| COVD-IOSTAR SSL | 0.7995 (0.0174) | 0.7904 (0.0215) | 0.7868 (0.0182) | ++-------------------+-----------------+-----------------+-----------------+