openocr-python 0.0.9__py3-none-any.whl → 0.1.0.dev0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- openocr/__init__.py +35 -1
- openocr/configs/dataset/rec/evaluation.yaml +41 -0
- openocr/configs/dataset/rec/ltb.yaml +9 -0
- openocr/configs/dataset/rec/mjsynth.yaml +11 -0
- openocr/configs/dataset/rec/openvino.yaml +25 -0
- openocr/configs/dataset/rec/ost.yaml +17 -0
- openocr/configs/dataset/rec/synthtext.yaml +7 -0
- openocr/configs/dataset/rec/test.yaml +77 -0
- openocr/configs/dataset/rec/textocr.yaml +13 -0
- openocr/configs/dataset/rec/textocr_horizontal.yaml +13 -0
- openocr/configs/dataset/rec/union14m_b.yaml +47 -0
- openocr/configs/dataset/rec/union14m_l_filtered.yaml +35 -0
- openocr/configs/rec/cmer/cmer.yml +127 -0
- openocr/configs/rec/mdiff4str/svtrv2_mdiffdecoder_base.yml +152 -0
- openocr/configs/rec/mdiff4str/svtrv2_mdiffdecoder_small.yml +152 -0
- openocr/configs/rec/unirec/focalsvtr_ardecoder_unirec.yml +114 -0
- openocr/configs/rec/unirec/opendoc_pipeline.yml +105 -0
- openocr/demo_gradio.py +28 -8
- openocr/demo_opendoc.py +572 -0
- openocr/demo_unirec.py +392 -0
- openocr/opendet/losses/__init__.py +5 -7
- openocr/opendet/preprocess/crop_resize.py +2 -1
- openocr/openocr.py +685 -0
- openocr/openrec/losses/__init__.py +8 -3
- openocr/openrec/losses/cmer_loss.py +12 -0
- openocr/openrec/losses/mdiff_loss.py +11 -0
- openocr/openrec/losses/unirec_loss.py +12 -0
- openocr/openrec/metrics/__init__.py +4 -1
- openocr/openrec/metrics/rec_metric_cmer.py +328 -0
- openocr/openrec/modeling/cmer_modeling/modeling_cmer.py +643 -0
- openocr/openrec/modeling/decoders/__init__.py +1 -0
- openocr/openrec/modeling/decoders/ctc_decoder.py +1 -1
- openocr/openrec/modeling/decoders/dan_decoder.py +4 -4
- openocr/openrec/modeling/decoders/dptr_parseq_clip_b_decoder.py +1563 -1398
- openocr/openrec/modeling/decoders/mdiff_decoder.py +587 -0
- openocr/openrec/modeling/decoders/smtr_decoder.py +99 -48
- openocr/openrec/modeling/unirec_modeling/configuration_unirec.py +166 -0
- openocr/openrec/modeling/unirec_modeling/modeling_unirec.py +433 -0
- openocr/openrec/optimizer/__init__.py +4 -3
- openocr/openrec/optimizer/lr.py +49 -0
- openocr/openrec/postprocess/__init__.py +2 -0
- openocr/openrec/postprocess/abinet_postprocess.py +1 -1
- openocr/openrec/postprocess/ar_postprocess.py +1 -1
- openocr/openrec/postprocess/cmer_postprocess.py +86 -0
- openocr/openrec/postprocess/cppd_postprocess.py +1 -1
- openocr/openrec/postprocess/igtr_postprocess.py +1 -1
- openocr/openrec/postprocess/lister_postprocess.py +1 -1
- openocr/openrec/postprocess/mgp_postprocess.py +1 -1
- openocr/openrec/postprocess/nrtr_postprocess.py +2 -2
- openocr/openrec/postprocess/smtr_postprocess.py +1 -1
- openocr/openrec/postprocess/srn_postprocess.py +1 -1
- openocr/openrec/postprocess/unirec_postprocess.py +58 -0
- openocr/openrec/postprocess/visionlan_postprocess.py +1 -1
- openocr/openrec/preprocess/__init__.py +5 -0
- openocr/openrec/preprocess/ce_label_encode.py +1 -1
- openocr/openrec/preprocess/cmer_label_encode.py +1025 -0
- openocr/openrec/preprocess/ctc_label_encode.py +1 -1
- openocr/openrec/preprocess/dptr_label_encode.py +177 -157
- openocr/openrec/preprocess/igtr_label_encode.py +4 -2
- openocr/openrec/preprocess/mdiff_label_encode.py +312 -0
- openocr/openrec/preprocess/rec_aug.py +128 -2
- openocr/openrec/preprocess/resize.py +57 -0
- openocr/openrec/preprocess/unirec_label_encode.py +62 -0
- openocr/tools/data/__init__.py +78 -55
- openocr/tools/data/cmer_web_dataset.py +310 -0
- openocr/tools/data/native_size_dataset.py +753 -0
- openocr/tools/data/native_size_sampler.py +158 -0
- openocr/tools/data/ratio_dataset_tvresize.py +2 -0
- openocr/tools/data/ratio_sampler.py +2 -1
- openocr/tools/download/download_dataset.py +38 -0
- openocr/tools/download/utils.py +28 -0
- openocr/tools/download_example_images.py +236 -0
- openocr/tools/engine/trainer.py +155 -39
- openocr/tools/eval_rec_all_ch.py +2 -2
- openocr/tools/infer_det.py +20 -2
- openocr/tools/infer_doc.py +898 -0
- openocr/tools/infer_doc_onnx.py +1172 -0
- openocr/tools/infer_e2e.py +27 -10
- openocr/tools/infer_rec.py +64 -15
- openocr/tools/infer_unirec_onnx.py +730 -0
- openocr/tools/to_markdown.py +468 -0
- openocr/tools/utils/ckpt.py +17 -5
- openocr/tools/utils/opendoc_onnx_utils/utils.py +1052 -0
- openocr_python-0.1.0.dev0.dist-info/METADATA +324 -0
- {openocr_python-0.0.9.dist-info → openocr_python-0.1.0.dev0.dist-info}/RECORD +89 -45
- {openocr_python-0.0.9.dist-info → openocr_python-0.1.0.dev0.dist-info}/WHEEL +1 -1
- openocr_python-0.1.0.dev0.dist-info/entry_points.txt +2 -0
- openocr_python-0.0.9.dist-info/METADATA +0 -149
- /openocr_python-0.0.9.dist-info/LICENCE → /openocr_python-0.1.0.dev0.dist-info/licenses/LICENSE +0 -0
- {openocr_python-0.0.9.dist-info → openocr_python-0.1.0.dev0.dist-info}/top_level.txt +0 -0
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
Global:
|
|
2
|
+
device: gpu
|
|
3
|
+
epoch_num: 40
|
|
4
|
+
log_smooth_window: 20
|
|
5
|
+
print_batch_step: 10
|
|
6
|
+
output_dir: ./output/rec/u14m_filter/svtrv2_mdiffdecoder_small/
|
|
7
|
+
save_epoch_step: [30, 1]
|
|
8
|
+
# evaluation is run every 2000 iterations
|
|
9
|
+
eval_batch_step: [0, 500]
|
|
10
|
+
eval_epoch_step: [0, 1]
|
|
11
|
+
cal_metric_during_train: False
|
|
12
|
+
pretrained_model:
|
|
13
|
+
checkpoints:
|
|
14
|
+
use_tensorboard: false
|
|
15
|
+
infer_img:
|
|
16
|
+
# for data or label process
|
|
17
|
+
character_dict_path: &character_dict_path ./tools/utils/EN_symbol_dict.txt # 96en
|
|
18
|
+
# ./tools/utils/ppocr_keys_v1.txt # ch
|
|
19
|
+
max_text_length: &max_text_length 25
|
|
20
|
+
use_space_char: &use_space_char False
|
|
21
|
+
save_res_path: ./output/rec/u14m_filter/predicts_svtrv2_mdiffdecoder_small.txt
|
|
22
|
+
use_amp: True
|
|
23
|
+
grad_clip_val: 20.0
|
|
24
|
+
|
|
25
|
+
Optimizer:
|
|
26
|
+
name: AdamW
|
|
27
|
+
lr: 0.0005 # for 8gpus bs128/gpu
|
|
28
|
+
weight_decay: 0.05
|
|
29
|
+
filter_bias_and_bn: True
|
|
30
|
+
|
|
31
|
+
LRScheduler:
|
|
32
|
+
name: OneCycleLR
|
|
33
|
+
warmup_epoch: 1.5 # pct_start 0.075*20 = 1.5ep
|
|
34
|
+
cycle_momentum: False
|
|
35
|
+
|
|
36
|
+
Architecture:
|
|
37
|
+
model_type: rec
|
|
38
|
+
algorithm: MDiff4STR
|
|
39
|
+
in_channels: 3
|
|
40
|
+
Transform:
|
|
41
|
+
Encoder:
|
|
42
|
+
name: SVTRv2LNConvTwo33
|
|
43
|
+
use_pos_embed: False
|
|
44
|
+
dims: [128, 256, 384]
|
|
45
|
+
depths: [3, 6, 3]
|
|
46
|
+
num_heads: [4, 8, 12]
|
|
47
|
+
mixer: [['Conv','Conv','Conv'],['Conv','Conv','Conv','FGlobal','Global','Global'],['Global','Global','Global']]
|
|
48
|
+
local_k: [[5, 5], [5, 5], [-1, -1]]
|
|
49
|
+
sub_k: [[1, 1], [2, 1], [-1, -1]]
|
|
50
|
+
last_stage: false
|
|
51
|
+
feat2d: False
|
|
52
|
+
Decoder:
|
|
53
|
+
name: MDiffDecoder
|
|
54
|
+
num_decoder_layers: 3
|
|
55
|
+
nhead: 6
|
|
56
|
+
max_len: *max_text_length
|
|
57
|
+
parallel_decoding: False
|
|
58
|
+
autoregressive_decoding: False
|
|
59
|
+
low_confidence_decoding: False
|
|
60
|
+
random_mask_decoding: False
|
|
61
|
+
semi_autoregressive_decoding: False
|
|
62
|
+
cloze_mask_decoding: False
|
|
63
|
+
sampler_step: 3
|
|
64
|
+
sample_k: &sample_k 3
|
|
65
|
+
temperature: 1.0
|
|
66
|
+
|
|
67
|
+
Loss:
|
|
68
|
+
name: MDiffLoss
|
|
69
|
+
|
|
70
|
+
PostProcess:
|
|
71
|
+
name: ARLabelDecode
|
|
72
|
+
character_dict_path: *character_dict_path
|
|
73
|
+
use_space_char: *use_space_char
|
|
74
|
+
|
|
75
|
+
Metric:
|
|
76
|
+
name: RecMetric
|
|
77
|
+
main_indicator: acc
|
|
78
|
+
is_filter: True
|
|
79
|
+
|
|
80
|
+
Train:
|
|
81
|
+
dataset:
|
|
82
|
+
name: RatioDataSetTVResize
|
|
83
|
+
ds_width: True
|
|
84
|
+
padding: false
|
|
85
|
+
data_dir_list: ['../Union14M-L-LMDB-Filtered/filter_train_challenging',
|
|
86
|
+
'../Union14M-L-LMDB-Filtered/filter_train_hard',
|
|
87
|
+
'../Union14M-L-LMDB-Filtered/filter_train_medium',
|
|
88
|
+
'../Union14M-L-LMDB-Filtered/filter_train_normal',
|
|
89
|
+
'../Union14M-L-LMDB-Filtered/filter_train_easy',
|
|
90
|
+
]
|
|
91
|
+
transforms:
|
|
92
|
+
- DecodeImagePIL: # load image
|
|
93
|
+
img_mode: RGB
|
|
94
|
+
- PARSeqAugPIL:
|
|
95
|
+
- MDiffLabelEncode: # Class handling label
|
|
96
|
+
character_dict_path: *character_dict_path
|
|
97
|
+
use_space_char: *use_space_char
|
|
98
|
+
max_text_length: *max_text_length
|
|
99
|
+
sample_num: *sample_k
|
|
100
|
+
- KeepKeys:
|
|
101
|
+
keep_keys: ['image', 'label', 'reflect_ids', 'noisy_batch', 'masked_indices', 'p_mask', 'length'] # dataloader will return list in this order
|
|
102
|
+
sampler:
|
|
103
|
+
name: RatioSampler
|
|
104
|
+
scales: [[128, 32]] # w, h
|
|
105
|
+
# divide_factor: to ensure the width and height dimensions can be devided by downsampling multiple
|
|
106
|
+
first_bs: &bs 256
|
|
107
|
+
fix_bs: false
|
|
108
|
+
divided_factor: [4, 16] # w, h
|
|
109
|
+
is_training: True
|
|
110
|
+
loader:
|
|
111
|
+
shuffle: True
|
|
112
|
+
batch_size_per_card: *bs
|
|
113
|
+
drop_last: True
|
|
114
|
+
max_ratio: &max_ratio 4
|
|
115
|
+
num_workers: 4
|
|
116
|
+
|
|
117
|
+
Eval:
|
|
118
|
+
dataset:
|
|
119
|
+
name: RatioDataSetTVResize
|
|
120
|
+
ds_width: True
|
|
121
|
+
padding: False
|
|
122
|
+
data_dir_list: [
|
|
123
|
+
'../evaluation/CUTE80',
|
|
124
|
+
'../evaluation/IC13_857',
|
|
125
|
+
'../evaluation/IC15_1811',
|
|
126
|
+
'../evaluation/IIIT5k_3000',
|
|
127
|
+
'../evaluation/SVT',
|
|
128
|
+
'../evaluation/SVTP',
|
|
129
|
+
]
|
|
130
|
+
transforms:
|
|
131
|
+
- DecodeImagePIL: # load image
|
|
132
|
+
img_mode: RGB
|
|
133
|
+
- ARLabelEncode: # Class handling label
|
|
134
|
+
character_dict_path: *character_dict_path
|
|
135
|
+
use_space_char: *use_space_char
|
|
136
|
+
max_text_length: *max_text_length
|
|
137
|
+
- KeepKeys:
|
|
138
|
+
keep_keys: ['image', 'label', 'length'] # dataloader will return list in this order
|
|
139
|
+
sampler:
|
|
140
|
+
name: RatioSampler
|
|
141
|
+
scales: [[128, 32]] # w, h
|
|
142
|
+
# divide_factor: to ensure the width and height dimensions can be devided by downsampling multiple
|
|
143
|
+
first_bs: *bs
|
|
144
|
+
fix_bs: false
|
|
145
|
+
divided_factor: [4, 16] # w, h
|
|
146
|
+
is_training: False
|
|
147
|
+
loader:
|
|
148
|
+
shuffle: False
|
|
149
|
+
drop_last: False
|
|
150
|
+
batch_size_per_card: *bs
|
|
151
|
+
max_ratio: *max_ratio
|
|
152
|
+
num_workers: 4
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
Global:
|
|
2
|
+
device: gpu
|
|
3
|
+
epoch_num: 10
|
|
4
|
+
log_smooth_window: 20
|
|
5
|
+
print_batch_step: 20
|
|
6
|
+
output_dir: ./output/rec/unirec-0.1b/
|
|
7
|
+
save_epoch_step: [0, 1] # save every 1 epoch after 7 epochs
|
|
8
|
+
save_iter_step: [0, 2000]
|
|
9
|
+
# evaluation is run every 2000 iterations
|
|
10
|
+
eval_batch_step: [2000000, 4000]
|
|
11
|
+
eval_epoch_step: [150, 1]
|
|
12
|
+
cal_metric_during_train: False
|
|
13
|
+
pretrained_model: ./unirec-0.1b/model.pth
|
|
14
|
+
checkpoints:
|
|
15
|
+
resume_from_iter: False
|
|
16
|
+
use_tensorboard: false
|
|
17
|
+
infer_img: ../crop_img_hand
|
|
18
|
+
# for data or label process
|
|
19
|
+
character_dict_path: &character_dict_path ./tools/utils/EN_symbol_dict.txt # 96en
|
|
20
|
+
# ./tools/utils/ppocr_keys_v1.txt # ch
|
|
21
|
+
max_text_length: &max_text_length 2048
|
|
22
|
+
use_space_char: &use_space_char False
|
|
23
|
+
save_res_path: ./output/rec/unirec-0.1b/predicts_unirec-0.1b.txt
|
|
24
|
+
use_amp: True
|
|
25
|
+
use_ema: False
|
|
26
|
+
use_transformers: True
|
|
27
|
+
grad_clip_val: 1.0
|
|
28
|
+
vlm_ocr_config: &vlm_ocr_config ./configs/rec/unirec/unirec-0.1b
|
|
29
|
+
|
|
30
|
+
Optimizer:
|
|
31
|
+
name: AdamW
|
|
32
|
+
lr: 0.0001 # for 4gpus bs256/gpu
|
|
33
|
+
weight_decay: 0.01
|
|
34
|
+
filter_bias_and_bn: True
|
|
35
|
+
|
|
36
|
+
LRScheduler:
|
|
37
|
+
name: OneCycleLR
|
|
38
|
+
warmup_epoch: 0.3 # pct_start 0.075*20 = 1.5ep
|
|
39
|
+
cycle_momentum: False
|
|
40
|
+
|
|
41
|
+
Architecture:
|
|
42
|
+
model_type: rec
|
|
43
|
+
algorithm: UniRec
|
|
44
|
+
in_channels: 3
|
|
45
|
+
Transform:
|
|
46
|
+
Encoder:
|
|
47
|
+
Decoder:
|
|
48
|
+
out_channels: -1 # for inference, set to -1
|
|
49
|
+
|
|
50
|
+
Loss:
|
|
51
|
+
name: UniRecLoss
|
|
52
|
+
|
|
53
|
+
PostProcess:
|
|
54
|
+
name: UniRecLabelDecode
|
|
55
|
+
lower: False
|
|
56
|
+
tokenizer_path: *vlm_ocr_config
|
|
57
|
+
|
|
58
|
+
Metric:
|
|
59
|
+
name: RecMetric
|
|
60
|
+
main_indicator: acc
|
|
61
|
+
is_filter: False
|
|
62
|
+
|
|
63
|
+
Train:
|
|
64
|
+
dataset:
|
|
65
|
+
name: NaSizeDataSet
|
|
66
|
+
divided_factor: ÷d_factor [64, 64] # w, h
|
|
67
|
+
max_side: &max_side [960, 1408] # [64*30, 64*44] # w, h [960, 1408] #
|
|
68
|
+
root_path: path/to/UniRec40M
|
|
69
|
+
add_return: True
|
|
70
|
+
zoom_min_factor: 4
|
|
71
|
+
use_zoom: True
|
|
72
|
+
# all_data: True
|
|
73
|
+
test_data: True
|
|
74
|
+
use_aug: false
|
|
75
|
+
use_linedata: False
|
|
76
|
+
transforms:
|
|
77
|
+
- UniRecLabelEncode: # Class handling label
|
|
78
|
+
max_text_length: *max_text_length
|
|
79
|
+
vlmocr: True
|
|
80
|
+
tokenizer_path: *vlm_ocr_config # path to tokenizer, e.g. 'vocab.json', 'merges.txt'
|
|
81
|
+
- KeepKeys:
|
|
82
|
+
keep_keys: ['image', 'label', 'length'] # dataloader will return list in this order
|
|
83
|
+
sampler:
|
|
84
|
+
name: NaSizeSampler
|
|
85
|
+
# divide_factor: to ensure the width and height dimensions can be devided by downsampling multiple
|
|
86
|
+
min_bs: 1
|
|
87
|
+
max_bs: 24
|
|
88
|
+
loader:
|
|
89
|
+
shuffle: True
|
|
90
|
+
batch_size_per_card: 64
|
|
91
|
+
drop_last: True
|
|
92
|
+
num_workers: 8
|
|
93
|
+
|
|
94
|
+
Eval:
|
|
95
|
+
dataset:
|
|
96
|
+
name: LMDBDataSet
|
|
97
|
+
data_dir: ../evaluation
|
|
98
|
+
transforms:
|
|
99
|
+
- DecodeImagePIL: # load image
|
|
100
|
+
img_mode: RGB
|
|
101
|
+
- UniRecLabelEncode: # Class handling label
|
|
102
|
+
max_text_length: *max_text_length
|
|
103
|
+
vlmocr: True
|
|
104
|
+
tokenizer_path: *vlm_ocr_config # path to tokenizer, e.g. 'vocab.json', 'merges.txt'
|
|
105
|
+
- NaSizeResize:
|
|
106
|
+
max_side: *max_side
|
|
107
|
+
divided_factor: *divided_factor
|
|
108
|
+
- KeepKeys:
|
|
109
|
+
keep_keys: ['image', 'label', 'length'] # dataloader will return list in this order
|
|
110
|
+
loader:
|
|
111
|
+
shuffle: False
|
|
112
|
+
drop_last: False
|
|
113
|
+
batch_size_per_card: 1
|
|
114
|
+
num_workers: 1
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
|
|
2
|
+
pipeline_name: PaddleOCR-VL
|
|
3
|
+
|
|
4
|
+
batch_size: 64
|
|
5
|
+
|
|
6
|
+
use_queues: False
|
|
7
|
+
|
|
8
|
+
use_doc_preprocessor: False
|
|
9
|
+
use_layout_detection: True
|
|
10
|
+
use_chart_recognition: False
|
|
11
|
+
format_block_content: False
|
|
12
|
+
merge_layout_blocks: True
|
|
13
|
+
markdown_ignore_labels:
|
|
14
|
+
- number
|
|
15
|
+
- footnote
|
|
16
|
+
- header
|
|
17
|
+
- header_image
|
|
18
|
+
- footer
|
|
19
|
+
- footer_image
|
|
20
|
+
- aside_text
|
|
21
|
+
|
|
22
|
+
SubModules:
|
|
23
|
+
LayoutDetection:
|
|
24
|
+
module_name: layout_detection
|
|
25
|
+
model_name: PP-DocLayoutV2
|
|
26
|
+
model_dir: null
|
|
27
|
+
batch_size: 8
|
|
28
|
+
threshold:
|
|
29
|
+
0: 0.5 # abstract
|
|
30
|
+
1: 0.5 # algorithm
|
|
31
|
+
2: 0.5 # aside_text
|
|
32
|
+
3: 0.5 # chart
|
|
33
|
+
4: 0.5 # content
|
|
34
|
+
5: 0.4 # formula
|
|
35
|
+
6: 0.4 # doc_title
|
|
36
|
+
7: 0.5 # figure_title
|
|
37
|
+
8: 0.5 # footer
|
|
38
|
+
9: 0.5 # footer
|
|
39
|
+
10: 0.5 # footnote
|
|
40
|
+
11: 0.5 # formula_number
|
|
41
|
+
12: 0.5 # header
|
|
42
|
+
13: 0.5 # header
|
|
43
|
+
14: 0.5 # image
|
|
44
|
+
15: 0.4 # formula
|
|
45
|
+
16: 0.5 # number
|
|
46
|
+
17: 0.4 # paragraph_title
|
|
47
|
+
18: 0.5 # reference
|
|
48
|
+
19: 0.5 # reference_content
|
|
49
|
+
20: 0.45 # seal
|
|
50
|
+
21: 0.5 # table
|
|
51
|
+
22: 0.4 # text
|
|
52
|
+
23: 0.4 # text
|
|
53
|
+
24: 0.5 # vision_footnote
|
|
54
|
+
layout_nms: True
|
|
55
|
+
layout_unclip_ratio: [1.0, 1.0]
|
|
56
|
+
layout_merge_bboxes_mode:
|
|
57
|
+
0: "union" # abstract
|
|
58
|
+
1: "union" # algorithm
|
|
59
|
+
2: "union" # aside_text
|
|
60
|
+
3: "large" # chart
|
|
61
|
+
4: "union" # content
|
|
62
|
+
5: "large" # display_formula
|
|
63
|
+
6: "large" # doc_title
|
|
64
|
+
7: "union" # figure_title
|
|
65
|
+
8: "union" # footer
|
|
66
|
+
9: "union" # footer
|
|
67
|
+
10: "union" # footnote
|
|
68
|
+
11: "union" # formula_number
|
|
69
|
+
12: "union" # header
|
|
70
|
+
13: "union" # header
|
|
71
|
+
14: "union" # image
|
|
72
|
+
15: "large" # inline_formula
|
|
73
|
+
16: "union" # number
|
|
74
|
+
17: "large" # paragraph_title
|
|
75
|
+
18: "union" # reference
|
|
76
|
+
19: "union" # reference_content
|
|
77
|
+
20: "union" # seal
|
|
78
|
+
21: "union" # table
|
|
79
|
+
22: "union" # text
|
|
80
|
+
23: "union" # text
|
|
81
|
+
24: "union" # vision_footnote
|
|
82
|
+
VLRecognition:
|
|
83
|
+
module_name: vl_recognition
|
|
84
|
+
model_name: PaddleOCR-VL-0.9B
|
|
85
|
+
model_dir: null
|
|
86
|
+
batch_size: 4096
|
|
87
|
+
genai_config:
|
|
88
|
+
backend: native
|
|
89
|
+
|
|
90
|
+
SubPipelines:
|
|
91
|
+
DocPreprocessor:
|
|
92
|
+
pipeline_name: doc_preprocessor
|
|
93
|
+
batch_size: 8
|
|
94
|
+
use_doc_orientation_classify: True
|
|
95
|
+
use_doc_unwarping: True
|
|
96
|
+
SubModules:
|
|
97
|
+
DocOrientationClassify:
|
|
98
|
+
module_name: doc_text_orientation
|
|
99
|
+
model_name: PP-LCNet_x1_0_doc_ori
|
|
100
|
+
model_dir: null
|
|
101
|
+
batch_size: 8
|
|
102
|
+
DocUnwarping:
|
|
103
|
+
module_name: image_unwarping
|
|
104
|
+
model_name: UVDoc
|
|
105
|
+
model_dir: null
|
openocr/demo_gradio.py
CHANGED
|
@@ -9,11 +9,12 @@ import numpy as np
|
|
|
9
9
|
import json
|
|
10
10
|
import time
|
|
11
11
|
from PIL import Image
|
|
12
|
-
from tools.infer_e2e import
|
|
12
|
+
from tools.infer_e2e import OpenOCRE2E, check_and_download_font, draw_ocr_box_txt
|
|
13
|
+
from tools.download_example_images import get_example_images_path
|
|
13
14
|
|
|
14
15
|
|
|
15
16
|
def initialize_ocr(model_type, drop_score):
|
|
16
|
-
return
|
|
17
|
+
return OpenOCRE2E(mode=model_type, drop_score=drop_score, backend='onnx')
|
|
17
18
|
|
|
18
19
|
|
|
19
20
|
# Default model type
|
|
@@ -108,12 +109,25 @@ def find_file_in_current_dir_and_subdirs(file_name):
|
|
|
108
109
|
return relative_path
|
|
109
110
|
|
|
110
111
|
|
|
111
|
-
|
|
112
|
+
# Get example images path and download if necessary
|
|
113
|
+
example_img_dir = get_example_images_path(demo_type='ocr')
|
|
114
|
+
e2e_img_example = list_image_paths(example_img_dir)
|
|
112
115
|
|
|
113
|
-
|
|
116
|
+
|
|
117
|
+
def launch_demo(share=False, server_port=7860, server_name='0.0.0.0'):
|
|
118
|
+
"""Launch OpenOCR Gradio demo with default configuration.
|
|
119
|
+
|
|
120
|
+
Args:
|
|
121
|
+
share: Whether to create a public share link (default: False)
|
|
122
|
+
server_port: Server port (default: 7860)
|
|
123
|
+
server_name: Server name (default: '0.0.0.0')
|
|
124
|
+
|
|
125
|
+
Returns:
|
|
126
|
+
gr.Blocks: Gradio demo instance
|
|
127
|
+
"""
|
|
114
128
|
css = '.image-container img { width: 100%; max-height: 320px;}'
|
|
115
129
|
|
|
116
|
-
with gr.Blocks(css=css) as demo:
|
|
130
|
+
with gr.Blocks(css=css, theme=gr.themes.Soft()) as demo:
|
|
117
131
|
gr.HTML("""
|
|
118
132
|
<h1 style='text-align: center;'><a href="https://github.com/Topdu/OpenOCR">OpenOCR</a></h1>
|
|
119
133
|
<p style='text-align: center;'>准确高效的通用 OCR 系统 (由<a href="https://fvl.fudan.edu.cn">FVL实验室</a> <a href="https://github.com/Topdu/OpenOCR">OCR Team</a> 创建) <a href="https://github.com/Topdu/OpenOCR/tree/main?tab=readme-ov-file#quick-start">[本地快速部署]</a></p>"""
|
|
@@ -126,7 +140,7 @@ if __name__ == '__main__':
|
|
|
126
140
|
examples = gr.Examples(examples=e2e_img_example,
|
|
127
141
|
inputs=input_image,
|
|
128
142
|
label='Examples')
|
|
129
|
-
downstream = gr.Button('
|
|
143
|
+
downstream = gr.Button('🚀 运行识别', variant='primary')
|
|
130
144
|
|
|
131
145
|
# 添加参数调节组件
|
|
132
146
|
with gr.Column():
|
|
@@ -139,7 +153,8 @@ if __name__ == '__main__':
|
|
|
139
153
|
['slow', 'fast'],
|
|
140
154
|
value='slow',
|
|
141
155
|
label='Detection Score Mode',
|
|
142
|
-
info=
|
|
156
|
+
info=
|
|
157
|
+
'文本框的置信度计算模式,默认为 slow。slow 模式计算速度较慢,但准确度较高。fast 模式计算速度较快,但准确度较低。'
|
|
143
158
|
)
|
|
144
159
|
with gr.Row():
|
|
145
160
|
rec_drop_score_slider = gr.Slider(
|
|
@@ -204,4 +219,9 @@ if __name__ == '__main__':
|
|
|
204
219
|
img_mask,
|
|
205
220
|
])
|
|
206
221
|
|
|
207
|
-
demo.launch(share=
|
|
222
|
+
demo.launch(share=share, server_port=server_port, server_name=server_name)
|
|
223
|
+
return demo
|
|
224
|
+
|
|
225
|
+
|
|
226
|
+
if __name__ == '__main__':
|
|
227
|
+
launch_demo(share=False)
|