Skip to content

Commit a757c1b

Browse files
authored
Merge 9fa97fa into df0be64
2 parents df0be64 + 9fa97fa commit a757c1b

File tree

16 files changed

+98
-61
lines changed

16 files changed

+98
-61
lines changed

docs/en/get_started/install.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,6 @@ MMOCR has different version requirements on MMEngine, MMCV and MMDetection at ea
193193

194194
| MMOCR | MMEngine | MMCV | MMDetection |
195195
| -------------- | --------------------------- | -------------------------- | --------------------------- |
196-
| dev-1.x | 0.5.0 \<= mmengine \< 1.0.0 | 2.0.0rc4 \<= mmcv \< 2.1.0 | 3.0.0rc0 \<= mmdet \< 3.1.0 |
196+
| dev-1.x | 0.5.0 \<= mmengine \< 1.0.0 | 2.0.0rc4 \<= mmcv \< 2.1.0 | 3.0.0rc5 \<= mmdet \< 3.1.0 |
197197
| 1.0.0rc\[4-5\] | 0.1.0 \<= mmengine \< 1.0.0 | 2.0.0rc1 \<= mmcv \< 2.1.0 | 3.0.0rc0 \<= mmdet \< 3.1.0 |
198198
| 1.0.0rc\[0-3\] | 0.0.0 \<= mmengine \< 0.2.0 | 2.0.0rc1 \<= mmcv \< 2.1.0 | 3.0.0rc0 \<= mmdet \< 3.1.0 |

docs/zh_cn/get_started/install.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,6 @@ docker run --gpus all --shm-size=8g -it -v {实际数据目录}:/mmocr/data mmoc
194194

195195
| MMOCR | MMEngine | MMCV | MMDetection |
196196
| -------------- | --------------------------- | -------------------------- | --------------------------- |
197-
| dev-1.x | 0.5.0 \<= mmengine \< 1.0.0 | 2.0.0rc4 \<= mmcv \< 2.1.0 | 3.0.0rc0 \<= mmdet \< 3.1.0 |
197+
| dev-1.x | 0.5.0 \<= mmengine \< 1.0.0 | 2.0.0rc4 \<= mmcv \< 2.1.0 | 3.0.0rc5 \<= mmdet \< 3.1.0 |
198198
| 1.0.0rc\[4-5\] | 0.1.0 \<= mmengine \< 1.0.0 | 2.0.0rc1 \<= mmcv \< 2.1.0 | 3.0.0rc0 \<= mmdet \< 3.1.0 |
199199
| 1.0.0rc\[0-3\] | 0.0.0 \<= mmengine \< 0.2.0 | 2.0.0rc1 \<= mmcv \< 2.1.0 | 3.0.0rc0 \<= mmdet \< 3.1.0 |

mmocr/__init__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141
f'Please install mmengine>={mmengine_minimum_version}, ' \
4242
f'<{mmengine_maximum_version}.'
4343

44-
mmdet_minimum_version = '3.0.0rc0'
44+
mmdet_minimum_version = '3.0.0rc5'
4545
mmdet_maximum_version = '3.1.0'
4646
mmdet_version = digit_version(mmdet.__version__)
4747

mmocr/apis/inferencers/base_mmocr_inferencer.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,11 @@
77
import numpy as np
88
from mmengine.dataset import Compose
99
from mmengine.infer.infer import BaseInferencer, ModelType
10+
from mmengine.registry import init_default_scope
1011
from mmengine.structures import InstanceData
1112
from torch import Tensor
1213

13-
from mmocr.utils import ConfigType, register_all_modules
14+
from mmocr.utils import ConfigType
1415

1516
InstanceList = List[InstanceData]
1617
InputType = Union[str, np.ndarray]
@@ -58,7 +59,7 @@ def __init__(self,
5859
# A global counter tracking the number of images processed, for
5960
# naming of the output images
6061
self.num_visualized_imgs = 0
61-
register_all_modules()
62+
init_default_scope(scope)
6263
super().__init__(
6364
model=model, weights=weights, device=device, scope=scope)
6465

mmocr/registry.py

+73-21
Original file line numberDiff line numberDiff line change
@@ -32,51 +32,103 @@
3232
from mmengine.registry import Registry
3333

3434
# manage all kinds of runners like `EpochBasedRunner` and `IterBasedRunner`
35-
RUNNERS = Registry('runner', parent=MMENGINE_RUNNERS)
35+
RUNNERS = Registry(
36+
'runner',
37+
parent=MMENGINE_RUNNERS,
38+
# TODO: update the location when mmocr has its own runner
39+
locations=['mmocr.engine'])
3640
# manage runner constructors that define how to initialize runners
3741
RUNNER_CONSTRUCTORS = Registry(
38-
'runner constructor', parent=MMENGINE_RUNNER_CONSTRUCTORS)
42+
'runner constructor',
43+
parent=MMENGINE_RUNNER_CONSTRUCTORS,
44+
# TODO: update the location when mmocr has its own runner constructor
45+
locations=['mmocr.engine'])
3946
# manage all kinds of loops like `EpochBasedTrainLoop`
40-
LOOPS = Registry('loop', parent=MMENGINE_LOOPS)
47+
LOOPS = Registry(
48+
'loop',
49+
parent=MMENGINE_LOOPS,
50+
# TODO: update the location when mmocr has its own loop
51+
locations=['mmocr.engine'])
4152
# manage all kinds of hooks like `CheckpointHook`
42-
HOOKS = Registry('hook', parent=MMENGINE_HOOKS)
53+
HOOKS = Registry(
54+
'hook', parent=MMENGINE_HOOKS, locations=['mmocr.engine.hooks'])
4355

