From d6c5c5c8d70902fbe3dbb522a2e9e959caae5f4d Mon Sep 17 00:00:00 2001 From: Srimanth Dhondy Date: Mon, 1 Apr 2024 16:56:03 +0530 Subject: [PATCH 1/3] The changes that were made to the files createLabe ls.py,json2instanceImg.py,json2labelImg.py regarding the creation of the labels for the dataset.The changes that were made are: 1. The removal of the part of code related to the PIL package( try and except block for the import of PILLOW_VERSION from PIL) 2. The line of code "results = list(tqdm(pool.imap(process_folder, files), total=len(files)))" was modified to "results = list(tqdm(pool.imap(partial(process_folder, args=args), files), total=len(files)))" 3. The function process_folder was modified to accept the argument args for the purpose of identifying the args.id_type that was passed in the function,which was causing the error "NoneType object has no attribute 'id_type'" when the function was called. 4. The line "sys.path.append("/Users/srimanthdhondy/Programs/public-code/helpers/")" was added to the file json2instanceImg,json2labelImg to import the necessary packages from the helpers folder. NOTE:Ensure to change the path to the helpers folder to the path in your system,while executing the code i.e., replace the path "/Users/srimanthdhondy/Programs/" with the path to the helpers folder in your system. NOTE: The changes were made to the files to ensure that the code runs without any errors and the labels are created successfully for the dataset.Refer the README.md file for the instructions to run the code. --- .DS_Store | Bin 0 -> 6148 bytes preperation/createLabels.py | 46 +++++++++++++++++--------------- preperation/json2instanceImg.py | 15 ++++++----- preperation/json2labelImg.py | 18 +++++++------ 4 files changed, 42 insertions(+), 37 deletions(-) create mode 100644 .DS_Store diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..3b24b288564bcb2c071847488690007060520b36 GIT binary patch literal 6148 zcmeHKK~BRk5FD2ZN_#0cE=YL+5PBtFbb_~D_*2x*r2hgDlw!198G3giIvQ}v65siDs3>mI*i-fMG3aA3V zT>)9UM_jKKbFSI)`duJrOU^cn>>{<(NopsImaXEPe){2zHK2<-Y#5zl-N<>XaSrf6 zR*D77C05l8=45wtvYMt7Yg0*Hd(dXQ%u<`(vxl1!dQ7ln3ZJH7K<0&!q>3c18-@Wc5m7KZSoG+ho9#&-Mct&33w`8E@SKsGM%*c5X zU8}Kf-d;=dMylGsRY3m5w2tfnYN~)LpbC@~ko_T|3&sHpk8bN=;jRG0Hk+NXE*}WO zi2}v}3y(=1ptc~b5bTNr5JUR-Ca2&ge9L2|U aXY7llLW~0z9@#?E4*@5G7OKFHD)0$g<&Db# literal 0 HcmV?d00001 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 From e2e4ca2667154bacd1235a1c79f7b35e5a7315d9 Mon Sep 17 00:00:00 2001 From: Srimanth <109213942+AISpaceXDragon@users.noreply.github.com> Date: Mon, 1 Apr 2024 17:38:24 +0530 Subject: [PATCH 2/3] Update README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) 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: From cfa3f8cb5059569606056b6ec132e2d65fd9b3f5 Mon Sep 17 00:00:00 2001 From: Srimanth <109213942+AISpaceXDragon@users.noreply.github.com> Date: Wed, 22 May 2024 13:00:36 +0530 Subject: [PATCH 3/3] Update requirements.txt --- requirements.txt | 1 + 1 file changed, 1 insertion(+) 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