Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 7 additions & 6 deletions preperation/cityscape_panoptic_gt.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,21 +30,22 @@


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(
f.split('/')[-2], image_id)
image_filename = '{}_gtFine_instancelevel3Ids.png'.format(image_id)
# pdb.set_trace()
# image entry, id for image is its filename without extension
image = {"id": image_filename,
image = {"id": image_id,
"width": original_format.shape[1],
"height": original_format.shape[0],
"file_name": image_filename}
Expand All @@ -53,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:
Expand Down Expand Up @@ -96,6 +96,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):
Expand Down
69 changes: 32 additions & 37 deletions preperation/createLabels.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,54 +78,49 @@ 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")
for split in ['train', 'val']:
folder_name = os.path.join(args.datadir, 'gtFine')
output_folder = os.path.join(folder_name, split + "_panoptic")
os.makedirs(output_folder, exist_ok=True)
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()
# search files
filesFine = glob.glob(searchFine)
filesFine.sort()

files = filesFine[:10]
files = filesFine

if not files:
tqdm.writeError(
"Did not find any files. Please consult the README.")
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)))
# 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=' ')
# iterate through files
progress = 0
tqdm.write("Progress: {:>3} %".format(
progress * 100 / len(files)), end=' ')

from multiprocessing import Pool
import time
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()
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))
folder_name = os.path.join(args.datadir, 'gtFine')
output_folder = os.path.join(folder_name, split + "_panoptic")
os.makedirs(output_folder, exist_ok=True)
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)


if __name__ == "__main__":
Expand Down