From b4678eb6571a56fbe5420fe676a5295aeda79d2c Mon Sep 17 00:00:00 2001 From: Xinyu Wang <45810070+xinke-wang@users.noreply.github.com> Date: Thu, 5 May 2022 14:09:05 +0800 Subject: [PATCH] [Fix] Fix Data Converter Issues (#955) * fix naf mask issue; fix lv path issue * fix path * fix ic13, ic11 path issue; fix cocotextv2 mask issue * fix funsd format --- tools/data/textdet/cocotext_converter.py | 2 ++ tools/data/textdet/lv_converter.py | 3 ++- tools/data/textdet/naf_converter.py | 5 +++-- tools/data/textrecog/funsd_converter.py | 4 ++-- tools/data/textrecog/ic11_converter.py | 4 ++-- tools/data/textrecog/ic13_converter.py | 4 ++-- 6 files changed, 13 insertions(+), 9 deletions(-) diff --git a/tools/data/textdet/cocotext_converter.py b/tools/data/textdet/cocotext_converter.py index 049efd38..4c28b7ba 100644 --- a/tools/data/textdet/cocotext_converter.py +++ b/tools/data/textdet/cocotext_converter.py @@ -92,6 +92,8 @@ def collect_cocotext_info(root_path, split, print_every=1000): w, h = math.ceil(w), math.ceil(h) bbox = [x, y, w, h] segmentation = [max(0, int(x)) for x in ann['mask']] + if len(segmentation) < 8 or len(segmentation) % 2 != 0: + segmentation = [x, y, x + w, y, x + w, y + h, x, y + h] anno = dict( iscrowd=iscrowd, category_id=1, diff --git a/tools/data/textdet/lv_converter.py b/tools/data/textdet/lv_converter.py index e14026ee..1d5dfa75 100644 --- a/tools/data/textdet/lv_converter.py +++ b/tools/data/textdet/lv_converter.py @@ -83,9 +83,10 @@ def load_img_info(files): '.')[0] # read imgs while ignoring orientations img = mmcv.imread(img_file, 'unchanged') + img_file = img_file.split('data/lv/')[1] img_info = dict( - file_name=osp.join(osp.basename(img_file)), + file_name=img_file, height=img.shape[0], width=img.shape[1], segm_file=osp.join(osp.basename(gt_file))) diff --git a/tools/data/textdet/naf_converter.py b/tools/data/textdet/naf_converter.py index cb800457..219950f7 100644 --- a/tools/data/textdet/naf_converter.py +++ b/tools/data/textdet/naf_converter.py @@ -139,14 +139,15 @@ def load_json_info(gt_file, img_info): if anno['type'] == 'blank': continue - xs, ys = [], [] + xs, ys, segmentation = [], [], [] for p in anno['poly_points']: xs.append(p[0]) ys.append(p[1]) + segmentation.append(p[0]) + segmentation.append(p[1]) x, y = max(0, min(xs)), max(0, min(ys)) w, h = max(xs) - x, max(ys) - y bbox = [x, y, w, h] - segmentation = anno['poly_points'] anno = dict( iscrowd=0, diff --git a/tools/data/textrecog/funsd_converter.py b/tools/data/textrecog/funsd_converter.py index 409f0702..baa73e16 100644 --- a/tools/data/textrecog/funsd_converter.py +++ b/tools/data/textrecog/funsd_converter.py @@ -140,9 +140,9 @@ def generate_ann(root_path, split, image_infos, preserve_vertical, format): dst_image_root = osp.join(root_path, 'dst_imgs', split) if split == 'training': - dst_label_file = osp.join(root_path, 'train_label.txt') + dst_label_file = osp.join(root_path, f'train_label.{format}') elif split == 'test': - dst_label_file = osp.join(root_path, 'test_label.txt') + dst_label_file = osp.join(root_path, f'test_label.{format}') os.makedirs(dst_image_root, exist_ok=True) lines = [] diff --git a/tools/data/textrecog/ic11_converter.py b/tools/data/textrecog/ic11_converter.py index e46b395a..bf638c72 100644 --- a/tools/data/textrecog/ic11_converter.py +++ b/tools/data/textrecog/ic11_converter.py @@ -39,7 +39,7 @@ def convert_annotations(root_path, split, format): 'r', encoding='"utf-8-sig') as f: annos = f.readlines() - dst_image_root = osp.join(root_path, split) + dst_image_root = osp.join(root_path, split.lower()) for anno in annos: # text may contain comma ',' dst_img_name, word = anno.split(', "') @@ -58,7 +58,7 @@ def convert_annotations(root_path, split, format): else: raise NotImplementedError - list_to_file(osp.join(root_path, f'{split}_label.{format}'), lines) + list_to_file(osp.join(root_path, f'{split.lower()}_label.{format}'), lines) def parse_args(): diff --git a/tools/data/textrecog/ic13_converter.py b/tools/data/textrecog/ic13_converter.py index b6f0c57d..28ddc12f 100644 --- a/tools/data/textrecog/ic13_converter.py +++ b/tools/data/textrecog/ic13_converter.py @@ -39,7 +39,7 @@ def convert_annotations(root_path, split, format): 'r', encoding='"utf-8-sig') as f: annos = f.readlines() - dst_image_root = osp.join(root_path, split) + dst_image_root = osp.join(root_path, split.lower()) for anno in annos: # text may contain comma ',' dst_img_name, word = anno.split(', "') @@ -58,7 +58,7 @@ def convert_annotations(root_path, split, format): else: raise NotImplementedError - list_to_file(osp.join(root_path, f'{split}_label.{format}'), lines) + list_to_file(osp.join(root_path, f'{split.lower()}_label.{format}'), lines) def parse_args():