diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000..3b24b28 Binary files /dev/null and b/.DS_Store differ diff --git a/README.md b/README.md index e3a5603..e8ff1bf 100644 --- a/README.md +++ b/README.md @@ -96,7 +96,7 @@ See helpers/anue_labels.py python preperation/createLabels.py --datadir $ANUE --id-type $IDTYPE --color [True|False] --instance [True|False] --num-workers $C ``` -- ANUE is the path to the AutoNUE dataset +- ANUE is the path to the AutoNUE dataset(the path to the gtFine for any dataset you have downloaded from the IDD website,for example: "/Users/srimanthdhondy/Programs/autodataset/idd20kII",here the idd20kII has two folders gtFine and leftImg8bit) - IDTYPE can be id, csId, csTrainId, level3Id, level2Id, level1Id. - color True generates the color masks - instance True generates the instance masks with the id given by IDTYPE @@ -108,6 +108,7 @@ For the supervised domain adaptation and semantic segmentation tasks, the masks ```bash python preperation/createLabels.py --datadir $ANUE --id-type level3Id --num-workers $C ``` +**NOTE**:In the scripts json2instanceImg.py, json2labelImg.py be sure to change the highlighted path in the line "sys.path.append("**/Users/srimanthdhondy/Programs**/public-code/helpers/")" as per your download location. Following commands are updated for the target labels of other domain adaptation tasks: diff --git a/preperation/createLabels.py b/preperation/createLabels.py index 04984fe..5d0a7e7 100644 --- a/preperation/createLabels.py +++ b/preperation/createLabels.py @@ -3,6 +3,7 @@ # python imports from __future__ import print_function +from functools import partial import os import glob import sys @@ -10,6 +11,7 @@ from imageio import imread, imsave import numpy as np from numpngw import write_png +import PIL from json2labelImg import json2labelImg from json2instanceImg import json2instanceImg @@ -23,11 +25,28 @@ import pandas as pd import shutil +global args args = None +def get_args(): + parser = ArgumentParser() + + parser.add_argument('--datadir', default="") + parser.add_argument('--id-type', default='level3Id') + parser.add_argument('--color', type=bool, default=False) + parser.add_argument('--instance', type=bool, default=False) + parser.add_argument('--panoptic', type=bool, default=False) + parser.add_argument('--semisup_da', type=bool, default=False) + parser.add_argument('--unsup_da', type=bool, default=False) + parser.add_argument('--weaksup_da', type=bool, default=False) + parser.add_argument('--num-workers', type=int, default=10) + + args = parser.parse_args() + + return args -def process_folder(fn): - global args +def process_folder(fn,args): + dst = fn.replace("_polygons.json", "_label{}s.png".format(args.id_type)) @@ -57,29 +76,13 @@ def process_folder(fn): try: json2labelImg(fn, dst, 'color') except: - tqdm.write("Failed to convert: {}".format(f)) + tqdm.write("Failed to convert: {}".format(fn)) raise # if args.panoptic and args.instance: # panoptic_converter(f, out_folder, out_file) -def get_args(): - parser = ArgumentParser() - - parser.add_argument('--datadir', default="") - parser.add_argument('--id-type', default='level3Id') - parser.add_argument('--color', type=bool, default=False) - parser.add_argument('--instance', type=bool, default=False) - parser.add_argument('--panoptic', type=bool, default=False) - parser.add_argument('--semisup_da', type=bool, default=False) - parser.add_argument('--unsup_da', type=bool, default=False) - parser.add_argument('--weaksup_da', type=bool, default=False) - parser.add_argument('--num-workers', type=int, default=10) - - args = parser.parse_args() - - return args # The main method @@ -124,7 +127,7 @@ def main(args): #print('args.semisup_da', args.semisup_da, len(files)) if not files: - tqdm.writeError( + tqdm.write( "Did not find any files. Please consult the README.") # a bit verbose @@ -141,8 +144,7 @@ def main(args): pool = Pool(args.num_workers) # results = pool.map(process_pred_gt_pair, pairs) - results = list( - tqdm(pool.imap(process_folder, files), total=len(files))) + results = list(tqdm(pool.imap(partial(process_folder, args=args), files), total=len(files))) pool.close() pool.join() diff --git a/preperation/json2instanceImg.py b/preperation/json2instanceImg.py index ebf9a59..a9f61e2 100755 --- a/preperation/json2instanceImg.py +++ b/preperation/json2instanceImg.py @@ -33,21 +33,22 @@ # # python imports +import sys +sys.path.append("/Users/srimanthdhondy/Programs/public-code/helpers/") from anue_labels import labels, name2label from annotation import Annotation import os -import sys import getopt from tqdm import tqdm # Image processing # Check if PIL is actually Pillow as expected -try: - from PIL import PILLOW_VERSION -except: - print("Please install the module 'Pillow' for image processing, e.g.") - print("pip install pillow") - sys.exit(-1) +#try: + #from PIL import PILLOW_VERSION +#except: + #print("Please install the module 'Pillow' for image processing, e.g.") + #print("pip install pillow") + #sys.exit(-1) try: import PIL.Image as Image diff --git a/preperation/json2labelImg.py b/preperation/json2labelImg.py index a437d7a..e2b5907 100755 --- a/preperation/json2labelImg.py +++ b/preperation/json2labelImg.py @@ -2,22 +2,24 @@ # # python imports +import sys +sys.path.append("/Users/srimanthdhondy/Programs/public-code/helpers/") from anue_labels import name2label from annotation import Annotation import os -import sys import getopt - +import tqdm +import sys import numpy # Image processing # Check if PIL is actually Pillow as expected -try: - from PIL import PILLOW_VERSION -except: - print("Please install the module 'Pillow' for image processing, e.g.") - print("pip install pillow") - sys.exit(-1) +#try: + #from PIL import PILLOW_VERSION +#except: + #print("Please install the module 'Pillow' for image processing, e.g.") + #print("pip install pillow") + #sys.exit(-1) try: import PIL.Image as Image diff --git a/requirements.txt b/requirements.txt index 50736bc..401887a 100644 --- a/requirements.txt +++ b/requirements.txt @@ -4,3 +4,4 @@ tqdm Pillow scipy==1.1.0 imageio +numpngw