Skip to content

Commit

Permalink
Merge pull request #44 from RapidAI/develop
Browse files Browse the repository at this point in the history
Move the dict txt into the inside of the onnx.
  • Loading branch information
SWHL authored Aug 17, 2022
2 parents afb6bb5 + 037e175 commit 156b21a
Show file tree
Hide file tree
Showing 22 changed files with 99 additions and 14,891 deletions.
5 changes: 5 additions & 0 deletions .github/workflows/make-linux.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@ on:
push:
branches:
- main
paths:
- '!python/**'
- '!ocrweb/**'
- '!*.md'
- '!docs/**'

env:
# Customize the CMake build type here (Release, Debug, RelWithDebInfo, etc.)
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
__pycache__/
*.py[cod]
*$py.class
.pytest_cache

# C extensions
*.so
Expand Down
15 changes: 6 additions & 9 deletions ocrweb/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,15 @@
├── task.py
├── rapidocr_onnxruntime
│   ├── __init__.py
│   ├── ch_ppocr_v3_det
│   ├── ch_ppocr_v2_cls
│   ├── ch_ppocr_v2_det
│   ├── ch_ppocr_v2_rec
│   ├── ch_ppocr_v3_rec
│   └── rapid_ocr_api.py
├── resources
│   ├── models
│ │   ├── ch_PP-OCRv3_det_infer.onnx
│ │   ├── ch_ppocr_mobile_v2.0_cls_infer.onnx
│ │   └── ch_PP-OCRv3_rec_infer.onnx
│   └── rec_dict
│ └── ppocr_keys_v1.txt
│   └── models
│    ├── ch_PP-OCRv3_det_infer.onnx
│    ├── ch_ppocr_mobile_v2.0_cls_infer.onnx
│    └── ch_PP-OCRv3_rec_infer.onnx
├── static
│   ├── css
│   └── js
Expand Down Expand Up @@ -83,7 +81,6 @@
print(rec_res)
else:
print(response.status_code)
```
5. 输出以下结果,即为正确。
Expand Down
1 change: 0 additions & 1 deletion ocrweb/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -69,4 +69,3 @@ Rec:

rec_img_shape: [3, 48, 320]
rec_batch_num: 6
keys_path: resources/rec_dict/ppocr_keys_v1.txt
15 changes: 10 additions & 5 deletions ocrweb/rapidocr_onnxruntime/ch_ppocr_v3_rec/text_recognize.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,19 @@

class TextRecognizer(object):
def __init__(self, config):
self.rec_image_shape = config['rec_img_shape']
self.rec_batch_num = config['rec_batch_num']
self.character_dict_path = config['keys_path']
self.postprocess_op = CTCLabelDecode(self.character_dict_path)

session_instance = OrtInferSession(config)
self.session = session_instance.session
self.input_name = session_instance.get_input_name()
meta_dict = session_instance.get_metadata()

if 'character' in meta_dict.keys():
self.character_dict_path = meta_dict['character'].splitlines()
else:
self.character_dict_path = config['keys_path']
self.postprocess_op = CTCLabelDecode(self.character_dict_path)

self.rec_batch_num = config['rec_batch_num']
self.rec_image_shape = config['rec_img_shape']

def resize_norm_img(self, img, max_wh_ratio):
img_channel, img_height, img_width = self.rec_image_shape
Expand Down
19 changes: 14 additions & 5 deletions ocrweb/rapidocr_onnxruntime/ch_ppocr_v3_rec/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@ def get_input_name(self, input_idx=0):
def get_output_name(self, output_idx=0):
return self.session.get_outputs()[output_idx].name

def get_metadata(self):
meta_dict = self.session.get_modelmeta().custom_metadata_map
return meta_dict


def read_yaml(yaml_path):
with open(yaml_path, 'rb') as f:
Expand All @@ -57,13 +61,18 @@ def __init__(self, character_dict_path):

self.character_str = []
assert character_dict_path is not None, "character_dict_path should not be None"
with open(character_dict_path, "rb") as fin:
lines = fin.readlines()
for line in lines:
line = line.decode('utf-8').strip("\n").strip("\r\n")
self.character_str.append(line)

if isinstance(character_dict_path, str):
with open(character_dict_path, "rb") as fin:
lines = fin.readlines()
for line in lines:
line = line.decode('utf-8').strip("\n").strip("\r\n")
self.character_str.append(line)
else:
self.character_str = character_dict_path
self.character_str.append(' ')


dict_character = self.add_special_char(self.character_str)
self.character = dict_character

Expand Down
3 changes: 2 additions & 1 deletion ocrweb/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@ numpy>=1.19.1
Shapely>=1.7.1
Flask>=2.1.2
Pillow
PyYAML
PyYAML
requests
95 changes: 0 additions & 95 deletions ocrweb/resources/rec_dict/en_dict.txt

This file was deleted.

Loading

0 comments on commit 156b21a

Please sign in to comment.