Пример #1
0
#for key in rd.res_dirs_dict_ksp.keys(): # Types
for key in rd.types:  # Types
    ims.append([])
    ksp.append([])
    vilar.append([])
    g2s.append([])
    mic17.append([])
    wtp.append([])

    dsets_to_plot = np.asarray(rd.best_dict_ksp[key][0:n_sets_per_type])
    for dset, gset in zip(dsets_to_plot[:, 0], dsets_to_plot[:, 1]):

        confs = [rd.confs_dict_ksp[key][dset][g] for g in range(5)]

        # Load config
        dataset = learning_dataset.LearningDataset(confs[0])
        gt = dataset.gt

        f = rd.self_frames_dict[key][dset]

        # Image
        cont_gt = segmentation.find_boundaries(gt[..., f], mode='thick')
        idx_cont_gt = np.where(cont_gt)
        im = utls.imread(confs[0].frameFileNames[f])
        im[idx_cont_gt[0], idx_cont_gt[1], :] = (255, 0, 0)
        locs2d = csv.readCsv(
            os.path.join(confs[0].root_path, confs[0].ds_dir,
                         confs[0].locs_dir, confs[0].csvFileName_fg))
        im = csv.draw2DPoint(locs2d, f, im, radius=7)
        ims[-1].append(im)
Пример #2
0
        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]
        preds = np.squeeze(np.asarray(list(f[a_group_key])))
        preds = preds.transpose((1,2,0))

        gt = l_dataset.gt
        if(gt[...,0].shape != preds[...,0].shape):
            print('Resizing preds...')
            out_shape = gt[...,0].shape
            preds = np.asarray([resize(preds[...,i], out_shape) for i in range(preds.shape[-1])]).transpose((1,2,0))
        pr, rc, _ = precision_recall_curve(gt.ravel(),
Пример #3
0
"""
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)
Пример #4
0
for key in rd.types:

    dsets_to_plot = np.asarray(rd.best_dict_ksp[key][0:n_sets_per_type])
    for dset, gset in zip(dsets_to_plot[:, 0], dsets_to_plot[:, 1]):

        path_out = os.path.join(rd.root_dir, 'plots_results',
                                (key + '_{}_{}').format(ind, dset))

        ims = []

        # 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))