import os from os.path import join from merge_predictions import get_image_dict, apply_merge from froc_by_pranjal import calc_froc_from_dict, pretty_print_fps import numpy as np import matplotlib.pyplot as plt OUT_DIR = 'euro_results_auto' numbers_dir = os.path.join(OUT_DIR, 'numbers') graphs_dir = os.path.join(OUT_DIR, 'graphs') BASE_FOLDER = '../bilateral_new/MammoDatasets' MIN_CLIP_FPI = 0.02 def plot_froc(input_files, save_file, TITLE = 'FRCNN vs BILATERAL FROC', SHOW = False, CLIP_FPI = 1.2): for file in input_files: lines = open(file).readlines() x = np.array([float(line.split()[0]) for line in lines]) y = np.array([float(line.split()[1]) for line in lines]) y = y[x0.85,preds)) # keep preds lower than 0.6 confidence return preds def c3_manp(preds): preds = list(filter(lambda x: x[0]>0.85,preds)) # keep preds lower than 0.6 confidence return preds def t1_manp(preds): preds = list(filter(lambda x: x[0]>0.6,preds)) # keep preds lower than 0.6 confidence return preds t2_manp = t1_manp mp_dict = { f'{dset[1]}_C2' : c2_manp, f'{dset[1]}_C3' : c3_manp, f'{dset[1]}_T1' : t1_manp, f'{dset[1]}_T2' : t2_manp, f'{dset[1]}_C4' : c3_manp } image_dict = get_image_dict(dataset_paths, allowed = allowed, USE_ACR = False, acr_cat = None, mp_dict = mp_dict) image_dict = apply_merge(image_dict, METHOD = 'nms', weights= weights, conf_type='absent_model_aware_avg') senses, fps = calc_froc_from_dict(image_dict, fps_req = [0.025,0.05,0.1,0.15,0.2,0.3,1.], save_to = os.path.join(num_dir, f'{title}.txt')) # Lets plot now GRAPHS = [ ('Bilateral','Baseline'), ('Contrast','Baseline'), ('Threshold','Baseline'), ('Proposed','Baseline'), ('Proposed', 'Bilateral'), ('Proposed', 'Contrast'), ('Proposed', 'Threshold'), ] # Now handle the directories graph_dir = os.path.join(graphs_dir, dset[1], test_split) os.makedirs(graph_dir, exist_ok=True) for graph in GRAPHS: if graph[0] not in CONFIGS or graph[1] not in CONFIGS: continue file_name1 = f'{CONFIGS[graph[0]][0]}.txt' file_name2 = f'{CONFIGS[graph[1]][0]}.txt' title1 = CONFIGS[graph[0]][0] title2 = CONFIGS[graph[1]][0] plot_froc({ join(num_dir, file_name1): title1, join(num_dir, file_name2) : title2, }, join(graph_dir,f'{title1}_vs_{title2}.png'),f'{title1} vs {title2} FROC', CLIP_FPI = 0.3 if dset[0] == 'IRCHVal' else 0.8)