Skip to content

Commit 7f4a1ee

Browse files
authored
abcnetv2 inference (#1657)
* abcnetv2 inference * update readme
1 parent 6992923 commit 7f4a1ee

File tree

11 files changed

+591
-13
lines changed

11 files changed

+591
-13
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,7 @@ Supported algorithms:
171171
<summary>Text Spotting</summary>
172172

173173
- [x] [ABCNet](projects/ABCNet/README.md) (CVPR'2020)
174+
- [x] [ABCNetV2](projects/ABCNet/README_V2.md) (TPAMI'2021)
174175

175176
</details>
176177

README_zh-CN.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,7 @@ pip3 install -e .
171171
<summary>端对端 OCR</summary>
172172

173173
- [x] [ABCNet](projects/ABCNet/README.md) (CVPR'2020)
174+
- [x] [ABCNetV2](projects/ABCNet/README_V2.md) (TPAMI'2021)
174175

175176
</details>
176177

projects/ABCNet/README.md

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -44,14 +44,6 @@ ln -s ${DataPath} $PYTHONPATH
4444
New-Item -ItemType SymbolicLink -Path $env:PYTHONPATH -Name data -Target ${DataPath}
4545
```
4646

47-
As of now, `BezierAlign` is not yet supported by MMCV, and we will use third-party MMCV with the implementation of `BezierAlign`. You will need to install it from the source code as follows:
48-
49-
```bash
50-
git clone -b lkk/bezier_align https://github.com/Harold-lkk/mmcv.git
51-
cd mmcv
52-
MMCV_WITH_OPS=1 MAX_JOBS=8 python setup.py develop
53-
```
54-
5547
### Training commands
5648

5749
In the current directory, run the following command to train the model:
@@ -95,7 +87,6 @@ If you find ABCNet useful in your research or applications, please cite ABCNet w
9587
booktitle = {Proc. IEEE Conf. Computer Vision and Pattern Recognition (CVPR)},
9688
year = {2020}
9789
}
98-
9990
```
10091

10192
## Checklist

projects/ABCNet/README_V2.md

Lines changed: 137 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,137 @@
1+
# ABCNet: Real-time Scene Text Spotting with Adaptive Bezier-Curve Network
2+
3+
<div>
4+
<a href="https://arxiv.org/abs/2105.03620">[arXiv paper]</a>
5+
<a href="https://ieeexplore.ieee.org/document/9525302">[TPAMI paper]</a>
6+
</div>
7+
8+
## Description
9+
10+
This is an implementation of [ABCNetV2](https://github.com/aim-uofa/AdelaiDet) based on [MMOCR](https://github.com/open-mmlab/mmocr/tree/dev-1.x), [MMCV](https://github.com/open-mmlab/mmcv), and [MMEngine](https://github.com/open-mmlab/mmengine).
11+
12+
**ABCNetV2** contributions are four-fold: 1) For the first time, we adaptively fit arbitrarily-shaped text by a parameterized Bezier curve, which, compared with segmentation-based methods, can not only provide structured output but also controllable representation. 2) We design a novel BezierAlign layer for extracting accurate convolution features of a text instance of arbitrary shapes, significantly improving the precision of recognition over previous methods. 3) Different from previous methods, which often suffer from complex post-processing and sensitive hyper-parameters, our ABCNet v2 maintains a simple pipeline with the only post-processing non-maximum suppression (NMS). 4) As the performance of text recognition closely depends on feature alignment, ABCNet v2 further adopts a simple yet effective coordinate convolution to encode the position of the convolutional filters, which leads to a considerable improvement with negligible computation overhead. Comprehensive experiments conducted on various bilingual (English and Chinese) benchmark datasets demonstrate that ABCNet v2 can achieve state-of-the-art performance while maintaining very high efficiency.
13+
14+
<center>
15+
<img src="https://user-images.githubusercontent.com/24622904/213096846-2557e0ac-ca18-4c4f-88c1-569107f48f9b.png">
16+
</center>
17+
18+
## Usage
19+
20+
<!-- For a typical model, this section should contain the commands for training and testing. You are also suggested to dump your environment specification to env.yml by `conda env export > env.yml`. -->
21+
22+
### Prerequisites
23+
24+
- Python 3.7
25+
- PyTorch 1.6 or higher
26+
- [MIM](https://github.com/open-mmlab/mim)
27+
- [MMOCR](https://github.com/open-mmlab/mmocr)
28+
29+
All the commands below rely on the correct configuration of `PYTHONPATH`, which should point to the project's directory so that Python can locate the module files. In `ABCNet/` root directory, run the following line to add the current directory to `PYTHONPATH`:
30+
31+
```shell
32+
# Linux
33+
export PYTHONPATH=`pwd`:$PYTHONPATH
34+
# Windows PowerShell
35+
$env:PYTHONPATH=Get-Location
36+
```
37+
38+
if the data is not in `ABCNet/`, you can link the data into `ABCNet/`:
39+
40+
```shell
41+
# Linux
42+
ln -s ${DataPath} $PYTHONPATH
43+
# Windows PowerShell
44+
New-Item -ItemType SymbolicLink -Path $env:PYTHONPATH -Name data -Target ${DataPath}
45+
```
46+
47+
### Testing commands
48+
49+
In the current directory, run the following command to test the model:
50+
51+
```bash
52+
mim test mmocr config/abcnet_v2/abcnet-v2_resnet50_bifpn_500e_icdar2015.py --work-dir work_dirs/ --checkpoint ${CHECKPOINT_PATH}
53+
```
54+
55+
## Results
56+
57+
Here we provide the baseline version of ABCNet with ResNet50 backbone.
58+
59+
To find more variants, please visit the [official model zoo](https://github.com/aim-uofa/AdelaiDet/blob/master/configs/BAText/README.md).
60+
61+
| Name | Pretrained Model | E2E-None-Hmean | det-Hmean | Download |
62+
| :-------------------: | :--------------: | :------------: | :-------: | :------------------------------------------------------------------------------------------------------------------------------------------: |
63+
| v2-icdar2015-finetune | SynthText | 0.6628 | 0.8886 | [model](https://download.openmmlab.com/mmocr/textspotting/abcnet-v2/abcnet-v2_resnet50_bifpn/abcnet-v2_resnet50_bifpn_500e_icdar2015-5e4cc7ed.pth) |
64+
65+
## Citation
66+
67+
If you find ABCNetV2 useful in your research or applications, please cite ABCNetV2 with the following BibTeX entry.
68+
69+
```BibTeX
70+
@ARTICLE{9525302,
71+
author={Liu, Yuliang and Shen, Chunhua and Jin, Lianwen and He, Tong and Chen, Peng and Liu, Chongyu and Chen, Hao},
72+
journal={IEEE Transactions on Pattern Analysis and Machine Intelligence},
73+
title={ABCNet v2: Adaptive Bezier-Curve Network for Real-time End-to-end Text Spotting},
74+
year={2021},
75+
volume={},
76+
number={},
77+
pages={1-1},
78+
doi={10.1109/TPAMI.2021.3107437}}
79+
```
80+
81+
## Checklist
82+
83+
<!-- Here is a checklist illustrating a usual development workflow of a successful project, and also serves as an overview of this project's progress. The PIC (person in charge) or contributors of this project should check all the items that they believe have been finished, which will further be verified by codebase maintainers via a PR.
84+
85+
OpenMMLab's maintainer will review the code to ensure the project's quality. Reaching the first milestone means that this project suffices the minimum requirement of being merged into 'projects/'. But this project is only eligible to become a part of the core package upon attaining the last milestone.
86+
87+
Note that keeping this section up-to-date is crucial not only for this project's developers but the entire community, since there might be some other contributors joining this project and deciding their starting point from this list. It also helps maintainers accurately estimate time and effort on further code polishing, if needed.
88+
89+
A project does not necessarily have to be finished in a single PR, but it's essential for the project to at least reach the first milestone in its very first PR. -->
90+
91+
- [x] Milestone 1: PR-ready, and acceptable to be one of the `projects/`.
92+
93+
- [x] Finish the code
94+
95+
<!-- The code's design shall follow existing interfaces and convention. For example, each model component should be registered into `mmocr.registry.MODELS` and configurable via a config file. -->
96+
97+
- [x] Basic docstrings & proper citation
98+
99+
<!-- Each major object should contain a docstring, describing its functionality and arguments. If you have adapted the code from other open-source projects, don't forget to cite the source project in docstring and make sure your behavior is not against its license. Typically, we do not accept any code snippet under GPL license. [A Short Guide to Open Source Licenses](https://medium.com/nationwide-technology/a-short-guide-to-open-source-licenses-cf5b1c329edd) -->
100+
101+
- [x] Test-time correctness
102+
103+
<!-- If you are reproducing the result from a paper, make sure your model's inference-time performance matches that in the original paper. The weights usually could be obtained by simply renaming the keys in the official pre-trained weights. This test could be skipped though, if you are able to prove the training-time correctness and check the second milestone. -->
104+
105+
- [x] A full README
106+
107+
<!-- As this template does. -->
108+
109+
- [ ] Milestone 2: Indicates a successful model implementation.
110+
111+
- [ ] Training-time correctness
112+
113+
<!-- If you are reproducing the result from a paper, checking this item means that you should have trained your model from scratch based on the original paper's specification and verified that the final result matches the report within a minor error range. -->
114+
115+
- [ ] Milestone 3: Good to be a part of our core package!
116+
117+
- [ ] Type hints and docstrings
118+
119+
<!-- Ideally *all* the methods should have [type hints](https://www.pythontutorial.net/python-basics/python-type-hints/) and [docstrings](https://google.github.io/styleguide/pyguide.html#381-docstrings). [Example](https://github.com/open-mmlab/mmocr/blob/76637a290507f151215d299707c57cea5120976e/mmocr/utils/polygon_utils.py#L80-L96) -->
120+
121+
- [ ] Unit tests
122+
123+
<!-- Unit tests for each module are required. [Example](https://github.com/open-mmlab/mmocr/blob/76637a290507f151215d299707c57cea5120976e/tests/test_utils/test_polygon_utils.py#L97-L106) -->
124+
125+
- [ ] Code polishing
126+
127+
<!-- Refactor your code according to reviewer's comment. -->
128+
129+
- [ ] Metafile.yml
130+
131+
<!-- It will be parsed by MIM and Inferencer. [Example](https://github.com/open-mmlab/mmocr/blob/1.x/configs/textdet/dbnet/metafile.yml) -->
132+
133+
- [ ] Move your modules into the core package following the codebase's file hierarchy structure.
134+
135+
<!-- In particular, you may have to refactor this README into a standard one. [Example](/configs/textdet/dbnet/README.md) -->
136+
137+
- [ ] Refactor your modules into the core package following the codebase's file hierarchy structure.

projects/ABCNet/abcnet/model/__init__.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,13 @@
99
from .abcnet_rec_decoder import ABCNetRecDecoder
1010
from .abcnet_rec_encoder import ABCNetRecEncoder
1111
from .bezier_roi_extractor import BezierRoIExtractor
12+
from .bifpn import BiFPN
13+
from .coordinate_head import CoordinateHead
1214
from .rec_roi_head import RecRoIHead
1315

1416
__all__ = [
1517
'ABCNetDetHead', 'ABCNetDetPostprocessor', 'ABCNetRecBackbone',
1618
'ABCNetRecDecoder', 'ABCNetRecEncoder', 'ABCNet', 'ABCNetRec',
1719
'BezierRoIExtractor', 'RecRoIHead', 'ABCNetPostprocessor',
18-
'ABCNetDetModuleLoss'
20+
'ABCNetDetModuleLoss', 'BiFPN', 'CoordinateHead'
1921
]

projects/ABCNet/abcnet/model/abcnet_rec_backbone.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,7 @@ def __init__(self, init_cfg=None):
4646
stride=(2, 1),
4747
bias='auto',
4848
norm_cfg=dict(type='GN', num_groups=32),
49-
act_cfg=dict(type='ReLU')),
50-
nn.AvgPool2d(kernel_size=(2, 1), stride=1))
49+
act_cfg=dict(type='ReLU')), nn.AdaptiveAvgPool2d((1, None)))
5150

5251
def forward(self, x):
5352
return self.convs(x)

0 commit comments

Comments
 (0)