#import dataset as ds #import learning_dataset from labeling.exps import results_dirs as rd from PIL import Image, ImageFont, ImageDraw import glob """ Makes plots self """ def gray2rgb(im): return (color.gray2rgb(im) * 255).astype(np.uint8) file_out = os.path.join(rd.root_dir, 'plots_results') placehold = utls.imread(os.path.join(file_out, 'placeholder.png')) n_sets_per_type = 2 dfs = [] # Self-learning ims = [] ksp = [] vilar = [] g2s = [] mic17 = [] wtp = [] #for key in rd.res_dirs_dict_ksp.keys(): # Types for key in rd.types: # Types
# Make images/gts/gaze-point confs = rd.confs_dict_ksp[key][dset] conf = confs[0] dataset = ld.LearningDataset(conf) gt = dataset.gt ksp_mat = np.load( os.path.join(rd.root_dir, rd.res_dirs_dict_ksp[key][dset][gset], 'results.npz'))['ksp_scores_mat'] for f in range(len(conf.frameFileNames)): cont_gt = segmentation.find_boundaries(gt[..., f], mode='thick') idx_cont_gt = np.where(cont_gt) im = utls.imread(conf.frameFileNames[f]) im[idx_cont_gt[0], idx_cont_gt[1], :] = (255, 0, 0) myGaze_fg = utls.readCsv( os.path.join(conf.root_path, conf.ds_dir, conf.locs_dir, conf.csvFileName_fg)) im = csv.draw2DPoint(myGaze_fg, f, im, radius=7) ksp_ = (cmap(ksp_mat[..., f] * 255)[..., 0:3] * 255).astype( np.uint8) im = np.concatenate((im, ksp_), axis=0) ims.append(im) # Save frames if (not os.path.exists(path_out)):
for dir_ in rd.res_dirs_dict_mic17[key]: print('Scoring:') print(dir_) path_ = os.path.join(rd.root_dir, dir_) # Get config conf = cfg.load_and_convert(os.path.join(path_, 'cfg.yml')) conf.root_path = rd.root_dir conf.dataOutDir = os.path.join(rd.root_dir, conf.dataOutDir) l_dataset = learning_dataset.LearningDataset(conf, pos_thr=0.5) gt = l_dataset.gt res_files = sorted(glob.glob(os.path.join(path_, '*.png'))) preds = np.asarray([utls.imread(f) for f in res_files]) preds = np.mean(preds, axis=3) preds = preds.transpose((1, 2, 0)) pr, rc, _ = precision_recall_curve(gt.ravel(), preds.ravel()) all_f1s = 2 * (pr * rc) / (pr + rc) max_f1 = np.nanmax(all_f1s) max_pr = pr[np.argmax(all_f1s)] max_rc = rc[np.argmax(all_f1s)] file_out = os.path.join(path_, 'scores.csv') C = pd.Index(["F1", "PR", "RC"], name="columns") I = pd.Index(['EEL'], name="Methods") data = np.asarray([max_f1, max_pr, max_rc]).reshape(1, 3) df = pd.DataFrame(data=data, index=I, columns=C) print('Saving F1 score')
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 ims = [utls.imread(f) for f in conf.frameFileNames] cont_gts = [segmentation.find_boundaries(gt[..., i]) for i in range(gt.shape[-1])] idx_cont_gts = [np.where(g) for g in cont_gts] path_csv = os.path.join(conf.root_path, conf.ds_dir, conf.locs_dir, conf.csvFileName_fg) labels = dataset.get_labels() dataset.load_labels_contours_if_not_exist() label_conts = dataset.labelContourMask locs = utls.readCsv(path_csv) for i in range(len(ims)): ims[i][idx_cont_gts[i][0], idx_cont_gts[i][1], :] = (255, 0, 0)
ksp = np.load(file_ksp)['ksp_scores_mat'] ksp = [ cmap((ksp[..., i] * 255).astype(np.uint8))[..., 0:3] for i in range(ksp.shape[-1]) ] with progressbar.ProgressBar(maxval=len(conf.frameFileNames)) as bar: for f, i in zip(conf.frameFileNames, range(len(conf.frameFileNames))): bar.update(i) # Image cont_gt = segmentation.find_boundaries(gt[..., i], mode='thick') idx_cont_gt = np.where(cont_gt) im = utls.imread(f) im[idx_cont_gt[0], idx_cont_gt[1], :] = (255, 0, 0) locs2d = csv.readCsv( os.path.join(conf.root_path, conf.ds_dir, conf.locs_dir, conf.csvFileName_fg)) im = csv.draw2DPoint(locs2d, i, im, radius=7) im = im / 255 im = np.concatenate((im, ksp[i].copy()), axis=1) im = (im * 255).astype(np.uint8) io.imsave( os.path.join(dir_out, 'frame_{:04d}.png'.format(i + 1)), im)