Ejemplo n.º 1
0
 def test_fname_pairs_log_files(self):
 
     a = fs.gen_paths(self.dir_, is_caffe_info_log)
     b = fs.gen_paths(self.dir_tmp, is_caffe_info_log)
     pairs = fs.fname_pairs(a, b)
     
     for x, y in pairs:
         assert_in(x, a)
         assert_in(y, b)
Ejemplo n.º 2
0
    def test_fname_pairs_log_files(self):

        a = fs.gen_paths(self.dir_, is_caffe_info_log)
        b = fs.gen_paths(self.dir_tmp, is_caffe_info_log)
        pairs = fs.fname_pairs(a, b)

        for x, y in pairs:
            assert_in(x, a)
            assert_in(y, b)
Ejemplo n.º 3
0
 def test_fname_pairs(self):
 
     a = ['foo1_a.txt', os.path.join('foo', 'bar_x.txt'), 'foo5.txt']
     b = [os.path.join('oof', 'bar_x.txt'), 'foo5_b.txt', 'foo2_b.txt']
     pairs = fs.fname_pairs(a, b)
     
     for x, y in pairs:
         assert_in(x, a)
         assert_in(y, b)
         
     assert_list_equal(pairs, [[os.path.join('foo', 'bar_x.txt'),
                                os.path.join('oof', 'bar_x.txt')],
                               ['foo5.txt', 'foo5_b.txt'],
                               ])
Ejemplo n.º 4
0
    def test_fname_pairs(self):

        a = ['foo1_a.txt', os.path.join('foo', 'bar_x.txt'), 'foo5.txt']
        b = [os.path.join('oof', 'bar_x.txt'), 'foo5_b.txt', 'foo2_b.txt']
        pairs = fs.fname_pairs(a, b)

        for x, y in pairs:
            assert_in(x, a)
            assert_in(y, b)

        assert_list_equal(pairs, [[os.path.join('foo', 'bar_x.txt'),
                                   os.path.join('oof', 'bar_x.txt')],
                                  ['foo5.txt', 'foo5_b.txt'],
                                  ])
Ejemplo n.º 5
0
def pascal_context_to_lmdb(dir_imgs,
                           dir_segm_labels,
                           fpath_labels_list,
                           fpath_labels_list_subset,
                           dst_prefix,
                           dir_dst,
                           val_list=None):
    '''
    Fine intersection of filename in both directories and create
    one lmdb directory for each
    val_list - list of entities to exclude from train (validation subset e.g. ['2008_000002', '2010_000433'])
    '''
    if dst_prefix is None:
        dst_prefix = ''

    print 'begin'
    labels_list = get_labels_list(fpath_labels_list)
    labels_59_list = get_labels_list(fpath_labels_list_subset)

    #print labels_list
    #print labels_59_list
    labels_lut = du.get_labels_lut(labels_list, labels_59_list)

    def apply_labels_lut(m):
        return labels_lut[m]

    print 'plus loin'
    paths_imgs = fs.gen_paths(dir_imgs, fs.filter_is_img)

    paths_segm_labels = fs.gen_paths(dir_segm_labels)

    paths_pairs = fs.fname_pairs(paths_imgs, paths_segm_labels)
    paths_imgs, paths_segm_labels = map(list, zip(*paths_pairs))

    print 'avant if'
    #for a, b in paths_pairs:
    #    print a,b

    if val_list is not None:
        # do train/val split

        train_idx, val_idx = du.get_train_val_split_from_names(
            paths_imgs, val_list)

        # images
        print 'begin images'
        print 'train'
        paths_imgs_train = [paths_imgs[i] for i in train_idx]
        fpath_lmdb_imgs_train = os.path.join(
            dir_dst, '%scontext_imgs_train_lmdb' % dst_prefix)
        to_lmdb.imgs_to_lmdb(paths_imgs_train, fpath_lmdb_imgs_train)

        print 'val'
        paths_imgs_val = [paths_imgs[i] for i in val_idx]
        fpath_lmdb_imgs_val = os.path.join(
            dir_dst, '%scontext_imgs_val_lmdb' % dst_prefix)
        to_lmdb.imgs_to_lmdb(paths_imgs_val, fpath_lmdb_imgs_val)

        # ground truth
        print 'begin labels'
        print 'train'
        paths_segm_labels_train = [paths_segm_labels[i] for i in train_idx]
        fpath_lmdb_segm_labels_train = os.path.join(
            dir_dst, '%scontext_labels_train_lmdb' % dst_prefix)
        to_lmdb.matfiles_to_lmdb(paths_segm_labels_train,
                                 fpath_lmdb_segm_labels_train,
                                 'LabelMap',
                                 lut=apply_labels_lut)

        print 'val'
        paths_segm_labels_val = [paths_segm_labels[i] for i in val_idx]
        fpath_lmdb_segm_labels_val = os.path.join(
            dir_dst, '%scontext_labels_val_lmdb' % dst_prefix)
        to_lmdb.matfiles_to_lmdb(paths_segm_labels_val,
                                 fpath_lmdb_segm_labels_val,
                                 'LabelMap',
                                 lut=apply_labels_lut)

        return len(paths_imgs_train), len(paths_imgs_val),\
            fpath_lmdb_imgs_train, fpath_lmdb_segm_labels_train, fpath_lmdb_imgs_val, fpath_lmdb_segm_labels_val

    else:
        print 'dans else'
        fpath_lmdb_imgs = os.path.join(dir_dst,
                                       '%scontext_imgs_lmdb' % dst_prefix)
        to_lmdb.imgs_to_lmdb(paths_imgs, fpath_lmdb_imgs)

        fpath_lmdb_segm_labels = os.path.join(
            dir_dst, '%scontext_labels_lmdb' % dst_prefix)
        to_lmdb.matfiles_to_lmdb(paths_segm_labels,
                                 fpath_lmdb_segm_labels,
                                 'LabelMap',
                                 lut=apply_labels_lut)

        return len(paths_imgs), fpath_lmdb_imgs, fpath_lmdb_segm_labels