From d6df20e07faf6baacd3e8b34c3858ee5ec32fad0 Mon Sep 17 00:00:00 2001 From: Chris Andrew Date: Mon, 14 Oct 2019 15:14:21 +0530 Subject: [PATCH 1/3] Prepending folder ID to image IDs. --- preperation/cityscape_panoptic_gt.py | 10 ++-- preperation/createLabels.py | 70 ++++++++++++++-------------- 2 files changed, 40 insertions(+), 40 deletions(-) diff --git a/preperation/cityscape_panoptic_gt.py b/preperation/cityscape_panoptic_gt.py index 7044e7c..1adf25a 100644 --- a/preperation/cityscape_panoptic_gt.py +++ b/preperation/cityscape_panoptic_gt.py @@ -30,15 +30,17 @@ def process_image(working_idx): + """Worker function.""" global file_list, categories_dic, output_folder f = file_list[working_idx] # print(f) - images = [] img = Image.open(f) img = img.resize((1280, 720)) original_format = np.array(img) # print("Processing file", f) - file_name = f.split('/')[-1] + print(f) + folder_id = f.split('/')[-2] + file_name = folder_id + "_" + f.split('/')[-1] image_id = file_name.rsplit('_', 2)[0] image_filename = '{}_gtFine_instancelevel3Ids.png'.format(image_id) # pdb.set_trace() @@ -52,7 +54,6 @@ def process_image(working_idx): (original_format.shape[0], original_format.shape[1], 3), dtype=np.uint8) id_generator = IdGenerator(categories_dict) - idx = 0 l = np.unique(original_format) segm_info = [] for el in l: @@ -94,6 +95,7 @@ def process_image(working_idx): def panoptic_converter(num_workers, original_format_folder, out_folder, out_file): + """Convert to panoptic segmentation format.""" global file_list, categories_dict, output_folder output_folder = out_folder if not os.path.isdir(out_folder): @@ -117,7 +119,7 @@ def panoptic_converter(num_workers, original_format_folder, out_folder, out_file categories_dict = {cat['id']: cat for cat in categories} file_list = sorted(glob.glob(os.path.join( - original_format_folder, '*/*_gtFine_instancelevel3Ids.png'))) + original_format_folder, '*/*_gtFine_instancelevel3Ids.png')))[0:10] images = [] annotations = [] diff --git a/preperation/createLabels.py b/preperation/createLabels.py index 9c6348a..9a7b235 100644 --- a/preperation/createLabels.py +++ b/preperation/createLabels.py @@ -78,44 +78,8 @@ def get_args(): def main(args): - import sys if args.panoptic: args.instance = True - sys.path.append(os.path.normpath(os.path.join( - os.path.dirname(__file__), '..', 'helpers'))) - # how to search for all ground truth - searchFine = os.path.join(args.datadir, "gtFine", - "*", "*", "*_gt*_polygons.json") - - # search files - filesFine = glob.glob(searchFine) - filesFine.sort() - - files = filesFine - - if not files: - tqdm.writeError( - "Did not find any files. Please consult the README.") - - # a bit verbose - tqdm.write("Processing {} annotation files".format(len(files))) - - # iterate through files - progress = 0 - tqdm.write("Progress: {:>3} %".format( - progress * 100 / len(files)), end=' ') - - from multiprocessing import Pool - import time - - pool = Pool(args.num_workers) - # results = pool.map(process_pred_gt_pair, pairs) - results = list( - tqdm(pool.imap(process_folder, files), total=len(files))) - pool.close() - pool.join() - - if args.panoptic: for split in ['train', 'val']: folder_name = os.path.join(args.datadir, 'gtFine') output_folder = os.path.join(folder_name, split + "_panoptic") @@ -123,6 +87,40 @@ def main(args): out_file = os.path.join(folder_name, split + "_panoptic.json") panoptic_converter(args.num_workers, os.path.join( folder_name, split), output_folder, out_file) + else: + sys.path.append(os.path.normpath(os.path.join( + os.path.dirname(__file__), '..', 'helpers'))) + # how to search for all ground truth + searchFine = os.path.join(args.datadir, "gtFine", + "*", "*", "*_gt*_polygons.json") + + # search files + filesFine = glob.glob(searchFine) + filesFine.sort() + + files = filesFine + + if not files: + tqdm.writeError( + "Did not find any files. Please consult the README.") + + # a bit verbose + tqdm.write("Processing {} annotation files".format(len(files))) + + # iterate through files + progress = 0 + tqdm.write("Progress: {:>3} %".format( + progress * 100 / len(files)), end=' ') + + from multiprocessing import Pool + + pool = Pool(args.num_workers) + # results = pool.map(process_pred_gt_pair, pairs) + results = list(tqdm(pool.imap(process_folder, files), total=len(files))) + pool.close() + pool.join() + + if __name__ == "__main__": From ec614c3d7c9f741ccee6d664e2b5905f26c4d978 Mon Sep 17 00:00:00 2001 From: Chris Andrew Date: Mon, 14 Oct 2019 15:18:27 +0530 Subject: [PATCH 2/3] Process all files --- preperation/cityscape_panoptic_gt.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/preperation/cityscape_panoptic_gt.py b/preperation/cityscape_panoptic_gt.py index 1adf25a..65e2828 100644 --- a/preperation/cityscape_panoptic_gt.py +++ b/preperation/cityscape_panoptic_gt.py @@ -119,7 +119,7 @@ def panoptic_converter(num_workers, original_format_folder, out_folder, out_file categories_dict = {cat['id']: cat for cat in categories} file_list = sorted(glob.glob(os.path.join( - original_format_folder, '*/*_gtFine_instancelevel3Ids.png')))[0:10] + original_format_folder, '*/*_gtFine_instancelevel3Ids.png'))) images = [] annotations = [] From 1189fed76acd2068b06743537e08a17c7fb19756 Mon Sep 17 00:00:00 2001 From: Chris Andrew Date: Mon, 14 Oct 2019 15:20:50 +0530 Subject: [PATCH 3/3] Merge with origin --- preperation/createLabels.py | 42 ------------------------------------- 1 file changed, 42 deletions(-) diff --git a/preperation/createLabels.py b/preperation/createLabels.py index a2bb18b..9a7b235 100644 --- a/preperation/createLabels.py +++ b/preperation/createLabels.py @@ -80,49 +80,7 @@ def get_args(): def main(args): if args.panoptic: args.instance = True -<<<<<<< HEAD for split in ['train', 'val']: -======= - sys.path.append(os.path.normpath(os.path.join( - os.path.dirname(__file__), '..', 'helpers'))) - # how to search for all ground truth - searchFine = os.path.join(args.datadir, "gtFine", - "*", "*", "*_gt*_polygons.json") - - # search files - filesFine = glob.glob(searchFine) - filesFine.sort() - - files = filesFine[:10] - - if not files: - tqdm.writeError( - "Did not find any files. Please consult the README.") - - # a bit verbose - tqdm.write( - "Processing {} annotation files for Sematic/Instance Segmentation".format(len(files))) - - # iterate through files - progress = 0 - tqdm.write("Progress: {:>3} %".format( - progress * 100 / len(files)), end=' ') - - from multiprocessing import Pool - import time - - pool = Pool(args.num_workers) - # results = pool.map(process_pred_gt_pair, pairs) - results = list( - tqdm(pool.imap(process_folder, files), total=len(files))) - pool.close() - pool.join() - - if args.panoptic: - for split in ['test']: - - tqdm.write("Panoptic Segmentation {} split".format(split)) ->>>>>>> 377a067c6887fd69ede779b17375be41277961f6 folder_name = os.path.join(args.datadir, 'gtFine') output_folder = os.path.join(folder_name, split + "_panoptic") os.makedirs(output_folder, exist_ok=True)