Beispiel #1
0
def main(args):
    imgs_dir = data_dir + 'fig'
    gt_dir = data_dir + 'mat'
    paths_imgs = fs.gen_paths(imgs_dir, fs.filter_is_img)
    paths_gt = fs.gen_paths(gt_dir)
    paths_pairs = fs.fname_pairs(paths_imgs, paths_gt)    
    paths_imgs, paths_gt = map(list, zip(*paths_pairs))

    lm_img_dst = lmdb_dst + phase + '_img_lmdb'
    lm_gt_dst  = lmdb_dst + phase + '_gt_lmdb'
    if not os.path.exists(lm_img_dst):
        print 'lmdb dir not exists,make it'
        os.makedirs(lm_img_dst)
    if not os.path.exists(lm_gt_dst):
        print 'lmdb dir not exists,make it'
        os.makedirs(lm_gt_dst)

    size1 = imgs_to_lmdb(paths_imgs, lm_img_dst, CAFFE_ROOT = CAFFE_ROOT)
    size2 = matfiles_to_lmdb(paths_gt, lm_gt_dst, 'gt',CAFFE_ROOT = CAFFE_ROOT)
    dif = size1 - size2
    dif = dif.sum()
    if(dif != 0):
         print 'ERROR: img-gt size not match! diff:'+str(diff)
         return 1
    return 0
Beispiel #2
0
def main(args):
    dir_imgs = CAFFE_ROOT + "data/fcn_label_full/" + phase + "_jpg"
    paths_imgs = fs.gen_paths(dir_imgs, fs.filter_is_img)

    dir_segm_labels = CAFFE_ROOT + "data/fcn_label_full/" + phase + "_maps"
    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))
    if not os.path.exists(lmimgDst):
        print "lmdb dir not exists,make it"
        os.makedirs(lmimgDst)
        if not os.path.exists(lmlabelDst):
            print "lmdb dir not exists,make it"
            os.makedirs(lmlabelDst)
    # for a, b in paths_pairs:
    #   print a,b
    size1 = to_lmdb.imgs_to_lmdb(paths_imgs, lmimgDst, CAFFE_ROOT=CAFFE_ROOT)
    size2 = to_lmdb.matfiles_to_lmdb(paths_segm_labels, lmlabelDst, "gt", CAFFE_ROOT=CAFFE_ROOT)
    dif = size1 - size2
    dif = dif.sum()
    scipy.io.savemat("./size1", dict({"sz": size1}), appendmat=True)
    scipy.io.savemat("./size2", dict({"sz": size2}), appendmat=True)
    print "size dif:" + str(dif)
    return 0
Beispiel #3
0
def main(args):
     dir_imgs = CAFFE_ROOT+'data/fcn_label_full/' + phase + '_jpg'
     paths_imgs = fs.gen_paths(dir_imgs, fs.filter_is_img)
     
     dir_segm_labels = CAFFE_ROOT + 'data/fcn_label_full/' + phase + '_maps'
     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))
     if not os.path.exists(lmimgDst):
     	print 'lmdb dir not exists,make it'
     	os.makedirs(lmimgDst)
 	if not os.path.exists(lmlabelDst):
 	    print 'lmdb dir not exists,make it'
 	    os.makedirs(lmlabelDst)
     #for a, b in paths_pairs:
     #   print a,b     
     size1 = to_lmdb.imgs_to_lmdb(paths_imgs, lmimgDst, CAFFE_ROOT = CAFFE_ROOT)
     size2 = to_lmdb.matfiles_to_lmdb(paths_segm_labels, lmlabelDst, 'gt',CAFFE_ROOT = CAFFE_ROOT)
     dif = size1 - size2
     dif = dif.sum()
     scipy.io.savemat('./size1',dict({'sz':size1}),appendmat=True)
     scipy.io.savemat('./size2',dict({'sz':size2}),appendmat=True)
     print 'size dif:'+str(dif)
     return 0
Beispiel #4
0
def main(args):
    imgs_dir = data_dir + 'fig'
    gt_dir = data_dir + 'mat'
    paths_imgs = fs.gen_paths(imgs_dir, fs.filter_is_img)
    paths_gt = fs.gen_paths(gt_dir)
    paths_pairs = fs.fname_pairs(paths_imgs, paths_gt)    
    paths_imgs, paths_gt = map(list, zip(*paths_pairs))

    lm_img_dst = lmdb_dst + phase + '_img_lmdb'
    lm_gt_dst  = lmdb_dst + phase + '_gt_lmdb'
    if not os.path.exists(lm_img_dst):
        print 'lmdb dir not exists,make it'
        os.makedirs(lm_img_dst)
    if not os.path.exists(lm_gt_dst):
        print 'lmdb dir not exists,make it'
        os.makedirs(lm_gt_dst)

    size1 = imgs_to_lmdb(paths_imgs, lm_img_dst, CAFFE_ROOT = CAFFE_ROOT)
    size2 = matfiles_to_lmdb(paths_gt, lm_gt_dst, 'gt',CAFFE_ROOT = CAFFE_ROOT)
    dif = size1 - size2
    dif = dif.sum()
    if(dif != 0):
         print 'ERROR: img-gt size not match! diff:'+str(diff)
         return 1
    return 0
