From 3f24e34a5d6cc9ec1f14a23e54c937b3f56e6ec9 Mon Sep 17 00:00:00 2001 From: gaotongxiao Date: Wed, 11 May 2022 14:33:29 +0800 Subject: [PATCH] remove some deprecated files causing import errors --- mmocr/datasets/__init__.py | 13 +-- mmocr/datasets/pipelines/__init__.py | 19 ++-- .../pipelines/custom_format_bundle.py | 66 -------------- mmocr/datasets/pipelines/kie_transforms.py | 89 +++++++++---------- 4 files changed, 60 insertions(+), 127 deletions(-) delete mode 100644 mmocr/datasets/pipelines/custom_format_bundle.py diff --git a/mmocr/datasets/__init__.py b/mmocr/datasets/__init__.py index ac121774..4910eb44 100644 --- a/mmocr/datasets/__init__.py +++ b/mmocr/datasets/__init__.py @@ -1,23 +1,24 @@ # Copyright (c) OpenMMLab. All rights reserved. from . import utils from .base_dataset import BaseDataset -from .builder import DATASETS, LOADERS, PARSERS, TRANSFORMS +from .builder import LOADERS, PARSERS, TRANSFORMS from .icdar_dataset import IcdarDataset +# TODO: check this from .kie_dataset import KIEDataset from .ner_dataset import NerDataset from .ocr_dataset import OCRDataset from .ocr_seg_dataset import OCRSegDataset from .openset_kie_dataset import OpensetKIEDataset -from .pipelines import CustomFormatBundle, DBNetTargets, FCENetTargets +from .pipelines import DBNetTargets, FCENetTargets from .text_det_dataset import TextDetDataset from .uniform_concat_dataset import UniformConcatDataset from .utils import * # NOQA __all__ = [ - 'DATASETS', 'IcdarDataset', 'BaseDataset', 'OCRDataset', 'TextDetDataset', - 'CustomFormatBundle', 'DBNetTargets', 'OCRSegDataset', 'KIEDataset', - 'FCENetTargets', 'NerDataset', 'UniformConcatDataset', 'OpensetKIEDataset', - 'TRANSFORMS', 'PARSERS', 'LOADERS' + 'IcdarDataset', 'BaseDataset', 'OCRDataset', 'TextDetDataset', + 'KIEDataset', 'DBNetTargets', 'OCRSegDataset', 'FCENetTargets', + 'NerDataset', 'UniformConcatDataset', 'OpensetKIEDataset', 'TRANSFORMS', + 'PARSERS', 'LOADERS' ] __all__ += utils.__all__ diff --git a/mmocr/datasets/pipelines/__init__.py b/mmocr/datasets/pipelines/__init__.py index 8f28304d..54c70262 100644 --- a/mmocr/datasets/pipelines/__init__.py +++ b/mmocr/datasets/pipelines/__init__.py @@ -1,8 +1,7 @@ # Copyright (c) OpenMMLab. All rights reserved. from .box_utils import sort_vertex, sort_vertex8 -from .custom_format_bundle import CustomFormatBundle from .dbnet_transforms import EastRandomCrop, ImgAug -from .kie_transforms import KIEFormatBundle, ResizeNoImg +from .kie_transforms import ResizeNoImg from .loading import (LoadImageFromLMDB, LoadImageFromNdarray, LoadTextAnnotations) from .ner_transforms import NerTransform, ToTensorNER @@ -21,14 +20,14 @@ from .transforms import (ColorJitter, PyramidRescale, RandomCropFlip, __all__ = [ 'LoadTextAnnotations', 'NormalizeOCR', 'OnlineCropOCR', 'ResizeOCR', - 'ToTensorOCR', 'CustomFormatBundle', 'DBNetTargets', 'PANetTargets', - 'ColorJitter', 'RandomCropInstances', 'RandomRotateTextDet', - 'ScaleAspectJitter', 'MultiRotateAugOCR', 'OCRSegTargets', 'FancyPCA', + 'ToTensorOCR', 'DBNetTargets', 'PANetTargets', 'ColorJitter', + 'RandomCropInstances', 'RandomRotateTextDet', 'ScaleAspectJitter', + 'MultiRotateAugOCR', 'OCRSegTargets', 'FancyPCA', 'RandomCropPolyInstances', 'RandomRotatePolyInstances', 'RandomPaddingOCR', 'ImgAug', 'EastRandomCrop', 'RandomRotateImageBox', 'OpencvToPil', - 'PilToOpencv', 'KIEFormatBundle', 'SquareResizePad', 'TextSnakeTargets', - 'sort_vertex', 'LoadImageFromNdarray', 'sort_vertex8', 'FCENetTargets', - 'RandomScaling', 'RandomCropFlip', 'NerTransform', 'ToTensorNER', - 'ResizeNoImg', 'PyramidRescale', 'OneOfWrapper', 'RandomWrapper', - 'TorchVisionWrapper', 'LoadImageFromLMDB' + 'PilToOpencv', 'SquareResizePad', 'TextSnakeTargets', 'sort_vertex', + 'LoadImageFromNdarray', 'sort_vertex8', 'FCENetTargets', 'RandomScaling', + 'RandomCropFlip', 'NerTransform', 'ToTensorNER', 'ResizeNoImg', + 'PyramidRescale', 'OneOfWrapper', 'RandomWrapper', 'TorchVisionWrapper', + 'LoadImageFromLMDB' ] diff --git a/mmocr/datasets/pipelines/custom_format_bundle.py b/mmocr/datasets/pipelines/custom_format_bundle.py deleted file mode 100644 index 59bc1f16..00000000 --- a/mmocr/datasets/pipelines/custom_format_bundle.py +++ /dev/null @@ -1,66 +0,0 @@ -# Copyright (c) OpenMMLab. All rights reserved. -import numpy as np -from mmcv.parallel import DataContainer as DC -from mmdet.datasets.pipelines.formatting import DefaultFormatBundle - -from mmocr.core.visualize import overlay_mask_img, show_feature -from mmocr.registry import TRANSFORMS - - -@TRANSFORMS.register_module() -class CustomFormatBundle(DefaultFormatBundle): - """Custom formatting bundle. - - It formats common fields such as 'img' and 'proposals' as done in - DefaultFormatBundle, while other fields such as 'gt_kernels' and - 'gt_effective_region_mask' will be formatted to DC as follows: - - - gt_kernels: to DataContainer (cpu_only=True) - - gt_effective_mask: to DataContainer (cpu_only=True) - - Args: - keys (list[str]): Fields to be formatted to DC only. - call_super (bool): If True, format common fields - by DefaultFormatBundle, else format fields in keys above only. - visualize (dict): If flag=True, visualize gt mask for debugging. - """ - - def __init__(self, - keys=[], - call_super=True, - visualize=dict(flag=False, boundary_key=None)): - - super().__init__() - self.visualize = visualize - self.keys = keys - self.call_super = call_super - - def __call__(self, results): - - if self.visualize['flag']: - img = results['img'].astype(np.uint8) - boundary_key = self.visualize['boundary_key'] - if boundary_key is not None: - img = overlay_mask_img(img, results[boundary_key].masks[0]) - - features = [img] - names = ['img'] - to_uint8 = [1] - - for k in results['mask_fields']: - for iter in range(len(results[k].masks)): - features.append(results[k].masks[iter]) - names.append(k + str(iter)) - to_uint8.append(0) - show_feature(features, names, to_uint8) - - if self.call_super: - results = super().__call__(results) - - for k in self.keys: - results[k] = DC(results[k], cpu_only=True) - - return results - - def __repr__(self): - return self.__class__.__name__ diff --git a/mmocr/datasets/pipelines/kie_transforms.py b/mmocr/datasets/pipelines/kie_transforms.py index e8b7ba68..2bfea409 100644 --- a/mmocr/datasets/pipelines/kie_transforms.py +++ b/mmocr/datasets/pipelines/kie_transforms.py @@ -1,8 +1,6 @@ # Copyright (c) OpenMMLab. All rights reserved. import numpy as np from mmcv import rescale_size -from mmcv.parallel import DataContainer as DC -from mmdet.datasets.pipelines.formatting import DefaultFormatBundle, to_tensor from mmocr.registry import TRANSFORMS @@ -40,52 +38,53 @@ class ResizeNoImg: return results -@TRANSFORMS.register_module() -class KIEFormatBundle(DefaultFormatBundle): - """Key information extraction formatting bundle. +# @TRANSFORMS.register_module() +# class KIEFormatBundle(DefaultFormatBundle): +# """Key information extraction formatting bundle. - Based on the DefaultFormatBundle, itt simplifies the pipeline of formatting - common fields, including "img", "proposals", "gt_bboxes", "gt_labels", - "gt_masks", "gt_semantic_seg", "relations" and "texts". - These fields are formatted as follows. +# Based on the DefaultFormatBundle, itt simplifies the pipeline of +# formatting +# common fields, including "img", "proposals", "gt_bboxes", "gt_labels", +# "gt_masks", "gt_semantic_seg", "relations" and "texts". +# These fields are formatted as follows. - - img: (1) transpose, (2) to tensor, (3) to DataContainer (stack=True) - - proposals: (1) to tensor, (2) to DataContainer - - gt_bboxes: (1) to tensor, (2) to DataContainer - - gt_bboxes_ignore: (1) to tensor, (2) to DataContainer - - gt_labels: (1) to tensor, (2) to DataContainer - - gt_masks: (1) to tensor, (2) to DataContainer (cpu_only=True) - - gt_semantic_seg: (1) unsqueeze dim-0 (2) to tensor, - (3) to DataContainer (stack=True) - - relations: (1) scale, (2) to tensor, (3) to DataContainer - - texts: (1) to tensor, (2) to DataContainer - """ +# - img: (1) transpose, (2) to tensor, (3) to DataContainer (stack=True) +# - proposals: (1) to tensor, (2) to DataContainer +# - gt_bboxes: (1) to tensor, (2) to DataContainer +# - gt_bboxes_ignore: (1) to tensor, (2) to DataContainer +# - gt_labels: (1) to tensor, (2) to DataContainer +# - gt_masks: (1) to tensor, (2) to DataContainer (cpu_only=True) +# - gt_semantic_seg: (1) unsqueeze dim-0 (2) to tensor, +# (3) to DataContainer (stack=True) +# - relations: (1) scale, (2) to tensor, (3) to DataContainer +# - texts: (1) to tensor, (2) to DataContainer +# """ - def __call__(self, results): - """Call function to transform and format common fields in results. +# def __call__(self, results): +# """Call function to transform and format common fields in results. - Args: - results (dict): Result dict contains the data to convert. +# Args: +# results (dict): Result dict contains the data to convert. - Returns: - dict: The result dict contains the data that is formatted with - default bundle. - """ - super().__call__(results) - if 'ann_info' in results: - for key in ['relations', 'texts']: - value = results['ann_info'][key] - if key == 'relations' and 'scale_factor' in results: - scale_factor = results['scale_factor'] - if isinstance(scale_factor, float): - sx = sy = scale_factor - else: - sx, sy = results['scale_factor'][:2] - r = sx / sy - factor = np.array([sx, sy, r, 1, r]).astype(np.float32) - value = value * factor[None, None] - results[key] = DC(to_tensor(value)) - return results +# Returns: +# dict: The result dict contains the data that is formatted with +# default bundle. +# """ +# super().__call__(results) +# if 'ann_info' in results: +# for key in ['relations', 'texts']: +# value = results['ann_info'][key] +# if key == 'relations' and 'scale_factor' in results: +# scale_factor = results['scale_factor'] +# if isinstance(scale_factor, float): +# sx = sy = scale_factor +# else: +# sx, sy = results['scale_factor'][:2] +# r = sx / sy +# factor = np.array([sx, sy, r, 1, r]).astype(np.float32) +# value = value * factor[None, None] +# results[key] = DC(to_tensor(value)) +# return results - def __repr__(self): - return self.__class__.__name__ +# def __repr__(self): +# return self.__class__.__name__