mirror of
https://github.com/open-mmlab/mmocr.git
synced 2025-06-03 21:54:47 +08:00
[Fix] Replace mmcv.fileio with mmengine (#1292)
This commit is contained in:
parent
0d9b40706c
commit
c7a4298c32
@ -5,6 +5,7 @@ import warnings
|
|||||||
from typing import Optional
|
from typing import Optional
|
||||||
|
|
||||||
import mmcv
|
import mmcv
|
||||||
|
import mmengine
|
||||||
import numpy as np
|
import numpy as np
|
||||||
from mmcv.transforms import BaseTransform
|
from mmcv.transforms import BaseTransform
|
||||||
from mmcv.transforms import LoadAnnotations as MMCV_LoadAnnotations
|
from mmcv.transforms import LoadAnnotations as MMCV_LoadAnnotations
|
||||||
@ -38,7 +39,7 @@ class LoadImageFromFile(MMCV_LoadImageFromFile):
|
|||||||
See :func:``mmcv.imfrombytes`` for details.
|
See :func:``mmcv.imfrombytes`` for details.
|
||||||
Defaults to 'cv2'.
|
Defaults to 'cv2'.
|
||||||
file_client_args (dict): Arguments to instantiate a FileClient.
|
file_client_args (dict): Arguments to instantiate a FileClient.
|
||||||
See :class:`mmcv.fileio.FileClient` for details.
|
See :class:`mmengine.fileio.FileClient` for details.
|
||||||
Defaults to ``dict(backend='disk')``.
|
Defaults to ``dict(backend='disk')``.
|
||||||
ignore_empty (bool): Whether to allow loading empty image or file path
|
ignore_empty (bool): Whether to allow loading empty image or file path
|
||||||
not existent. Defaults to False.
|
not existent. Defaults to False.
|
||||||
@ -59,7 +60,7 @@ class LoadImageFromFile(MMCV_LoadImageFromFile):
|
|||||||
self.color_type = color_type
|
self.color_type = color_type
|
||||||
self.imdecode_backend = imdecode_backend
|
self.imdecode_backend = imdecode_backend
|
||||||
self.file_client_args = file_client_args.copy()
|
self.file_client_args = file_client_args.copy()
|
||||||
self.file_client = mmcv.FileClient(**self.file_client_args)
|
self.file_client = mmengine.FileClient(**self.file_client_args)
|
||||||
self.min_size = min_size
|
self.min_size = min_size
|
||||||
|
|
||||||
def transform(self, results: dict) -> Optional[dict]:
|
def transform(self, results: dict) -> Optional[dict]:
|
||||||
@ -473,7 +474,7 @@ class LoadImageFromLMDB(BaseTransform):
|
|||||||
See :func:``mmcv.imfrombytes`` for details.
|
See :func:``mmcv.imfrombytes`` for details.
|
||||||
Defaults to 'cv2'.
|
Defaults to 'cv2'.
|
||||||
file_client_args (dict): Arguments to instantiate a FileClient.
|
file_client_args (dict): Arguments to instantiate a FileClient.
|
||||||
See :class:`mmcv.fileio.FileClient` for details.
|
See :class:`mmengine.fileio.FileClient` for details.
|
||||||
Defaults to ``dict(backend='lmdb', db_path='')``.
|
Defaults to ``dict(backend='lmdb', db_path='')``.
|
||||||
ignore_empty (bool): Whether to allow loading empty image or file path
|
ignore_empty (bool): Whether to allow loading empty image or file path
|
||||||
not existent. Defaults to False.
|
not existent. Defaults to False.
|
||||||
@ -490,7 +491,7 @@ class LoadImageFromLMDB(BaseTransform):
|
|||||||
self.color_type = color_type
|
self.color_type = color_type
|
||||||
self.imdecode_backend = imdecode_backend
|
self.imdecode_backend = imdecode_backend
|
||||||
self.file_client_args = file_client_args.copy()
|
self.file_client_args = file_client_args.copy()
|
||||||
self.file_client = mmcv.FileClient(**self.file_client_args)
|
self.file_client = mmengine.FileClient(**self.file_client_args)
|
||||||
|
|
||||||
def transform(self, results: dict) -> Optional[dict]:
|
def transform(self, results: dict) -> Optional[dict]:
|
||||||
"""Functions to load image from LMDB file.
|
"""Functions to load image from LMDB file.
|
||||||
|
@ -3,6 +3,7 @@ import os.path as osp
|
|||||||
from typing import Sequence, Union
|
from typing import Sequence, Union
|
||||||
|
|
||||||
import mmcv
|
import mmcv
|
||||||
|
import mmengine
|
||||||
from mmengine.hooks import Hook
|
from mmengine.hooks import Hook
|
||||||
from mmengine.runner import Runner
|
from mmengine.runner import Runner
|
||||||
from mmengine.visualization import Visualizer
|
from mmengine.visualization import Visualizer
|
||||||
@ -26,7 +27,7 @@ class VisualizationHook(Hook):
|
|||||||
wait_time (float): The interval of show in seconds. Defaults
|
wait_time (float): The interval of show in seconds. Defaults
|
||||||
to 0.
|
to 0.
|
||||||
file_client_args (dict): Arguments to instantiate a FileClient.
|
file_client_args (dict): Arguments to instantiate a FileClient.
|
||||||
See :class:`mmcv.fileio.FileClient` for details.
|
See :class:`mmengine.fileio.FileClient` for details.
|
||||||
Defaults to ``dict(backend='disk')``.
|
Defaults to ``dict(backend='disk')``.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
@ -72,7 +73,7 @@ class VisualizationHook(Hook):
|
|||||||
return
|
return
|
||||||
|
|
||||||
if self.file_client is None:
|
if self.file_client is None:
|
||||||
self.file_client = mmcv.FileClient(**self.file_client_args)
|
self.file_client = mmengine.FileClient(**self.file_client_args)
|
||||||
|
|
||||||
# There is no guarantee that the same batch of images
|
# There is no guarantee that the same batch of images
|
||||||
# is visualized for each evaluation.
|
# is visualized for each evaluation.
|
||||||
@ -113,7 +114,7 @@ class VisualizationHook(Hook):
|
|||||||
return
|
return
|
||||||
|
|
||||||
if self.file_client is None:
|
if self.file_client is None:
|
||||||
self.file_client = mmcv.FileClient(**self.file_client_args)
|
self.file_client = mmengine.FileClient(**self.file_client_args)
|
||||||
|
|
||||||
for output in outputs:
|
for output in outputs:
|
||||||
img_path = output.img_path
|
img_path = output.img_path
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
import warnings
|
import warnings
|
||||||
from typing import Dict, Sequence
|
from typing import Dict, Sequence
|
||||||
|
|
||||||
import mmcv
|
import mmengine
|
||||||
|
|
||||||
from mmocr.utils import is_type_list
|
from mmocr.utils import is_type_list
|
||||||
|
|
||||||
@ -122,7 +122,7 @@ def dump_ocr_data(image_infos: Sequence[Dict], out_json_name: str,
|
|||||||
|
|
||||||
out_json['data_list'].append(single_info)
|
out_json['data_list'].append(single_info)
|
||||||
|
|
||||||
mmcv.dump(out_json, out_json_name)
|
mmengine.dump(out_json, out_json_name)
|
||||||
|
|
||||||
return out_json
|
return out_json
|
||||||
|
|
||||||
|
@ -7,6 +7,7 @@ import warnings
|
|||||||
|
|
||||||
import cv2
|
import cv2
|
||||||
import mmcv
|
import mmcv
|
||||||
|
import mmengine
|
||||||
import numpy as np
|
import numpy as np
|
||||||
import torch
|
import torch
|
||||||
from matplotlib import pyplot as plt
|
from matplotlib import pyplot as plt
|
||||||
@ -884,6 +885,6 @@ def imshow_edge(img,
|
|||||||
'edges': result['edges'].detach().cpu(),
|
'edges': result['edges'].detach().cpu(),
|
||||||
'metas': result['img_metas'][0]
|
'metas': result['img_metas'][0]
|
||||||
}
|
}
|
||||||
mmcv.dump(res_dic, f'{out_file}_res.pkl')
|
mmengine.dump(res_dic, f'{out_file}_res.pkl')
|
||||||
|
|
||||||
return vis_img
|
return vis_img
|
||||||
|
@ -3,7 +3,7 @@ import os.path as osp
|
|||||||
import tempfile
|
import tempfile
|
||||||
from unittest import TestCase
|
from unittest import TestCase
|
||||||
|
|
||||||
import mmcv
|
import mmengine
|
||||||
|
|
||||||
from mmocr.datasets.icdar_dataset import IcdarDataset
|
from mmocr.datasets.icdar_dataset import IcdarDataset
|
||||||
|
|
||||||
@ -116,7 +116,7 @@ class TestIcdarDataset(TestCase):
|
|||||||
categories
|
categories
|
||||||
}
|
}
|
||||||
self.metainfo = dict(CLASSES=('text'))
|
self.metainfo = dict(CLASSES=('text'))
|
||||||
mmcv.dump(fake_json, json_name)
|
mmengine.dump(fake_json, json_name)
|
||||||
|
|
||||||
def test_icdar_dataset(self):
|
def test_icdar_dataset(self):
|
||||||
tmp_dir = tempfile.TemporaryDirectory()
|
tmp_dir = tempfile.TemporaryDirectory()
|
||||||
|
@ -3,7 +3,7 @@ import os.path as osp
|
|||||||
import tempfile
|
import tempfile
|
||||||
from unittest import TestCase
|
from unittest import TestCase
|
||||||
|
|
||||||
import mmcv
|
import mmengine
|
||||||
|
|
||||||
from mmocr.utils.data_converter_utils import (dump_ocr_data,
|
from mmocr.utils.data_converter_utils import (dump_ocr_data,
|
||||||
recog_anno_to_imginfo)
|
recog_anno_to_imginfo)
|
||||||
@ -127,15 +127,15 @@ class TestDataConverterUtils(TestCase):
|
|||||||
self._create_dummy_data()
|
self._create_dummy_data()
|
||||||
|
|
||||||
dump_ocr_data(input_data, output_path, 'textdet')
|
dump_ocr_data(input_data, output_path, 'textdet')
|
||||||
result = mmcv.load(output_path)
|
result = mmengine.load(output_path)
|
||||||
self.assertDictEqual(result, det_target)
|
self.assertDictEqual(result, det_target)
|
||||||
|
|
||||||
dump_ocr_data(input_data, output_path, 'textspotter')
|
dump_ocr_data(input_data, output_path, 'textspotter')
|
||||||
result = mmcv.load(output_path)
|
result = mmengine.load(output_path)
|
||||||
self.assertDictEqual(result, spotter_target)
|
self.assertDictEqual(result, spotter_target)
|
||||||
|
|
||||||
dump_ocr_data(input_data, output_path, 'textrecog')
|
dump_ocr_data(input_data, output_path, 'textrecog')
|
||||||
result = mmcv.load(output_path)
|
result = mmengine.load(output_path)
|
||||||
self.assertDictEqual(result, recog_target)
|
self.assertDictEqual(result, recog_target)
|
||||||
|
|
||||||
def test_recog_anno_to_imginfo(self):
|
def test_recog_anno_to_imginfo(self):
|
||||||
|
@ -4,6 +4,7 @@ import os.path as osp
|
|||||||
from functools import partial
|
from functools import partial
|
||||||
|
|
||||||
import mmcv
|
import mmcv
|
||||||
|
import mmengine
|
||||||
import numpy as np
|
import numpy as np
|
||||||
|
|
||||||
from mmocr.utils import bezier_to_polygon, sort_points
|
from mmocr.utils import bezier_to_polygon, sort_points
|
||||||
@ -104,14 +105,14 @@ def main():
|
|||||||
out_dir = args.out_dir if args.out_dir else root_path
|
out_dir = args.out_dir if args.out_dir else root_path
|
||||||
mmcv.mkdir_or_exist(out_dir)
|
mmcv.mkdir_or_exist(out_dir)
|
||||||
|
|
||||||
anns = mmcv.load(osp.join(root_path, 'train1.json'))
|
anns = mmengine.load(osp.join(root_path, 'train1.json'))
|
||||||
data1 = convert_annotations(anns, 'syntext_word_eng', args.num_sample,
|
data1 = convert_annotations(anns, 'syntext_word_eng', args.num_sample,
|
||||||
args.nproc)
|
args.nproc)
|
||||||
|
|
||||||
# Get the maximum image id from data1
|
# Get the maximum image id from data1
|
||||||
start_img_id = max(data1['images'], key=lambda x: x['id'])['id'] + 1
|
start_img_id = max(data1['images'], key=lambda x: x['id'])['id'] + 1
|
||||||
start_ann_id = max(data1['annotations'], key=lambda x: x['id'])['id'] + 1
|
start_ann_id = max(data1['annotations'], key=lambda x: x['id'])['id'] + 1
|
||||||
anns = mmcv.load(osp.join(root_path, 'train2.json'))
|
anns = mmengine.load(osp.join(root_path, 'train2.json'))
|
||||||
data2 = convert_annotations(
|
data2 = convert_annotations(
|
||||||
anns,
|
anns,
|
||||||
'emcs_imgs',
|
'emcs_imgs',
|
||||||
@ -122,7 +123,7 @@ def main():
|
|||||||
|
|
||||||
data1['images'] += data2['images']
|
data1['images'] += data2['images']
|
||||||
data1['annotations'] += data2['annotations']
|
data1['annotations'] += data2['annotations']
|
||||||
mmcv.dump(data1, osp.join(out_dir, 'instances_training.json'))
|
mmengine.dump(data1, osp.join(out_dir, 'instances_training.json'))
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
@ -7,6 +7,7 @@ import warnings
|
|||||||
from functools import partial
|
from functools import partial
|
||||||
|
|
||||||
import mmcv
|
import mmcv
|
||||||
|
import mmengine
|
||||||
|
|
||||||
from mmocr.utils import list_to_file
|
from mmocr.utils import list_to_file
|
||||||
from mmocr.utils.img_utils import crop_img, warp_img
|
from mmocr.utils.img_utils import crop_img, warp_img
|
||||||
@ -21,7 +22,7 @@ def parse_labelme_json(json_file,
|
|||||||
warp_flag=False):
|
warp_flag=False):
|
||||||
invalid_res = [[], [], []]
|
invalid_res = [[], [], []]
|
||||||
|
|
||||||
json_obj = mmcv.load(json_file)
|
json_obj = mmengine.load(json_file)
|
||||||
|
|
||||||
img_file = osp.basename(json_obj['imagePath'])
|
img_file = osp.basename(json_obj['imagePath'])
|
||||||
img_full_path = osp.join(img_dir, img_file)
|
img_full_path = osp.join(img_dir, img_file)
|
||||||
|
@ -4,6 +4,7 @@ import math
|
|||||||
import os.path as osp
|
import os.path as osp
|
||||||
|
|
||||||
import mmcv
|
import mmcv
|
||||||
|
import mmengine
|
||||||
|
|
||||||
from mmocr.utils import convert_annotations
|
from mmocr.utils import convert_annotations
|
||||||
|
|
||||||
@ -61,7 +62,7 @@ def collect_art_info(root_path, split, ratio, print_every=1000):
|
|||||||
raise Exception(
|
raise Exception(
|
||||||
f'{annotation_path} not exists, please check and try again.')
|
f'{annotation_path} not exists, please check and try again.')
|
||||||
|
|
||||||
annotation = mmcv.load(annotation_path)
|
annotation = mmengine.load(annotation_path)
|
||||||
img_prefixes = annotation.keys()
|
img_prefixes = annotation.keys()
|
||||||
|
|
||||||
trn_files, val_files = [], []
|
trn_files, val_files = [], []
|
||||||
|
@ -2,13 +2,13 @@
|
|||||||
import argparse
|
import argparse
|
||||||
import json
|
import json
|
||||||
|
|
||||||
import mmcv
|
import mmengine
|
||||||
|
|
||||||
from mmocr.utils import list_to_file
|
from mmocr.utils import list_to_file
|
||||||
|
|
||||||
|
|
||||||
def parse_coco_json(in_path):
|
def parse_coco_json(in_path):
|
||||||
json_obj = mmcv.load(in_path)
|
json_obj = mmengine.load(in_path)
|
||||||
image_infos = json_obj['images']
|
image_infos = json_obj['images']
|
||||||
annotations = json_obj['annotations']
|
annotations = json_obj['annotations']
|
||||||
imgid2imgname = {}
|
imgid2imgname = {}
|
||||||
|
@ -3,7 +3,7 @@ import argparse
|
|||||||
import math
|
import math
|
||||||
import os.path as osp
|
import os.path as osp
|
||||||
|
|
||||||
import mmcv
|
import mmengine
|
||||||
|
|
||||||
from mmocr.utils import dump_ocr_data
|
from mmocr.utils import dump_ocr_data
|
||||||
|
|
||||||
@ -66,7 +66,7 @@ def collect_cocotext_info(root_path, split, print_every=1000):
|
|||||||
raise Exception(
|
raise Exception(
|
||||||
f'{annotation_path} not exists, please check and try again.')
|
f'{annotation_path} not exists, please check and try again.')
|
||||||
|
|
||||||
annotation = mmcv.load(annotation_path)
|
annotation = mmengine.load(annotation_path)
|
||||||
|
|
||||||
img_infos = []
|
img_infos = []
|
||||||
for i, img_info in enumerate(annotation['imgs'].values()):
|
for i, img_info in enumerate(annotation['imgs'].values()):
|
||||||
|
@ -4,7 +4,7 @@ from collections import defaultdict
|
|||||||
from copy import deepcopy
|
from copy import deepcopy
|
||||||
from typing import Dict, List
|
from typing import Dict, List
|
||||||
|
|
||||||
import mmcv
|
import mmengine
|
||||||
|
|
||||||
from mmocr.utils import dump_ocr_data
|
from mmocr.utils import dump_ocr_data
|
||||||
|
|
||||||
@ -19,7 +19,7 @@ def parse_coco_json(in_path: str) -> List[Dict]:
|
|||||||
list[dict]: List of image information dicts. To be used by
|
list[dict]: List of image information dicts. To be used by
|
||||||
dump_ocr_data().
|
dump_ocr_data().
|
||||||
"""
|
"""
|
||||||
json_obj = mmcv.load(in_path)
|
json_obj = mmengine.load(in_path)
|
||||||
image_infos = json_obj['images']
|
image_infos = json_obj['images']
|
||||||
annotations = json_obj['annotations']
|
annotations = json_obj['annotations']
|
||||||
imgid2annos = defaultdict(list)
|
imgid2annos = defaultdict(list)
|
||||||
|
@ -5,6 +5,7 @@ import os
|
|||||||
import os.path as osp
|
import os.path as osp
|
||||||
|
|
||||||
import mmcv
|
import mmcv
|
||||||
|
import mmengine
|
||||||
|
|
||||||
from mmocr.utils import dump_ocr_data
|
from mmocr.utils import dump_ocr_data
|
||||||
|
|
||||||
@ -100,7 +101,7 @@ def load_json_info(gt_file, img_info):
|
|||||||
img_info (dict): The dict of the img and annotation information
|
img_info (dict): The dict of the img and annotation information
|
||||||
"""
|
"""
|
||||||
|
|
||||||
annotation = mmcv.load(gt_file)
|
annotation = mmengine.load(gt_file)
|
||||||
anno_info = []
|
anno_info = []
|
||||||
for form in annotation['form']:
|
for form in annotation['form']:
|
||||||
for ann in form['words']:
|
for ann in form['words']:
|
||||||
|
@ -4,6 +4,7 @@ import math
|
|||||||
import os.path as osp
|
import os.path as osp
|
||||||
|
|
||||||
import mmcv
|
import mmcv
|
||||||
|
import mmengine
|
||||||
import numpy as np
|
import numpy as np
|
||||||
|
|
||||||
from mmocr.utils import dump_ocr_data
|
from mmocr.utils import dump_ocr_data
|
||||||
@ -25,7 +26,7 @@ def collect_imgur_info(root_path, annotation_filename, print_every=1000):
|
|||||||
raise Exception(
|
raise Exception(
|
||||||
f'{annotation_path} not exists, please check and try again.')
|
f'{annotation_path} not exists, please check and try again.')
|
||||||
|
|
||||||
annotation = mmcv.load(annotation_path)
|
annotation = mmengine.load(annotation_path)
|
||||||
images = annotation['index_to_ann_map'].keys()
|
images = annotation['index_to_ann_map'].keys()
|
||||||
img_infos = []
|
img_infos = []
|
||||||
for i, img_name in enumerate(images):
|
for i, img_name in enumerate(images):
|
||||||
|
@ -4,6 +4,7 @@ import math
|
|||||||
import os.path as osp
|
import os.path as osp
|
||||||
|
|
||||||
import mmcv
|
import mmcv
|
||||||
|
import mmengine
|
||||||
|
|
||||||
from mmocr.utils import dump_ocr_data
|
from mmocr.utils import dump_ocr_data
|
||||||
|
|
||||||
@ -50,7 +51,7 @@ def collect_lsvt_info(root_path, split, ratio, print_every=1000):
|
|||||||
raise Exception(
|
raise Exception(
|
||||||
f'{annotation_path} not exists, please check and try again.')
|
f'{annotation_path} not exists, please check and try again.')
|
||||||
|
|
||||||
annotation = mmcv.load(annotation_path)
|
annotation = mmengine.load(annotation_path)
|
||||||
img_prefixes = annotation.keys()
|
img_prefixes = annotation.keys()
|
||||||
|
|
||||||
trn_files, val_files = [], []
|
trn_files, val_files = [], []
|
||||||
|
@ -3,6 +3,7 @@ import argparse
|
|||||||
import os.path as osp
|
import os.path as osp
|
||||||
|
|
||||||
import mmcv
|
import mmcv
|
||||||
|
import mmengine
|
||||||
|
|
||||||
from mmocr.utils import dump_ocr_data
|
from mmocr.utils import dump_ocr_data
|
||||||
|
|
||||||
@ -127,7 +128,7 @@ def load_json_info(gt_file, img_info):
|
|||||||
assert isinstance(gt_file, str)
|
assert isinstance(gt_file, str)
|
||||||
assert isinstance(img_info, dict)
|
assert isinstance(img_info, dict)
|
||||||
|
|
||||||
annotation = mmcv.load(gt_file)
|
annotation = mmengine.load(gt_file)
|
||||||
anno_info = []
|
anno_info = []
|
||||||
|
|
||||||
# 'textBBs' contains the printed texts of the table while 'fieldBBs'
|
# 'textBBs' contains the printed texts of the table while 'fieldBBs'
|
||||||
@ -175,7 +176,7 @@ def parse_args():
|
|||||||
def main():
|
def main():
|
||||||
args = parse_args()
|
args = parse_args()
|
||||||
root_path = args.root_path
|
root_path = args.root_path
|
||||||
split_info = mmcv.load(
|
split_info = mmengine.load(
|
||||||
osp.join(root_path, 'annotations', 'train_valid_test_split.json'))
|
osp.join(root_path, 'annotations', 'train_valid_test_split.json'))
|
||||||
split_info['training'] = split_info.pop('train')
|
split_info['training'] = split_info.pop('train')
|
||||||
split_info['val'] = split_info.pop('valid')
|
split_info['val'] = split_info.pop('valid')
|
||||||
|
@ -5,6 +5,7 @@ import os
|
|||||||
import os.path as osp
|
import os.path as osp
|
||||||
|
|
||||||
import mmcv
|
import mmcv
|
||||||
|
import mmengine
|
||||||
|
|
||||||
from mmocr.utils import dump_ocr_data
|
from mmocr.utils import dump_ocr_data
|
||||||
|
|
||||||
@ -142,7 +143,7 @@ def load_json_info(gt_file, img_info):
|
|||||||
img_info (dict): The dict of the img and annotation information
|
img_info (dict): The dict of the img and annotation information
|
||||||
"""
|
"""
|
||||||
|
|
||||||
annotation = mmcv.load(gt_file)
|
annotation = mmengine.load(gt_file)
|
||||||
anno_info = []
|
anno_info = []
|
||||||
for line in annotation['lines']:
|
for line in annotation['lines']:
|
||||||
segmentation = line['points']
|
segmentation = line['points']
|
||||||
|
@ -3,7 +3,7 @@ import argparse
|
|||||||
import math
|
import math
|
||||||
import os.path as osp
|
import os.path as osp
|
||||||
|
|
||||||
import mmcv
|
import mmengine
|
||||||
|
|
||||||
from mmocr.utils import dump_ocr_data
|
from mmocr.utils import dump_ocr_data
|
||||||
|
|
||||||
@ -23,7 +23,7 @@ def collect_textocr_info(root_path, annotation_filename, print_every=1000):
|
|||||||
raise Exception(
|
raise Exception(
|
||||||
f'{annotation_path} not exists, please check and try again.')
|
f'{annotation_path} not exists, please check and try again.')
|
||||||
|
|
||||||
annotation = mmcv.load(annotation_path)
|
annotation = mmengine.load(annotation_path)
|
||||||
|
|
||||||
# img_idx = img_start_idx
|
# img_idx = img_start_idx
|
||||||
img_infos = []
|
img_infos = []
|
||||||
|
@ -4,7 +4,7 @@ import json
|
|||||||
import math
|
import math
|
||||||
import os.path as osp
|
import os.path as osp
|
||||||
|
|
||||||
import mmcv
|
import mmengine
|
||||||
|
|
||||||
from mmocr.utils.fileio import list_to_file
|
from mmocr.utils.fileio import list_to_file
|
||||||
|
|
||||||
@ -63,7 +63,7 @@ def convert_art(root_path, split, ratio, format):
|
|||||||
raise Exception(
|
raise Exception(
|
||||||
f'{annotation_path} not exists, please check and try again.')
|
f'{annotation_path} not exists, please check and try again.')
|
||||||
|
|
||||||
annotation = mmcv.load(annotation_path)
|
annotation = mmengine.load(annotation_path)
|
||||||
# outputs
|
# outputs
|
||||||
dst_label_file = osp.join(root_path, f'{split}_label.{format}')
|
dst_label_file = osp.join(root_path, f'{split}_label.{format}')
|
||||||
|
|
||||||
|
@ -6,6 +6,7 @@ import os.path as osp
|
|||||||
from functools import partial
|
from functools import partial
|
||||||
|
|
||||||
import mmcv
|
import mmcv
|
||||||
|
import mmengine
|
||||||
|
|
||||||
from mmocr.utils.fileio import list_to_file
|
from mmocr.utils.fileio import list_to_file
|
||||||
|
|
||||||
@ -131,7 +132,7 @@ def convert_cocotext(root_path,
|
|||||||
raise Exception(
|
raise Exception(
|
||||||
f'{annotation_path} not exists, please check and try again.')
|
f'{annotation_path} not exists, please check and try again.')
|
||||||
|
|
||||||
annotation = mmcv.load(annotation_path)
|
annotation = mmengine.load(annotation_path)
|
||||||
# outputs
|
# outputs
|
||||||
dst_label_file = osp.join(root_path, f'{split}_label.{format}')
|
dst_label_file = osp.join(root_path, f'{split}_label.{format}')
|
||||||
dst_image_root = osp.join(root_path, 'crops', split)
|
dst_image_root = osp.join(root_path, 'crops', split)
|
||||||
|
@ -6,6 +6,7 @@ import os
|
|||||||
import os.path as osp
|
import os.path as osp
|
||||||
|
|
||||||
import mmcv
|
import mmcv
|
||||||
|
import mmengine
|
||||||
|
|
||||||
from mmocr.utils.fileio import list_to_file
|
from mmocr.utils.fileio import list_to_file
|
||||||
from mmocr.utils.img_utils import crop_img
|
from mmocr.utils.img_utils import crop_img
|
||||||
@ -102,7 +103,7 @@ def load_json_info(gt_file, img_info):
|
|||||||
img_info (dict): The dict of the img and annotation information
|
img_info (dict): The dict of the img and annotation information
|
||||||
"""
|
"""
|
||||||
|
|
||||||
annotation = mmcv.load(gt_file)
|
annotation = mmengine.load(gt_file)
|
||||||
anno_info = []
|
anno_info = []
|
||||||
for form in annotation['form']:
|
for form in annotation['form']:
|
||||||
for ann in form['words']:
|
for ann in form['words']:
|
||||||
|
@ -6,6 +6,7 @@ import os
|
|||||||
import os.path as osp
|
import os.path as osp
|
||||||
|
|
||||||
import mmcv
|
import mmcv
|
||||||
|
import mmengine
|
||||||
import numpy as np
|
import numpy as np
|
||||||
|
|
||||||
from mmocr.utils.fileio import list_to_file
|
from mmocr.utils.fileio import list_to_file
|
||||||
@ -33,7 +34,7 @@ def collect_imgur_info(root_path, annotation_filename, print_every=1000):
|
|||||||
raise Exception(
|
raise Exception(
|
||||||
f'{annotation_path} not exists, please check and try again.')
|
f'{annotation_path} not exists, please check and try again.')
|
||||||
|
|
||||||
annotation = mmcv.load(annotation_path)
|
annotation = mmengine.load(annotation_path)
|
||||||
images = annotation['index_to_ann_map'].keys()
|
images = annotation['index_to_ann_map'].keys()
|
||||||
img_infos = []
|
img_infos = []
|
||||||
for i, img_name in enumerate(images):
|
for i, img_name in enumerate(images):
|
||||||
|
@ -6,6 +6,7 @@ import os.path as osp
|
|||||||
from functools import partial
|
from functools import partial
|
||||||
|
|
||||||
import mmcv
|
import mmcv
|
||||||
|
import mmengine
|
||||||
|
|
||||||
from mmocr.utils.fileio import list_to_file
|
from mmocr.utils.fileio import list_to_file
|
||||||
|
|
||||||
@ -114,7 +115,7 @@ def convert_lsvt(root_path,
|
|||||||
raise Exception(
|
raise Exception(
|
||||||
f'{annotation_path} not exists, please check and try again.')
|
f'{annotation_path} not exists, please check and try again.')
|
||||||
|
|
||||||
annotation = mmcv.load(annotation_path)
|
annotation = mmengine.load(annotation_path)
|
||||||
# outputs
|
# outputs
|
||||||
dst_label_file = osp.join(root_path, f'{split}_label.{format}')
|
dst_label_file = osp.join(root_path, f'{split}_label.{format}')
|
||||||
dst_image_root = osp.join(root_path, 'crops', split)
|
dst_image_root = osp.join(root_path, 'crops', split)
|
||||||
|
@ -4,6 +4,7 @@ import json
|
|||||||
import os.path as osp
|
import os.path as osp
|
||||||
|
|
||||||
import mmcv
|
import mmcv
|
||||||
|
import mmengine
|
||||||
import numpy as np
|
import numpy as np
|
||||||
|
|
||||||
from mmocr.utils.fileio import list_to_file
|
from mmocr.utils.fileio import list_to_file
|
||||||
@ -138,7 +139,7 @@ def load_json_info(gt_file, img_info):
|
|||||||
assert isinstance(gt_file, str)
|
assert isinstance(gt_file, str)
|
||||||
assert isinstance(img_info, dict)
|
assert isinstance(img_info, dict)
|
||||||
|
|
||||||
annotation = mmcv.load(gt_file)
|
annotation = mmengine.load(gt_file)
|
||||||
anno_info = []
|
anno_info = []
|
||||||
|
|
||||||
# 'textBBs' contains the printed texts of the table while 'fieldBBs'
|
# 'textBBs' contains the printed texts of the table while 'fieldBBs'
|
||||||
@ -267,7 +268,7 @@ def parse_args():
|
|||||||
def main():
|
def main():
|
||||||
args = parse_args()
|
args = parse_args()
|
||||||
root_path = args.root_path
|
root_path = args.root_path
|
||||||
split_info = mmcv.load(
|
split_info = mmengine.load(
|
||||||
osp.join(root_path, 'annotations', 'train_valid_test_split.json'))
|
osp.join(root_path, 'annotations', 'train_valid_test_split.json'))
|
||||||
split_info['training'] = split_info.pop('train')
|
split_info['training'] = split_info.pop('train')
|
||||||
split_info['val'] = split_info.pop('valid')
|
split_info['val'] = split_info.pop('valid')
|
||||||
|
@ -6,6 +6,7 @@ from argparse import ArgumentParser
|
|||||||
from functools import partial
|
from functools import partial
|
||||||
|
|
||||||
import mmcv
|
import mmcv
|
||||||
|
import mmengine
|
||||||
from PIL import Image
|
from PIL import Image
|
||||||
|
|
||||||
from mmocr.utils.fileio import list_to_file
|
from mmocr.utils.fileio import list_to_file
|
||||||
@ -67,7 +68,7 @@ def convert_openimages(root_path,
|
|||||||
dst_image_root = osp.join(root_path, dst_image_path)
|
dst_image_root = osp.join(root_path, dst_image_path)
|
||||||
os.makedirs(dst_image_root, exist_ok=True)
|
os.makedirs(dst_image_root, exist_ok=True)
|
||||||
|
|
||||||
annotation = mmcv.load(annotation_path)
|
annotation = mmengine.load(annotation_path)
|
||||||
|
|
||||||
process_img_with_path = partial(
|
process_img_with_path = partial(
|
||||||
process_img,
|
process_img,
|
||||||
|
@ -6,6 +6,7 @@ import os
|
|||||||
import os.path as osp
|
import os.path as osp
|
||||||
|
|
||||||
import mmcv
|
import mmcv
|
||||||
|
import mmengine
|
||||||
|
|
||||||
from mmocr.utils.fileio import list_to_file
|
from mmocr.utils.fileio import list_to_file
|
||||||
from mmocr.utils.img_utils import crop_img
|
from mmocr.utils.img_utils import crop_img
|
||||||
@ -144,7 +145,7 @@ def load_json_info(gt_file, img_info):
|
|||||||
img_info (dict): The dict of the img and annotation information
|
img_info (dict): The dict of the img and annotation information
|
||||||
"""
|
"""
|
||||||
|
|
||||||
annotation = mmcv.load(gt_file)
|
annotation = mmengine.load(gt_file)
|
||||||
anno_info = []
|
anno_info = []
|
||||||
for line in annotation['lines']:
|
for line in annotation['lines']:
|
||||||
if line['ignore'] == 1:
|
if line['ignore'] == 1:
|
||||||
|
@ -6,6 +6,7 @@ import os.path as osp
|
|||||||
from functools import partial
|
from functools import partial
|
||||||
|
|
||||||
import mmcv
|
import mmcv
|
||||||
|
import mmengine
|
||||||
|
|
||||||
from mmocr.utils.fileio import list_to_file
|
from mmocr.utils.fileio import list_to_file
|
||||||
|
|
||||||
@ -63,7 +64,7 @@ def convert_textocr(root_path,
|
|||||||
dst_image_root = osp.join(root_path, dst_image_path)
|
dst_image_root = osp.join(root_path, dst_image_path)
|
||||||
os.makedirs(dst_image_root, exist_ok=True)
|
os.makedirs(dst_image_root, exist_ok=True)
|
||||||
|
|
||||||
annotation = mmcv.load(annotation_path)
|
annotation = mmengine.load(annotation_path)
|
||||||
|
|
||||||
process_img_with_path = partial(
|
process_img_with_path = partial(
|
||||||
process_img,
|
process_img,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user