4456
# manage data-related modules
45-
DATASETS = Registry('dataset', parent=MMENGINE_DATASETS)
46-
DATA_SAMPLERS = Registry('data sampler', parent=MMENGINE_DATA_SAMPLERS)
47-
TRANSFORMS = Registry('transform', parent=MMENGINE_TRANSFORMS)
57+
DATASETS = Registry(
58+
'dataset', parent=MMENGINE_DATASETS, locations=['mmocr.datasets'])
59+
DATA_SAMPLERS = Registry(
60+
'data sampler',
61+
parent=MMENGINE_DATA_SAMPLERS,
62+
locations=['mmocr.datasets.samplers'])
63+
TRANSFORMS = Registry(
64+
'transform',
65+
parent=MMENGINE_TRANSFORMS,
66+
locations=['mmocr.datasets.transforms'])
4867

4968
# manage all kinds of modules inheriting `nn.Module`
50-
MODELS = Registry('model', parent=MMENGINE_MODELS)
69+
MODELS = Registry('model', parent=MMENGINE_MODELS, locations=['mmocr.models'])
5170
# manage all kinds of model wrappers like 'MMDistributedDataParallel'
52-
MODEL_WRAPPERS = Registry('model_wrapper', parent=MMENGINE_MODEL_WRAPPERS)
71+
MODEL_WRAPPERS = Registry(
72+
'model wrapper',
73+
parent=MMENGINE_MODEL_WRAPPERS,
74+
locations=['mmocr.models'])
5375
# manage all kinds of weight initialization modules like `Uniform`
5476
WEIGHT_INITIALIZERS = Registry(
55-
'weight initializer', parent=MMENGINE_WEIGHT_INITIALIZERS)
77+
'weight initializer',
78+
parent=MMENGINE_WEIGHT_INITIALIZERS,
79+
locations=['mmocr.models'])
5680

5781
# manage all kinds of optimizers like `SGD` and `Adam`
58-
OPTIMIZERS = Registry('optimizer', parent=MMENGINE_OPTIMIZERS)
82+
OPTIMIZERS = Registry(
83+
'optimizer',
84+
parent=MMENGINE_OPTIMIZERS,
85+
# TODO: update the location when mmocr has its own optimizer
86+
locations=['mmocr.engine'])
5987
# manage optimizer wrapper
60-
OPTIM_WRAPPERS = Registry('optim wrapper', parent=MMENGINE_OPTIM_WRAPPERS)
88+
OPTIM_WRAPPERS = Registry(
89+
'optimizer wrapper',
90+
parent=MMENGINE_OPTIM_WRAPPERS,
91+
# TODO: update the location when mmocr has its own optimizer wrapper
92+
locations=['mmocr.engine'])
6193
# manage constructors that customize the optimization hyperparameters.
6294
OPTIM_WRAPPER_CONSTRUCTORS = Registry(
63-
'optimizer constructor', parent=MMENGINE_OPTIM_WRAPPER_CONSTRUCTORS)
95+
'optimizer constructor',
96+
parent=MMENGINE_OPTIM_WRAPPER_CONSTRUCTORS,
97+
# TODO: update the location when mmocr has its own optimizer constructor
98+
locations=['mmocr.engine'])
6499
# manage all kinds of parameter schedulers like `MultiStepLR`
65100
PARAM_SCHEDULERS = Registry(
66-
'parameter scheduler', parent=MMENGINE_PARAM_SCHEDULERS)
67-
101+
'parameter scheduler',
102+
parent=MMENGINE_PARAM_SCHEDULERS,
103+
# TODO: update the location when mmocr has its own parameter scheduler
104+
locations=['mmocr.engine'])
68105
# manage all kinds of metrics
69-
METRICS = Registry('metric', parent=MMENGINE_METRICS)
106+
METRICS = Registry(
107+
'metric', parent=MMENGINE_METRICS, locations=['mmocr.evaluation.metrics'])
70108
# manage evaluator
71-
EVALUATOR = Registry('evaluator', parent=MMENGINE_EVALUATOR)
109+
EVALUATOR = Registry(
110+
'evaluator',
111+
parent=MMENGINE_EVALUATOR,
112+
locations=['mmocr.evaluation.evaluator'])
72113

