From 4fcfe0c8363806b97202d7d0509c655d365e8b4c Mon Sep 17 00:00:00 2001 From: myasin Date: Wed, 26 May 2021 15:11:48 +0530 Subject: [PATCH 1/4] Update voc2coco.py --- voc2coco.py | 27 ++++++++++----------------- 1 file changed, 10 insertions(+), 17 deletions(-) diff --git a/voc2coco.py b/voc2coco.py index d04670d..b0e126b 100644 --- a/voc2coco.py +++ b/voc2coco.py @@ -9,7 +9,9 @@ import glob START_BOUNDING_BOX_ID = 1 -PRE_DEFINE_CATEGORIES = None +PRE_DEFINE_CATEGORIES = {"signature_block": 1, + "initial_block": 2, + "negative_class": 3} # If necessary, pre-define category and its id # PRE_DEFINE_CATEGORIES = {"aeroplane": 1, "bicycle": 2, "bird": 3, "boat": 4, # "bottle":5, "bus": 6, "car": 7, "cat": 8, "chair": 9, @@ -37,15 +39,6 @@ def get_and_check(root, name, length): return vars -def get_filename_as_int(filename): - try: - filename = filename.replace("\\", "/") - filename = os.path.splitext(os.path.basename(filename))[0] - return int(filename) - except: - raise ValueError("Filename %s is supposed to be an integer." % (filename)) - - def get_categories(xml_files): """Generate category name to id mapping from a list of xml files. @@ -73,7 +66,7 @@ def convert(xml_files, json_file): else: categories = get_categories(xml_files) bnd_id = START_BOUNDING_BOX_ID - for xml_file in xml_files: + for idx, xml_file in enumerate(xml_files): tree = ET.parse(xml_file) root = tree.getroot() path = get(root, "path") @@ -83,8 +76,8 @@ def convert(xml_files, json_file): filename = get_and_check(root, "filename", 1).text else: raise ValueError("%d paths found in %s" % (len(path), xml_file)) - ## The filename must be a number - image_id = get_filename_as_int(filename) + # The 'index' is given as img_id + image_id = idx size = get_and_check(root, "size", 1) width = int(get_and_check(size, "width", 1).text) height = int(get_and_check(size, "height", 1).text) @@ -105,10 +98,10 @@ def convert(xml_files, json_file): categories[category] = new_id category_id = categories[category] bndbox = get_and_check(obj, "bndbox", 1) - xmin = int(get_and_check(bndbox, "xmin", 1).text) - 1 - ymin = int(get_and_check(bndbox, "ymin", 1).text) - 1 - xmax = int(get_and_check(bndbox, "xmax", 1).text) - ymax = int(get_and_check(bndbox, "ymax", 1).text) + xmin = int(float(get_and_check(bndbox, "xmin", 1).text)) - 1 + ymin = int(float(get_and_check(bndbox, "ymin", 1).text)) - 1 + xmax = int(float(get_and_check(bndbox, "xmax", 1).text)) + ymax = int(float(get_and_check(bndbox, "ymax", 1).text)) assert xmax > xmin assert ymax > ymin o_width = abs(xmax - xmin) From 48ca615913a62e81b6381c9c1a6cef1f983d3803 Mon Sep 17 00:00:00 2001 From: myasin Date: Wed, 9 Jun 2021 14:57:21 +0530 Subject: [PATCH 2/4] Update voc2coco.py --- voc2coco.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/voc2coco.py b/voc2coco.py index b0e126b..9685028 100644 --- a/voc2coco.py +++ b/voc2coco.py @@ -136,8 +136,8 @@ def convert(xml_files, json_file): parser = argparse.ArgumentParser( description="Convert Pascal VOC annotation to COCO format." ) - parser.add_argument("xml_dir", help="Directory path to xml files.", type=str) - parser.add_argument("json_file", help="Output COCO format json file.", type=str) + parser.add_argument("--xml_dir", help="Directory path to xml files.", type=str) + parser.add_argument("--json_file", help="Output COCO format json file.", type=str) args = parser.parse_args() xml_files = glob.glob(os.path.join(args.xml_dir, "*.xml")) From 3d3d555006b61d70043b052cf1f65c7fa305aa7b Mon Sep 17 00:00:00 2001 From: myasin Date: Wed, 16 Jun 2021 13:01:32 +0530 Subject: [PATCH 3/4] Update voc2coco.py --- voc2coco.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/voc2coco.py b/voc2coco.py index 9685028..8a6bca7 100644 --- a/voc2coco.py +++ b/voc2coco.py @@ -9,9 +9,7 @@ import glob START_BOUNDING_BOX_ID = 1 -PRE_DEFINE_CATEGORIES = {"signature_block": 1, - "initial_block": 2, - "negative_class": 3} + # If necessary, pre-define category and its id # PRE_DEFINE_CATEGORIES = {"aeroplane": 1, "bicycle": 2, "bird": 3, "boat": 4, # "bottle":5, "bus": 6, "car": 7, "cat": 8, "chair": 9, From c45e44f09e04acaffa0f6f733e466865c22a0130 Mon Sep 17 00:00:00 2001 From: myasin Date: Wed, 16 Jun 2021 13:02:29 +0530 Subject: [PATCH 4/4] Update voc2coco.py --- voc2coco.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/voc2coco.py b/voc2coco.py index 8a6bca7..e15a18d 100644 --- a/voc2coco.py +++ b/voc2coco.py @@ -9,7 +9,7 @@ import glob START_BOUNDING_BOX_ID = 1 - +PRE_DEFINE_CATEGORIES = None # If necessary, pre-define category and its id # PRE_DEFINE_CATEGORIES = {"aeroplane": 1, "bicycle": 2, "bird": 3, "boat": 4, # "bottle":5, "bus": 6, "car": 7, "cat": 8, "chair": 9,