Skip to content

Commit

Permalink
Merge pull request #342 from breezedeus/dev
Browse files Browse the repository at this point in the history
Integrated latest PPOCRv4 models based on RapidOCR for faster inference
  • Loading branch information
breezedeus authored Nov 30, 2024
2 parents efc5373 + 579dc4d commit e61f84b
Show file tree
Hide file tree
Showing 23 changed files with 571 additions and 162 deletions.
50 changes: 50 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
.idea/.gitignore
.idea/crnn-mxnet-chinese-text-recognition.iml
.idea/git_toolbox_blame.xml
.idea/git_toolbox_prj.xml
.idea/misc.xml
.idea/modules.xml
.idea/vcs.xml
.idea/dictionaries/king.xml
.idea/inspectionProfiles/Project_Default.xml
.pytest_cache/v/cache/lastfailed
.pytest_cache/v/cache/nodeids
.pytest_cache/v/cache/stepwise
.streamlit/*
.ropeproject/*
*/__pycache__/*
*/*/__pycache__/*
*/*/*/__pycache__/*
dist/*
build/*
predict-result*/*
eval_results/*
*/*.pyc
*.ckpt
*/*.ckpt
inference/*
runs/*
s1/*
tmp*/*
wandb/*
debug*/*
docs/fonts/*
docs/predict-outputs/*
data/*
*.onnx
*.jpg
*.png
*.jpeg
*.gif
*.zip
*.pyo
*.pyc
*.egg-info
fonts/*
cnocr.egg-info/dependency_links.txt
cnocr.egg-info/entry_points.txt
cnocr.egg-info/not-zip-safe
cnocr.egg-info/PKG-INFO
cnocr.egg-info/requires.txt
cnocr.egg-info/SOURCES.txt
cnocr.egg-info/top_level.txt
22 changes: 19 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,16 @@
---
</div>

### [Update 2024.11.28]:发布 V2.3.1

主要变更:

* 基于 RapidOCR 集成 PPOCRv4 最新版 OCR 模型,提供更多的模型选择
* 新增支持 PP-OCRv4 识别模型,包括标准版和服务器版
* 修改读文件实现方式,支持 Windows 的中文路径
* 修复Bug:当使用多个进程时,transform_func 无法序列化
* 修复Bug:与 albumentations=1.4.* 兼容

### [Update 2023.12.24]:发布 V2.3

主要变更:
Expand Down Expand Up @@ -376,13 +386,13 @@ print(ocr_out)
| ------------------------------------------------------------ | ------------ | --------- | ------------ | ------------ | ------------------------------ | -------------------- |
| db_shufflenet_v2 || X | cnocr | 18 M | 简体中文、繁体中文、英文、数字 ||
| **db_shufflenet_v2_small** || X | cnocr | 12 M | 简体中文、繁体中文、英文、数字 ||
| [db_shufflenet_v2_tiny](https://mp.weixin.qq.com/s/fHPNoGyo72EFApVhEgR6Nw) || X | cnocr | 7.5 M | 简体中文、繁体中文、英文、数字 ||
| db_mobilenet_v3 || X | cnocr | 16 M | 简体中文、繁体中文、英文、数字 ||
| db_mobilenet_v3_small || X | cnocr | 7.9 M | 简体中文、繁体中文、英文、数字 ||
| db_resnet34 || X | cnocr | 86 M | 简体中文、繁体中文、英文、数字 ||
| db_resnet18 || X | cnocr | 47 M | 简体中文、繁体中文、英文、数字 ||
| ch_PP-OCRv4_det | X || ppocr | 4.5 M | 简体中文、繁体中文、英文、数字 ||
| ch_PP-OCRv4_det_server | X || ppocr | 108 M | 简体中文、繁体中文、英文、数字 ||
| ch_PP-OCRv3_det | X || ppocr | 2.3 M | 简体中文、繁体中文、英文、数字 ||
| ch_PP-OCRv2_det | X || ppocr | 2.2 M | 简体中文、繁体中文、英文、数字 ||
| **en_PP-OCRv3_det** | X || ppocr | 2.3 M | **英文**、数字 ||


Expand Down Expand Up @@ -419,11 +429,18 @@ print(ocr_out)
| **number-densenet_lite_136-fc** 🆕 ||| cnocr | 2.7 M | **纯数字**(仅包含 `0~9` 十个数字) | X |
| **number-densenet_lite_136-gru** 🆕 <br /> ([星球会员](https://t.zsxq.com/FEYZRJQ)专享) ||| cnocr | 5.5 M | **纯数字**(仅包含 `0~9` 十个数字) | X |
| **number-densenet_lite_666-gru_large** 🆕 <br />(购买链接:[B站](https://gf.bilibili.com/item/detail/1104055055)[Lemon Squeezy](https://ocr.lemonsqueezy.com/)||| cnocr | 55 M | **纯数字**(仅包含 `0~9` 十个数字) | X |
| ch_PP-OCRv4 | X || ppocr | 10 M | 简体中文、英文、数字 ||
| ch_PP-OCRv4_server | X || ppocr | 86 M | 简体中文、英文、数字 ||
| ch_PP-OCRv3 | X || ppocr | 10 M | 简体中文、英文、数字 ||
| ch_ppocr_mobile_v2.0 | X || ppocr | 4.2 M | 简体中文、英文、数字 ||
| en_PP-OCRv4 | X || ppocr | 8.6 M | **英文**、数字 ||
| en_PP-OCRv3 | X || ppocr | 8.5 M | **英文**、数字 ||
| en_number_mobile_v2.0 | X || ppocr | 1.8 M | **英文**、数字 ||
| chinese_cht_PP-OCRv3 | X || ppocr | 11 M | **繁体中文**、英文、数字 | X |
| japan_PP-OCRv3 | X || ppocr | 9.6 M | **日文**、英文、数字 ||
| korean_PP-OCRv3 | X || ppocr | 9.4 M | **韩文**、英文、数字 ||
| latin_PP-OCRv3 | X || ppocr | 8.6 M | **拉丁文**、英文、数字 ||
| arabic_PP-OCRv3 | X || ppocr | 8.6 M | **阿拉伯文**、英文、数字 ||



Expand Down Expand Up @@ -452,4 +469,3 @@ print(ocr_out)
---

官方代码库:[https://github.com/breezedeus/cnocr](https://github.com/breezedeus/cnocr)

32 changes: 24 additions & 8 deletions README_en.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,16 @@
---
</div>

### [Update 2024.11.28]: Release of V2.3.1

Major Changes:

* Based on RapidOCR, integrate the latest version of PPOCRv4 OCR models, providing more model options
* Add support for PP-OCRv4 recognition models, including standard and server versions
* Modify the implementation of reading files to support Chinese paths on Windows
* Fix bug: When using multiple processes, the transform_func cannot be serialized
* Fix bug: Compatible with albumentations=1.4.*

### [Update 2023.12.24]: Release of V2.3

Major Changes:
Expand Down Expand Up @@ -300,13 +310,13 @@ Refer to [CnSTD](https://github.com/breezedeus/CnSTD?tab=readme-ov-file#%E5%B7%B
| **en_PP-OCRv3_det** | X || ppocr | 2.3 M | **English**、Numbers ||
| db_shufflenet_v2 || X | cnocr | 18 M | Simplified Chinese, Traditional Chinese, English, Numbers ||
| **db_shufflenet_v2_small** || X | cnocr | 12 M | Simplified Chinese, Traditional Chinese, English, Numbers ||
| [db_shufflenet_v2_tiny](https://mp.weixin.qq.com/s/fHPNoGyo72EFApVhEgR6Nw) || X | cnocr | 7.5 M | Simplified Chinese, Traditional Chinese, English, Numbers ||
| db_mobilenet_v3 || X | cnocr | 16 M | Simplified Chinese, Traditional Chinese, English, Numbers ||
| db_mobilenet_v3_small || X | cnocr | 7.9 M | Simplified Chinese, Traditional Chinese, English, Numbers ||
| db_resnet34 || X | cnocr | 86 M | Simplified Chinese, Traditional Chinese, English, Numbers ||
| db_resnet18 || X | cnocr | 47 M | Simplified Chinese, Traditional Chinese, English, Numbers ||
| ch_PP-OCRv4_det | X || ppocr | 4.5 M | Simplified Chinese, Traditional Chinese, English, Numbers ||
| ch_PP-OCRv4_det_server | X || ppocr | 108 M | Simplified Chinese, Traditional Chinese, English, Numbers ||
| ch_PP-OCRv3_det | X || ppocr | 2.3 M | Simplified Chinese, Traditional Chinese, English, Numbers ||
| ch_PP-OCRv2_det | X || ppocr | 2.2 M | Simplified Chinese, Traditional Chinese, English, Numbers ||



Expand Down Expand Up @@ -342,12 +352,18 @@ For more details, see: [Available Models](https://cnocr.readthedocs.io/zh-cn/sta
| **number-densenet_lite_136-fc** 🆕 ||| cnocr | 2.7 M | **Pure Numeric** (contains only the ten digits `0~9`) | X |
| **number-densenet_lite_136-gru** 🆕 <br /> ([Planet Members](https://t.zsxq.com/FEYZRJQ) Only) ||| cnocr | 5.5 M | **Pure Numeric** (contains only the ten digits `0~9`) | X |
| **number-densenet_lite_666-gru_large** 🆕 <br /> ([Purchase Link](https://ocr.lemonsqueezy.com)) ||| cnocr | 56 M | **Pure Numeric** (contains only the ten digits `0~9`) | X |
| **en_PP-OCRv3** | X || ppocr | 8.5 M | **English**、Numbers ||
| **en_number_mobile_v2.0** | X || ppocr | 1.8 M | **English**、Numbers ||
| **chinese_cht_PP-OCRv3** | X || ppocr | 11 M | **Traditional Chinese**, English, Numbers | X |
| densenet_lite_136-gru ||| cnocr | 12 M | Simplified Chinese, English, Numbers | X |
| ch_PP-OCRv3 | X || ppocr | 10 M | Simplified Chinese, English, Numbers ||
| ch_ppocr_mobile_v2.0 | X || ppocr | 4.2 M | Simplified Chinese, English, Numbers ||
| ch_PP-OCRv4 | X || ppocr | 10 M | Simplified Chinese, English, Numbers ||
| ch_PP-OCRv4_server | X || ppocr | 86 M | Simplified Chinese, English, Numbers ||
| ch_PP-OCRv3 | X || ppocr | 10 M | Simplified Chinese, English, Numbers ||
| ch_ppocr_mobile_v2.0 | X || ppocr | 4.2 M | Simplified Chinese, English, Numbers ||
| **en_PP-OCRv3** | X || ppocr | 8.5 M | **English**、Numbers ||
| **en_PP-OCRv4** | X || ppocr | 8.6 M | **English**、Numbers ||
| **en_number_mobile_v2.0** | X || ppocr | 1.8 M | **English**、Numbers ||
| **chinese_cht_PP-OCRv3** | X || ppocr | 11 M | **Traditional Chinese**, English, Numbers | X |
| **japan_PP-OCRv3** | X || ppocr | 9.6 M | **Japanese**, English, Numbers ||
| **korean_PP-OCRv3** | X || ppocr | 9.4 M | **Korean**, English, Numbers ||
| **latin_PP-OCRv3** | X || ppocr | 8.6 M | **Latin**, English, Numbers ||
| **arabic_PP-OCRv3** | X || ppocr | 8.6 M | **Arabic**, English, Numbers ||


## Future work
Expand Down
2 changes: 1 addition & 1 deletion cnocr/__version__.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,4 @@
# specific language governing permissions and limitations
# under the License.

__version__ = '2.3.0.3'
__version__ = '2.3.1'
2 changes: 1 addition & 1 deletion cnocr/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ def main():
det_models.append(('naive_det', 'onnx'))
det_models.sort()
det_model_name = st.sidebar.selectbox(
'选择检测模型', det_models, index=det_models.index(('ch_PP-OCRv3_det', 'onnx'))
'选择检测模型', det_models, index=det_models.index(('ch_PP-OCRv4_det', 'onnx'))
)

all_models = list(REC_AVAILABLE_MODELS.all_models())
Expand Down
4 changes: 2 additions & 2 deletions cnocr/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -215,8 +215,8 @@ def visualize_example(example, fp_prefix):
'-d',
'--det-model-name',
type=str,
default='ch_PP-OCRv3_det',
help='检测模型名称。默认值为 ch_PP-OCRv3_det',
default='ch_PP-OCRv4_det',
help='检测模型名称。默认值为 ch_PP-OCRv4_det',
)
@click.option(
'--det-model-backend',
Expand Down
9 changes: 5 additions & 4 deletions cnocr/cn_ocr.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
from .utils import data_dir, read_img
from .line_split import line_split
from .recognizer import Recognizer
from .ppocr import PPRecognizer, PP_SPACE
from .ppocr import PPRecognizer, RapidRecognizer, PP_SPACE

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -64,7 +64,7 @@ def __init__(
self,
rec_model_name: str = 'densenet_lite_136-gru',
*,
det_model_name: str = 'ch_PP-OCRv3_det',
det_model_name: str = 'ch_PP-OCRv4_det',
cand_alphabet: Optional[Union[Collection, str]] = None,
context: str = 'cpu', # ['cpu', 'gpu', 'cuda']
rec_model_fp: Optional[str] = None,
Expand All @@ -83,7 +83,7 @@ def __init__(
Args:
rec_model_name (str): 识别模型名称。默认为 `densenet_lite_136-gru`
det_model_name (str): 检测模型名称。默认为 `ch_PP-OCRv3_det`
det_model_name (str): 检测模型名称。默认为 `ch_PP-OCRv4_det`
cand_alphabet (Optional[Union[Collection, str]]): 待识别字符所在的候选集合。默认为 `None`,表示不限定识别字符范围
context (str): 'cpu', or 'gpu'。表明预测时是使用CPU还是GPU。默认为 `cpu`。
此参数仅在 `model_backend=='pytorch'` 时有效。
Expand Down Expand Up @@ -143,7 +143,8 @@ def __init__(
if self.rec_space == REC_AVAILABLE_MODELS.CNOCR_SPACE:
rec_cls = Recognizer
elif self.rec_space == PP_SPACE:
rec_cls = PPRecognizer
rec_name = REC_AVAILABLE_MODELS.get_value(rec_model_name, rec_model_backend, 'recognizer')
rec_cls = RapidRecognizer if rec_name == 'RapidRecognizer' else PPRecognizer
if rec_vocab_fp is not None:
logger.warning('param `vocab_fp` is invalid for %s models' % PP_SPACE)
else:
Expand Down
12 changes: 12 additions & 0 deletions cnocr/consts.py
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,18 @@ def get_vocab_fp(
)
return CN_VOCAB_FP

def get_value(self, model_name, model_backend, key) -> Optional[Any]:
if (model_name, model_backend) in self.CNOCR_MODELS:
info = self.CNOCR_MODELS[(model_name, model_backend)]
elif (model_name, model_backend) in self.OUTER_MODELS:
info = self.OUTER_MODELS[(model_name, model_backend)]
else:
logger.warning(
'no url is found for model %s' % ((model_name, model_backend),)
)
return None
return info.get(key)

def get_epoch(self, model_name, model_backend) -> Optional[int]:
if (model_name, model_backend) in self.CNOCR_MODELS:
return self.CNOCR_MODELS[(model_name, model_backend)]['epoch']
Expand Down
Loading

0 comments on commit e61f84b

Please sign in to comment.