73114
# manage task-specific modules like anchor generators and box coders
74-
TASK_UTILS = Registry('task util', parent=MMENGINE_TASK_UTILS)
115+
TASK_UTILS = Registry(
116+
'task util', parent=MMENGINE_TASK_UTILS, locations=['mmocr.models'])
75117

76118
# manage visualizer
77-
VISUALIZERS = Registry('visualizer', parent=MMENGINE_VISUALIZERS)
119+
VISUALIZERS = Registry(
120+
'visualizer',
121+
parent=MMENGINE_VISUALIZERS,
122+
locations=['mmocr.visualization'])
78123
# manage visualizer backend
79-
VISBACKENDS = Registry('vis_backend', parent=MMENGINE_VISBACKENDS)
124+
VISBACKENDS = Registry(
125+
'visualizer backend',
126+
parent=MMENGINE_VISBACKENDS,
127+
locations=['mmocr.visualization'])
80128

81129
# manage logprocessor
82-
LOG_PROCESSORS = Registry('log_processor', parent=MMENGINE_LOG_PROCESSORS)
130+
LOG_PROCESSORS = Registry(
131+
'logger processor',
132+
parent=MMENGINE_LOG_PROCESSORS,
133+
# TODO: update the location when mmocr has its own log processor
134+
locations=['mmocr.engine'])

requirements/mminstall.txt

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
mmcv>==2.0.0rc1,<2.1.0
2-
mmdet>=3.0.0rc0,<3.1.0
3-
mmengine>= 0.1.0, <1.0.0
1+
mmcv>==2.0.0rc4,<2.1.0
2+
mmdet>=3.0.0rc5,<3.1.0
3+
mmengine>= 0.5.0, <1.0.0

tests/test_datasets/test_dataset_wrapper.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,10 @@
44
from unittest import TestCase
55
from unittest.mock import MagicMock
66

7+
from mmengine.registry import init_default_scope
8+
79
from mmocr.datasets import ConcatDataset, OCRDataset
810
from mmocr.registry import TRANSFORMS
9-
from mmocr.utils import register_all_modules
1011

1112

1213
class TestConcatDataset(TestCase):
@@ -22,7 +23,7 @@ def __call__(self, *args, **kwargs):
2223

2324
def setUp(self):
2425

25-
register_all_modules()
26+
init_default_scope('mmocr')
2627
dataset = OCRDataset
2728

2829
# create dataset_a

tests/test_models/test_textdet/test_detectors/test_drrg.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,19 @@
77
import numpy as np
88
import torch
99
from mmengine.config import Config, ConfigDict
10+
from mmengine.registry import init_default_scope
1011

1112
from mmocr.registry import MODELS
1213
from mmocr.testing.data import create_dummy_textdet_inputs
13-
from mmocr.utils import register_all_modules
1414

1515

1616
class TestDRRG(unittest.TestCase):
1717

1818
def setUp(self):
1919
cfg_path = 'textdet/drrg/drrg_resnet50_fpn-unet_1200e_ctw1500.py'
2020
self.model_cfg = self._get_detector_cfg(cfg_path)
21-
register_all_modules()
21+
cfg = self._get_config_module(cfg_path)
22+
init_default_scope(cfg.get('default_scope', 'mmocr'))
2223
self.model = MODELS.build(self.model_cfg)
2324
self.inputs = create_dummy_textdet_inputs(input_shape=(1, 3, 224, 224))
2425

tests/test_models/test_textdet/test_wrappers/test_mmdet_wrapper.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,17 @@
55
from mmdet.structures import DetDataSample
66
from mmdet.testing import demo_mm_inputs
77
from mmengine.config import Config
8+
from mmengine.registry import init_default_scope
89
from mmengine.structures import InstanceData
910

1011
from mmocr.registry import MODELS
1112
from mmocr.structures import TextDetDataSample
12-
from mmocr.utils import register_all_modules
1313

1414

1515
class TestMMDetWrapper(unittest.TestCase):
1616

