""" Calculate F1 score for ratio of positive pixels in superpixels """ save_path = os.path.join(rd.root_dir, 'plots_results', 'sp_thr_f1s.npz') ratios = [0.25, 0.5, 0.75, 1.0] res = dict() # Self-learning for key in rd.types: res[key] = dict() for seq in rd.res_dirs_dict_ksp[key][0]: f1s = list() cfg_ = cfg.load_and_convert(os.path.join(rd.root_dir, seq, 'cfg.yml')) dset = learning_dataset.LearningDataset(cfg_) gt = dset.gt sp_gt = dset.make_y_map_true(gt) for r in ratios: f1 = f1_score(gt.ravel(), (sp_gt >= r).ravel()) f1s.append(f1) res[key][cfg_.ds_dir] = f1s data = {'res': res, 'ratios': ratios} np.savez(save_path, **data)
splits = utls.splitall(path_) return os.path.join(root_dir, *splits[prefix_remove:]) for key in rd.types: #for key in ['Brain', 'Cochlea', 'Slitlamp']: for dir_ in rd.res_dirs_dict_wtp[key]: print('Scoring:') print(dir_) # Get h5 file path_ = os.path.join(rd.root_dir, dir_) # Get config conf = cfg.load_and_convert(os.path.join(path_, 'cfg.yml')) conf.precomp_desc_path = adjust_path(rd.root_dir, conf.precomp_desc_path) conf.frameFileNames = [adjust_path(rd.root_dir, f) for f in conf.frameFileNames] conf.root_path = rd.root_dir conf.dataOutDir = adjust_path(rd.root_dir, conf.dataOutDir) l_dataset = learning_dataset.LearningDataset(conf, pos_thr=0.5) gt = l_dataset.gt file_ = os.path.join(path_, 'nn_objectness_g1', 'predictions.h5') f = h5py.File(file_, 'r') a_group_key = list(f.keys())[0]
#dict_ = pickle.load(open('g_for_dict', 'rb')) #dict_['forward_tracklets'] #dict_['forward_sets'] #paths = utls.tracklet_set_to_sp_path(dict_['forward_tracklets'], # dict_['forward_sets'], # iter_=0) root_dir = os.path.join('/home/laurent.lejeune/medical-labeling/', 'Dataset00/results') #exp_dir = '2018-05-31_09-55-01_exp' #exp_dir = '2018-05-31_09-55-40_exp' exp_dir = '2018-05-31_09-56-40_exp' conf = cfg.load_and_convert(os.path.join(root_dir, exp_dir, 'cfg.yml')) pksp.main(conf) #dataset = learning_dataset.LearningDataset(conf) #labels = dataset.get_labels() #im = [utls.imread(f) for f in conf.frameFileNames] #res = np.load(os.path.join(dir_, 'results.npz')) #list_paths_back = res['list_paths_back'] #list_paths_for = res['list_paths_for'] #seeds = utls.list_paths_to_seeds(list_paths_for, # list_paths_back) #seeds += list(set([p.tolist() for p in list_paths_back[-1]])) #seeds += list(set([p.tolist() for p in list_paths_for[-1]]))
from matplotlib.backends.backend_agg import FigureCanvasAgg from scipy.ndimage.measurements import center_of_mass import copy """ Makes plots self """ def gray2rgb(im): return (color.gray2rgb(im)*255).astype(np.uint8) file_out = os.path.join(rd.root_dir, 'plots_results') dir_ = 'Dataset30/results/2018-06-01_14-22-56_for_paths' conf = cfg.load_and_convert(os.path.join(rd.root_dir, dir_, 'cfg.yml')) res = np.load(os.path.join(rd.root_dir, dir_, 'results.npz')) list_paths_back = res['list_paths_back'] list_paths_forw = res['list_paths_for'] color_sps = (0, 0, 255) ims = [] ksp = [] # Load config dataset = learning_dataset.LearningDataset(conf) gt = dataset.gt # Image
if (not os.path.exists(file_out)): print('{} doesnt exist. Creating.'.format(file_out)) os.mkdir(file_out) cmap = plt.get_cmap('viridis') for key in ['Slitlamp']: #for key in rd.types: # Types # Get first gaze-set of every dataset for i in [0]: #for i in range(4): #My model dir_ksp = os.path.join(rd.root_dir, rd.res_dirs_dict_ksp[key][i][0]) conf = cfg.load_and_convert(os.path.join(dir_ksp, 'cfg.yml')) print('Type: {}. Dset: {}'.format(key, conf.ds_dir)) # Load config dataset = learning_dataset.LearningDataset(conf) gt = dataset.gt exp_dir = '{}_{}'.format(key, i + 1) dir_out = os.path.join(file_out, exp_dir) if (not os.path.exists(dir_out)): print('{} doesnt exist. Creating.'.format(dir_out)) os.mkdir(dir_out) file_ksp = os.path.join(dir_ksp, 'results.npz')