Beispiel #5
0
def main(args):

    paths_imgs = fs.gen_paths(imgs_dir, fs.filter_is_img)
    paths_gt = fs.gen_paths(gt_dir)
    paths_pairs = fs.fname_pairs(paths_imgs, paths_gt)
    paths_imgs, paths_gt = map(list, zip(*paths_pairs))

    lm_img_dst = imgs_dir + '_lmdb'
    lm_gt_dst = gt_dir + '_lmdb'
    if not os.path.exists(lm_img_dst):
        print 'lmdb dir not exists,make it'
        os.makedirs(lm_img_dst)
    if not os.path.exists(lm_gt_dst):
        print 'lmdb dir not exists,make it'
        os.makedirs(lm_gt_dst)

    size1 = imgs_to_lmdb(paths_imgs, lm_img_dst, CAFFE_ROOT=CAFFE_ROOT)
    size2 = matfiles_to_lmdb(paths_gt, lm_gt_dst, 'gt', CAFFE_ROOT=CAFFE_ROOT)
    dif = size1 - size2
    dif = dif.sum()
    #scipy.io.savemat('./size1',dict({'sz':size1}),appendmat=True)
    #scipy.io.savemat('./size2',dict({'sz':size2}),appendmat=True)
    if (dif != 0):
        print 'ERROR: img-gt size not match! diff:' + str(diff)
        return 1
    return 0
Beispiel #6
0
def main(args):
    
    paths_imgs = fs.gen_paths(imgs_dir, fs.filter_is_img)
    paths_gt = fs.gen_paths(gt_dir)
    paths_pairs = fs.fname_pairs(paths_imgs, paths_gt)    
    paths_imgs, paths_gt = map(list, zip(*paths_pairs))

    lm_img_dst = imgs_dir + '_lmdb'
    lm_gt_dst  = gt_dir + '_lmdb'
    if not os.path.exists(lm_img_dst):
        print 'lmdb dir not exists,make it'
        os.makedirs(lm_img_dst)
    if not os.path.exists(lm_gt_dst):
        print 'lmdb dir not exists,make it'
        os.makedirs(lm_gt_dst)

    size1 = imgs_to_lmdb(paths_imgs, lm_img_dst, CAFFE_ROOT = CAFFE_ROOT)
    size2 = matfiles_to_lmdb(paths_gt, lm_gt_dst, 'gt',CAFFE_ROOT = CAFFE_ROOT)
    dif = size1 - size2
    dif = dif.sum()
    #scipy.io.savemat('./size1',dict({'sz':size1}),appendmat=True)
    #scipy.io.savemat('./size2',dict({'sz':size2}),appendmat=True)
    if(dif != 0):
         print 'ERROR: img-gt size not match! diff:'+str(diff)
         return 1
    return 0
def pascal_context_to_lmdb(dir_imgs,
                           dir_segm_labels,
                           fpath_labels_list,
                           fpath_labels_list_subset,
                           dst_prefix,
                           dir_dst,
                           CAFFE_ROOT=None,
                           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 = ''
        
    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 = get_labels_lut(labels_list, labels_59_list)
    def apply_labels_lut(m):
        return labels_lut[m]
    
    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))
    
    #for a, b in paths_pairs:
    #    print a,b
    
    if val_list is not None:
        # do train/val split
        
        train_idx, val_idx = get_train_val_split(paths_imgs, val_list)
        
        # images
        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,
                             CAFFE_ROOT=CAFFE_ROOT)
        
        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,
                             CAFFE_ROOT=CAFFE_ROOT)
        
        # ground truth
        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',
                                 CAFFE_ROOT=CAFFE_ROOT, lut=apply_labels_lut)
        
        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',
                                 CAFFE_ROOT=CAFFE_ROOT, 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:
        fpath_lmdb_imgs = os.path.join(dir_dst,
                                       '%scontext_imgs_lmdb' % dst_prefix)
        to_lmdb.imgs_to_lmdb(paths_imgs,
                             fpath_lmdb_imgs,
                             CAFFE_ROOT=CAFFE_ROOT)
        
        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',
                                 CAFFE_ROOT=CAFFE_ROOT, lut=apply_labels_lut)
        
        return len(paths_imgs), fpath_lmdb_imgs, fpath_lmdb_segm_labels
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 = ''
        
    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]
    
    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))
    
    #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
        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)
        
        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
        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)
        
        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:
        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