1717
def setUp(self):
18-
register_all_modules()
18+
init_default_scope('mmocr')
1919
model_cfg_fcos = dict(
2020
type='MMDetWrapper',
2121
cfg=dict(

tests/test_models/test_textrecog/test_backbones/test_resnet.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,16 @@
22
from unittest import TestCase
33

44
import torch
5+
from mmengine.registry import init_default_scope
56

67
from mmocr.models.textrecog.backbones import ResNet
7-
from mmocr.utils import register_all_modules
88

99

1010
class TestResNet(TestCase):
1111

1212
def setUp(self) -> None:
1313
self.img = torch.rand(1, 3, 32, 100)
14-
register_all_modules()
14+
init_default_scope('mmocr')
1515

1616
def test_resnet45_aster(self):
1717
resnet45_aster = ResNet(

tools/analysis_tools/browse_dataset.py

+2-3
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,11 @@
99
import numpy as np
1010
from mmengine.config import Config, DictAction
1111
from mmengine.dataset import Compose
12+
from mmengine.registry import init_default_scope
1213
from mmengine.utils import ProgressBar
1314
from mmengine.visualization import Visualizer
1415

1516
from mmocr.registry import DATASETS, VISUALIZERS
16-
from mmocr.utils import register_all_modules
1717

1818

1919
# TODO: Support for printing the change in key of results
@@ -331,8 +331,7 @@ def main():
331331
if args.cfg_options is not None:
332332
cfg.merge_from_dict(args.cfg_options)
333333

334-
# register all modules in mmyolo into the registries
335-
register_all_modules()
334+
init_default_scope(cfg.get('default_scope', 'mmocr'))
336335

337336
dataset_cfg, visualizer_cfg = obtain_dataset_cfg(cfg, args.phase,
338337
args.mode, args.task)

tools/analysis_tools/get_flops.py

+2-3
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,9 @@
44
import torch
55
from fvcore.nn import FlopCountAnalysis, flop_count_table
66
from mmengine import Config
7+
from mmengine.registry import init_default_scope
78

89
from mmocr.registry import MODELS
9-
from mmocr.utils import register_all_modules
10-
11-
register_all_modules()
1210

1311

1412
def parse_args():
@@ -38,6 +36,7 @@ def main():
3836
input_shape = (1, 3, h, w)
3937

4038
cfg = Config.fromfile(args.config)
39+
init_default_scope(cfg.get('default_scope', 'mmocr'))
4140
model = MODELS.build(cfg.model)
4241

4342
flops = FlopCountAnalysis(model, torch.ones(input_shape))

tools/analysis_tools/offline_eval.py

+2-4
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,7 @@
55
import mmengine
66
from mmengine.config import Config, DictAction
77
from mmengine.evaluator import Evaluator
8-
9-
from mmocr.utils import register_all_modules
8+
from mmengine.registry import init_default_scope
109

1110

1211
def parse_args():
@@ -33,10 +32,9 @@ def parse_args():
3332
def main():
3433
args = parse_args()
3534

36-
register_all_modules()
37-
3835
# load config
3936
cfg = Config.fromfile(args.config)
37+
init_default_scope(cfg.get('default_scope', 'mmocr'))
4038
if args.cfg_options is not None:
4139
cfg.merge_from_dict(args.cfg_options)
4240

tools/dataset_converters/prepare_dataset.py

-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
import warnings
55

66
from mmocr.datasets.preparers import DatasetPreparer
7-
from mmocr.utils import register_all_modules
87

98

109
def parse_args():
@@ -39,7 +38,6 @@ def parse_args():
3938

4039
def main():
4140
args = parse_args()
42-
register_all_modules()
4341
for dataset in args.datasets:
4442
if not osp.isdir(osp.join(args.dataset_zoo_path, dataset)):
4543
warnings.warn(f'{dataset} is not supported yet. Please check '

tools/test.py

-6
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@
77
from mmengine.registry import RUNNERS
88
from mmengine.runner import Runner
99

10-
from mmocr.utils import register_all_modules
11-
1210

1311
def parse_args():
1412
parser = argparse.ArgumentParser(description='Test (and eval) a model')
@@ -80,10 +78,6 @@ def trigger_visualization_hook(cfg, args):
8078
def main():
8179
args = parse_args()
8280

83-
# register all modules in mmocr into the registries
84-
# do not init the default scope here because it will be init in the runner
85-
register_all_modules(init_default_scope=False)
86-
8781
# load config
8882
cfg = Config.fromfile(args.config)
8983
cfg.launcher = args.launcher

tools/train.py

-6
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@
99
from mmengine.registry import RUNNERS
1010
from mmengine.runner import Runner
1111

12-
from mmocr.utils import register_all_modules
13-
1412

1513
def parse_args():
1614
parser = argparse.ArgumentParser(description='Train a model')
@@ -54,10 +52,6 @@ def parse_args():
5452
def main():
5553
args = parse_args()
5654

57-
# register all modules in mmdet into the registries
58-
# do not init the default scope here because it will be init in the runner
59-
register_all_modules(init_default_scope=False)
60-
6155
# load config
6256
cfg = Config.fromfile(args.config)
6357
cfg.launcher = args.launcher

0 commit comments

Comments
 (0)