diff --git a/mmocr/datasets/transforms/loading.py b/mmocr/datasets/transforms/loading.py index 611ff71e..05450322 100644 --- a/mmocr/datasets/transforms/loading.py +++ b/mmocr/datasets/transforms/loading.py @@ -5,6 +5,7 @@ import warnings from typing import Optional import mmcv +import mmengine import numpy as np from mmcv.transforms import BaseTransform from mmcv.transforms import LoadAnnotations as MMCV_LoadAnnotations @@ -38,7 +39,7 @@ class LoadImageFromFile(MMCV_LoadImageFromFile): See :func:``mmcv.imfrombytes`` for details. Defaults to 'cv2'. 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')``. ignore_empty (bool): Whether to allow loading empty image or file path not existent. Defaults to False. @@ -59,7 +60,7 @@ class LoadImageFromFile(MMCV_LoadImageFromFile): self.color_type = color_type self.imdecode_backend = imdecode_backend 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 def transform(self, results: dict) -> Optional[dict]: @@ -473,7 +474,7 @@ class LoadImageFromLMDB(BaseTransform): See :func:``mmcv.imfrombytes`` for details. Defaults to 'cv2'. 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='')``. ignore_empty (bool): Whether to allow loading empty image or file path not existent. Defaults to False. @@ -490,7 +491,7 @@ class LoadImageFromLMDB(BaseTransform): self.color_type = color_type self.imdecode_backend = imdecode_backend 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]: """Functions to load image from LMDB file. diff --git a/mmocr/engine/hooks/visualization_hook.py b/mmocr/engine/hooks/visualization_hook.py index 5c183d1f..0b52d4ea 100644 --- a/mmocr/engine/hooks/visualization_hook.py +++ b/mmocr/engine/hooks/visualization_hook.py @@ -3,6 +3,7 @@ import os.path as osp from typing import Sequence, Union import mmcv +import mmengine from mmengine.hooks import Hook from mmengine.runner import Runner from mmengine.visualization import Visualizer @@ -26,7 +27,7 @@ class VisualizationHook(Hook): wait_time (float): The interval of show in seconds. Defaults to 0. 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')``. """ @@ -72,7 +73,7 @@ class VisualizationHook(Hook): return 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 # is visualized for each evaluation. @@ -113,7 +114,7 @@ class VisualizationHook(Hook): return 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: img_path = output.img_path diff --git a/mmocr/utils/data_converter_utils.py b/mmocr/utils/data_converter_utils.py index 0f959de7..38cbd703 100644 --- a/mmocr/utils/data_converter_utils.py +++ b/mmocr/utils/data_converter_utils.py @@ -2,7 +2,7 @@ import warnings from typing import Dict, Sequence -import mmcv +import mmengine 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) - mmcv.dump(out_json, out_json_name) + mmengine.dump(out_json, out_json_name) return out_json diff --git a/mmocr/visualization/visualize.py b/mmocr/visualization/visualize.py index 8b451d9d..a8af6f34 100644 --- a/mmocr/visualization/visualize.py +++ b/mmocr/visualization/visualize.py @@ -7,6 +7,7 @@ import warnings import cv2 import mmcv +import mmengine import numpy as np import torch from matplotlib import pyplot as plt @@ -884,6 +885,6 @@ def imshow_edge(img, 'edges': result['edges'].detach().cpu(), '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 diff --git a/tests/test_datasets/test_icdar_dataset.py b/tests/test_datasets/test_icdar_dataset.py index 5a304e35..d4b3b544 100644 --- a/tests/test_datasets/test_icdar_dataset.py +++ b/tests/test_datasets/test_icdar_dataset.py @@ -3,7 +3,7 @@ import os.path as osp import tempfile from unittest import TestCase -import mmcv +import mmengine from mmocr.datasets.icdar_dataset import IcdarDataset @@ -116,7 +116,7 @@ class TestIcdarDataset(TestCase): categories } self.metainfo = dict(CLASSES=('text')) - mmcv.dump(fake_json, json_name) + mmengine.dump(fake_json, json_name) def test_icdar_dataset(self): tmp_dir = tempfile.TemporaryDirectory() diff --git a/tests/test_utils/test_data_converter_utils.py b/tests/test_utils/test_data_converter_utils.py index e1806d88..eb258ef5 100644 --- a/tests/test_utils/test_data_converter_utils.py +++ b/tests/test_utils/test_data_converter_utils.py @@ -3,7 +3,7 @@ import os.path as osp import tempfile from unittest import TestCase -import mmcv +import mmengine from mmocr.utils.data_converter_utils import (dump_ocr_data, recog_anno_to_imginfo) @@ -127,15 +127,15 @@ class TestDataConverterUtils(TestCase): self._create_dummy_data() dump_ocr_data(input_data, output_path, 'textdet') - result = mmcv.load(output_path) + result = mmengine.load(output_path) self.assertDictEqual(result, det_target) dump_ocr_data(input_data, output_path, 'textspotter') - result = mmcv.load(output_path) + result = mmengine.load(output_path) self.assertDictEqual(result, spotter_target) dump_ocr_data(input_data, output_path, 'textrecog') - result = mmcv.load(output_path) + result = mmengine.load(output_path) self.assertDictEqual(result, recog_target) def test_recog_anno_to_imginfo(self): diff --git a/tools/dataset_converters/common/curvedsyntext_converter.py b/tools/dataset_converters/common/curvedsyntext_converter.py index ddffd50e..f125787c 100644 --- a/tools/dataset_converters/common/curvedsyntext_converter.py +++ b/tools/dataset_converters/common/curvedsyntext_converter.py @@ -4,6 +4,7 @@ import os.path as osp from functools import partial import mmcv +import mmengine import numpy as np 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 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, args.nproc) # Get the maximum image id from data1 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 - anns = mmcv.load(osp.join(root_path, 'train2.json')) + anns = mmengine.load(osp.join(root_path, 'train2.json')) data2 = convert_annotations( anns, 'emcs_imgs', @@ -122,7 +123,7 @@ def main(): data1['images'] += data2['images'] 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__': diff --git a/tools/dataset_converters/common/labelme_converter.py b/tools/dataset_converters/common/labelme_converter.py index 0497c1ee..58ae17b0 100644 --- a/tools/dataset_converters/common/labelme_converter.py +++ b/tools/dataset_converters/common/labelme_converter.py @@ -7,6 +7,7 @@ import warnings from functools import partial import mmcv +import mmengine from mmocr.utils import list_to_file from mmocr.utils.img_utils import crop_img, warp_img @@ -21,7 +22,7 @@ def parse_labelme_json(json_file, warp_flag=False): invalid_res = [[], [], []] - json_obj = mmcv.load(json_file) + json_obj = mmengine.load(json_file) img_file = osp.basename(json_obj['imagePath']) img_full_path = osp.join(img_dir, img_file) diff --git a/tools/dataset_converters/textdet/art_converter.py b/tools/dataset_converters/textdet/art_converter.py index 950da5a9..9d3b6a25 100644 --- a/tools/dataset_converters/textdet/art_converter.py +++ b/tools/dataset_converters/textdet/art_converter.py @@ -4,6 +4,7 @@ import math import os.path as osp import mmcv +import mmengine from mmocr.utils import convert_annotations @@ -61,7 +62,7 @@ def collect_art_info(root_path, split, ratio, print_every=1000): raise Exception( f'{annotation_path} not exists, please check and try again.') - annotation = mmcv.load(annotation_path) + annotation = mmengine.load(annotation_path) img_prefixes = annotation.keys() trn_files, val_files = [], [] diff --git a/tools/dataset_converters/textdet/coco_to_line_dict.py b/tools/dataset_converters/textdet/coco_to_line_dict.py index b8d0583e..7dcb5edb 100644 --- a/tools/dataset_converters/textdet/coco_to_line_dict.py +++ b/tools/dataset_converters/textdet/coco_to_line_dict.py @@ -2,13 +2,13 @@ import argparse import json -import mmcv +import mmengine from mmocr.utils import list_to_file def parse_coco_json(in_path): - json_obj = mmcv.load(in_path) + json_obj = mmengine.load(in_path) image_infos = json_obj['images'] annotations = json_obj['annotations'] imgid2imgname = {} diff --git a/tools/dataset_converters/textdet/cocotext_converter.py b/tools/dataset_converters/textdet/cocotext_converter.py index b3956e7c..e4ef78ee 100644 --- a/tools/dataset_converters/textdet/cocotext_converter.py +++ b/tools/dataset_converters/textdet/cocotext_converter.py @@ -3,7 +3,7 @@ import argparse import math import os.path as osp -import mmcv +import mmengine from mmocr.utils import dump_ocr_data @@ -66,7 +66,7 @@ def collect_cocotext_info(root_path, split, print_every=1000): raise Exception( f'{annotation_path} not exists, please check and try again.') - annotation = mmcv.load(annotation_path) + annotation = mmengine.load(annotation_path) img_infos = [] for i, img_info in enumerate(annotation['imgs'].values()): diff --git a/tools/dataset_converters/textdet/data_migrator.py b/tools/dataset_converters/textdet/data_migrator.py index 0930b898..38da8a04 100644 --- a/tools/dataset_converters/textdet/data_migrator.py +++ b/tools/dataset_converters/textdet/data_migrator.py @@ -4,7 +4,7 @@ from collections import defaultdict from copy import deepcopy from typing import Dict, List -import mmcv +import mmengine 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 dump_ocr_data(). """ - json_obj = mmcv.load(in_path) + json_obj = mmengine.load(in_path) image_infos = json_obj['images'] annotations = json_obj['annotations'] imgid2annos = defaultdict(list) diff --git a/tools/dataset_converters/textdet/funsd_converter.py b/tools/dataset_converters/textdet/funsd_converter.py index a6f3487b..dbb91bc7 100644 --- a/tools/dataset_converters/textdet/funsd_converter.py +++ b/tools/dataset_converters/textdet/funsd_converter.py @@ -5,6 +5,7 @@ import os import os.path as osp import mmcv +import mmengine 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 """ - annotation = mmcv.load(gt_file) + annotation = mmengine.load(gt_file) anno_info = [] for form in annotation['form']: for ann in form['words']: diff --git a/tools/dataset_converters/textdet/imgur_converter.py b/tools/dataset_converters/textdet/imgur_converter.py index 1012f9af..272ec35d 100644 --- a/tools/dataset_converters/textdet/imgur_converter.py +++ b/tools/dataset_converters/textdet/imgur_converter.py @@ -4,6 +4,7 @@ import math import os.path as osp import mmcv +import mmengine import numpy as np from mmocr.utils import dump_ocr_data @@ -25,7 +26,7 @@ def collect_imgur_info(root_path, annotation_filename, print_every=1000): raise Exception( 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() img_infos = [] for i, img_name in enumerate(images): diff --git a/tools/dataset_converters/textdet/lsvt_converter.py b/tools/dataset_converters/textdet/lsvt_converter.py index 11fc25e7..aa44d106 100644 --- a/tools/dataset_converters/textdet/lsvt_converter.py +++ b/tools/dataset_converters/textdet/lsvt_converter.py @@ -4,6 +4,7 @@ import math import os.path as osp import mmcv +import mmengine from mmocr.utils import dump_ocr_data @@ -50,7 +51,7 @@ def collect_lsvt_info(root_path, split, ratio, print_every=1000): raise Exception( f'{annotation_path} not exists, please check and try again.') - annotation = mmcv.load(annotation_path) + annotation = mmengine.load(annotation_path) img_prefixes = annotation.keys() trn_files, val_files = [], [] diff --git a/tools/dataset_converters/textdet/naf_converter.py b/tools/dataset_converters/textdet/naf_converter.py index c4c5a5ea..92817639 100644 --- a/tools/dataset_converters/textdet/naf_converter.py +++ b/tools/dataset_converters/textdet/naf_converter.py @@ -3,6 +3,7 @@ import argparse import os.path as osp import mmcv +import mmengine 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(img_info, dict) - annotation = mmcv.load(gt_file) + annotation = mmengine.load(gt_file) anno_info = [] # 'textBBs' contains the printed texts of the table while 'fieldBBs' @@ -175,7 +176,7 @@ def parse_args(): def main(): args = parse_args() root_path = args.root_path - split_info = mmcv.load( + split_info = mmengine.load( osp.join(root_path, 'annotations', 'train_valid_test_split.json')) split_info['training'] = split_info.pop('train') split_info['val'] = split_info.pop('valid') diff --git a/tools/dataset_converters/textdet/rects_converter.py b/tools/dataset_converters/textdet/rects_converter.py index d4cd247d..16971a77 100644 --- a/tools/dataset_converters/textdet/rects_converter.py +++ b/tools/dataset_converters/textdet/rects_converter.py @@ -5,6 +5,7 @@ import os import os.path as osp import mmcv +import mmengine 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 """ - annotation = mmcv.load(gt_file) + annotation = mmengine.load(gt_file) anno_info = [] for line in annotation['lines']: segmentation = line['points'] diff --git a/tools/dataset_converters/textdet/textocr_converter.py b/tools/dataset_converters/textdet/textocr_converter.py index 378749e5..67a8e32f 100644 --- a/tools/dataset_converters/textdet/textocr_converter.py +++ b/tools/dataset_converters/textdet/textocr_converter.py @@ -3,7 +3,7 @@ import argparse import math import os.path as osp -import mmcv +import mmengine from mmocr.utils import dump_ocr_data @@ -23,7 +23,7 @@ def collect_textocr_info(root_path, annotation_filename, print_every=1000): raise Exception( 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_infos = [] diff --git a/tools/dataset_converters/textrecog/art_converter.py b/tools/dataset_converters/textrecog/art_converter.py index 8e47aca5..fa182db3 100644 --- a/tools/dataset_converters/textrecog/art_converter.py +++ b/tools/dataset_converters/textrecog/art_converter.py @@ -4,7 +4,7 @@ import json import math import os.path as osp -import mmcv +import mmengine from mmocr.utils.fileio import list_to_file @@ -63,7 +63,7 @@ def convert_art(root_path, split, ratio, format): raise Exception( f'{annotation_path} not exists, please check and try again.') - annotation = mmcv.load(annotation_path) + annotation = mmengine.load(annotation_path) # outputs dst_label_file = osp.join(root_path, f'{split}_label.{format}') diff --git a/tools/dataset_converters/textrecog/cocotext_converter.py b/tools/dataset_converters/textrecog/cocotext_converter.py index e2fb4d4b..335bbea8 100644 --- a/tools/dataset_converters/textrecog/cocotext_converter.py +++ b/tools/dataset_converters/textrecog/cocotext_converter.py @@ -6,6 +6,7 @@ import os.path as osp from functools import partial import mmcv +import mmengine from mmocr.utils.fileio import list_to_file @@ -131,7 +132,7 @@ def convert_cocotext(root_path, raise Exception( f'{annotation_path} not exists, please check and try again.') - annotation = mmcv.load(annotation_path) + annotation = mmengine.load(annotation_path) # outputs dst_label_file = osp.join(root_path, f'{split}_label.{format}') dst_image_root = osp.join(root_path, 'crops', split) diff --git a/tools/dataset_converters/textrecog/funsd_converter.py b/tools/dataset_converters/textrecog/funsd_converter.py index e5aa35a6..bc8c357f 100644 --- a/tools/dataset_converters/textrecog/funsd_converter.py +++ b/tools/dataset_converters/textrecog/funsd_converter.py @@ -6,6 +6,7 @@ import os import os.path as osp import mmcv +import mmengine from mmocr.utils.fileio import list_to_file 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 """ - annotation = mmcv.load(gt_file) + annotation = mmengine.load(gt_file) anno_info = [] for form in annotation['form']: for ann in form['words']: diff --git a/tools/dataset_converters/textrecog/imgur_converter.py b/tools/dataset_converters/textrecog/imgur_converter.py index 3d29d109..fbccc391 100644 --- a/tools/dataset_converters/textrecog/imgur_converter.py +++ b/tools/dataset_converters/textrecog/imgur_converter.py @@ -6,6 +6,7 @@ import os import os.path as osp import mmcv +import mmengine import numpy as np 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( 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() img_infos = [] for i, img_name in enumerate(images): diff --git a/tools/dataset_converters/textrecog/lsvt_converter.py b/tools/dataset_converters/textrecog/lsvt_converter.py index 465b3359..f3243cd1 100644 --- a/tools/dataset_converters/textrecog/lsvt_converter.py +++ b/tools/dataset_converters/textrecog/lsvt_converter.py @@ -6,6 +6,7 @@ import os.path as osp from functools import partial import mmcv +import mmengine from mmocr.utils.fileio import list_to_file @@ -114,7 +115,7 @@ def convert_lsvt(root_path, raise Exception( f'{annotation_path} not exists, please check and try again.') - annotation = mmcv.load(annotation_path) + annotation = mmengine.load(annotation_path) # outputs dst_label_file = osp.join(root_path, f'{split}_label.{format}') dst_image_root = osp.join(root_path, 'crops', split) diff --git a/tools/dataset_converters/textrecog/naf_converter.py b/tools/dataset_converters/textrecog/naf_converter.py index 9815580a..867f5859 100644 --- a/tools/dataset_converters/textrecog/naf_converter.py +++ b/tools/dataset_converters/textrecog/naf_converter.py @@ -4,6 +4,7 @@ import json import os.path as osp import mmcv +import mmengine import numpy as np 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(img_info, dict) - annotation = mmcv.load(gt_file) + annotation = mmengine.load(gt_file) anno_info = [] # 'textBBs' contains the printed texts of the table while 'fieldBBs' @@ -267,7 +268,7 @@ def parse_args(): def main(): args = parse_args() root_path = args.root_path - split_info = mmcv.load( + split_info = mmengine.load( osp.join(root_path, 'annotations', 'train_valid_test_split.json')) split_info['training'] = split_info.pop('train') split_info['val'] = split_info.pop('valid') diff --git a/tools/dataset_converters/textrecog/openvino_converter.py b/tools/dataset_converters/textrecog/openvino_converter.py index 6c00d802..0ac38910 100644 --- a/tools/dataset_converters/textrecog/openvino_converter.py +++ b/tools/dataset_converters/textrecog/openvino_converter.py @@ -6,6 +6,7 @@ from argparse import ArgumentParser from functools import partial import mmcv +import mmengine from PIL import Image 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) 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, diff --git a/tools/dataset_converters/textrecog/rects_converter.py b/tools/dataset_converters/textrecog/rects_converter.py index d83d4a2d..6a1d1e78 100644 --- a/tools/dataset_converters/textrecog/rects_converter.py +++ b/tools/dataset_converters/textrecog/rects_converter.py @@ -6,6 +6,7 @@ import os import os.path as osp import mmcv +import mmengine from mmocr.utils.fileio import list_to_file 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 """ - annotation = mmcv.load(gt_file) + annotation = mmengine.load(gt_file) anno_info = [] for line in annotation['lines']: if line['ignore'] == 1: diff --git a/tools/dataset_converters/textrecog/textocr_converter.py b/tools/dataset_converters/textrecog/textocr_converter.py index 2c161788..19fe907c 100644 --- a/tools/dataset_converters/textrecog/textocr_converter.py +++ b/tools/dataset_converters/textrecog/textocr_converter.py @@ -6,6 +6,7 @@ import os.path as osp from functools import partial import mmcv +import mmengine 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) 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,