Skip to content
Snippets Groups Projects
Commit 7e544ab4 authored by Tim Laibacher's avatar Tim Laibacher
Browse files

Add more f1 to viz

parent 08e191d7
No related branches found
No related tags found
No related merge requests found
Pipeline #31864 passed
File added
...@@ -6,7 +6,7 @@ import os ...@@ -6,7 +6,7 @@ import os
import csv import csv
import pandas as pd import pandas as pd
import PIL import PIL
from PIL import Image from PIL import Image,ImageFont, ImageDraw
import torchvision.transforms.functional as VF import torchvision.transforms.functional as VF
import torch import torch
...@@ -198,10 +198,10 @@ def plot_overview(outputfolders,title): ...@@ -198,10 +198,10 @@ def plot_overview(outputfolders,title):
def metricsviz(dataset def metricsviz(dataset
,output_path ,output_path
,tp_color= (128,128,128) ,tp_color= (0,255,0) # (128,128,128) Gray
,fp_color = (70, 240, 240) ,fp_color = (0, 0, 255) # (70, 240, 240) Cyan
,fn_color = (245, 130, 48) ,fn_color = (255, 0, 0) # (245, 130, 48) Orange
): ,overlayed=True):
""" Visualizes true positives, false positives and false negatives """ Visualizes true positives, false positives and false negatives
Default colors TP: Gray, FP: Cyan, FN: Orange Default colors TP: Gray, FP: Cyan, FN: Orange
...@@ -253,6 +253,16 @@ def metricsviz(dataset ...@@ -253,6 +253,16 @@ def metricsviz(dataset
# paste together # paste together
tp_pil_colored.paste(fp_pil_colored,mask=fp_pil) tp_pil_colored.paste(fp_pil_colored,mask=fp_pil)
tp_pil_colored.paste(fn_pil_colored,mask=fn_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 # save to disk
overlayed_path = os.path.join(output_path,'tpfnfpviz') overlayed_path = os.path.join(output_path,'tpfnfpviz')
...@@ -277,8 +287,8 @@ def overlay(dataset, output_path): ...@@ -277,8 +287,8 @@ def overlay(dataset, output_path):
gt = sample[2].byte() # byte tensor gt = sample[2].byte() # byte tensor
# read metrics # read metrics
metrics = pd.read_csv(os.path.join(output_path,'results','Metrics.csv')) #metrics = pd.read_csv(os.path.join(output_path,'results',name+'.csv'))
optimal_threshold = metrics['threshold'][metrics['f1_score'].idxmax()] #f1 = metrics[' f1_score'].max()
# read probability output # read probability output
pred = Image.open(os.path.join(output_path,'images',name)) pred = Image.open(os.path.join(output_path,'images',name))
...@@ -286,6 +296,11 @@ def overlay(dataset, output_path): ...@@ -286,6 +296,11 @@ def overlay(dataset, output_path):
pred_green = PIL.ImageOps.colorize(pred, (0,0,0), (0,255,0)) pred_green = PIL.ImageOps.colorize(pred, (0,0,0), (0,255,0))
overlayed = PIL.Image.blend(img, pred_green, 0.4) 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 # save to disk
overlayed_path = os.path.join(output_path,'overlayed') overlayed_path = os.path.join(output_path,'overlayed')
if not os.path.exists(overlayed_path): os.makedirs(overlayed_path) if not os.path.exists(overlayed_path): os.makedirs(overlayed_path)
......
...@@ -11,27 +11,27 @@ F1 Scores ...@@ -11,27 +11,27 @@ F1 Scores
F1 score together with standard deviation across test images. F1 score together with standard deviation across test images.
+-------------------+--------+-----------------+---------+ +-------------------+-----------------+-----------------+-----------------+
| F1 score | DRIU | DRIU BN | M2U-Net | | F1 score | DRIU | DRIU BN | M2U-Net |
+-------------------+--------+-----------------+---------+ +-------------------+-----------------+-----------------+-----------------+
| COVD-DRIVE | 0.7896 | 0.8000 (0.0182) | 0.7906 | | COVD-DRIVE | 0.7896 (0.0178) | 0.8000 (0.0182) | 0.7906 (0.0179) |
+-------------------+--------+-----------------+---------+ +-------------------+-----------------+-----------------+-----------------+
| COVD-DRIVE SSL | 0.7870 | 0.8020 (0.0179) | 0.7938 | | COVD-DRIVE SSL | 0.7870 (0.0176) | 0.8020 (0.0179) | 0.7938 (0.0142) |
+-------------------+--------+-----------------+---------+ +-------------------+-----------------+-----------------+-----------------+
| COVD-STARE | 0.7979 | 0.8129 (0.0986) | 0.8120 | | COVD-STARE | 0.7979 (0.1254) | 0.8129 (0.0986) | 0.8120 (0.0457) |
+-------------------+--------+-----------------+---------+ +-------------------+-----------------+-----------------+-----------------+
| COVD-STARE SSL | 0.8062 | 0.8221 (0.0784) | 0.8222 | | COVD-STARE SSL | 0.8062 (0.1033) | 0.8221 (0.0784) | 0.8222 (0.0441) |
+-------------------+--------+-----------------+---------+ +-------------------+-----------------+-----------------+-----------------+
| COVD-CHASEDB1 | 0.7979 | 0.7923 (0.0240) | 0.7898 | | COVD-CHASEDB1 | 0.7979 (0.0284) | 0.7923 (0.0240) | 0.7898 (0.0236) |
+-------------------+--------+-----------------+---------+ +-------------------+-----------------+-----------------+-----------------+
| COVD-CHASEDB1 SSL | 0.7976 | 0.7992 (0.0235) | 0.8000 | | COVD-CHASEDB1 SSL | 0.7976 (0.0242) | 0.7992 (0.0235) | 0.8000 (0.0268) |
+-------------------+--------+-----------------+---------+ +-------------------+-----------------+-----------------+-----------------+
| COVD-HRF | 0.8013 | 0.8027 (0.0452) | 0.8036 | | COVD-HRF | 0.8013 (0.0436) | 0.8027 (0.0452) | 0.8036 (0.0442) |
+-------------------+--------+-----------------+---------+ +-------------------+-----------------+-----------------+-----------------+
| COVD-HRF SSL | 0.8002 | | 0.7999 | | COVD-HRF SSL | 0.8002 (0.0421) | | 0.7987 (0.0436) |
+-------------------+--------+-----------------+---------+ +-------------------+-----------------+-----------------+-----------------+
| COVD-IOSTAR | 0.7934 | 0.7763 (0.0311) | 0.7953 | | COVD-IOSTAR | 0.7934 (0.0206) | 0.7763 (0.0311) | 0.7953 (0.0152) |
+-------------------+--------+-----------------+---------+ +-------------------+-----------------+-----------------+-----------------+
| COVD-IOSTAR SSL | 0.7995 | 0.7904 (0.0215) | 0.7868 | | COVD-IOSTAR SSL | 0.7995 (0.0174) | 0.7904 (0.0215) | 0.7868 (0.0182) |
+-------------------+--------+-----------------+---------+ +-------------------+-----------------+-----------------+-----------------+
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment