Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
PaddleOCR
提交
9023a5c5
P
PaddleOCR
项目概览
PaddlePaddle
/
PaddleOCR
大约 1 年 前同步成功
通知
1528
Star
32962
Fork
6643
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
108
列表
看板
标记
里程碑
合并请求
7
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
PaddleOCR
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
108
Issue
108
列表
看板
标记
里程碑
合并请求
7
合并请求
7
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
9023a5c5
编写于
6月 03, 2020
作者:
T
tink2123
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
update infer doc and fix yml
上级
80c18878
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
20 addition
and
11 deletion
+20
-11
configs/rec/rec_chinese_lite_train.yml
configs/rec/rec_chinese_lite_train.yml
+2
-2
configs/rec/rec_icdar15_train.yml
configs/rec/rec_icdar15_train.yml
+1
-1
configs/rec/rec_mv3_none_bilstm_ctc.yml
configs/rec/rec_mv3_none_bilstm_ctc.yml
+1
-1
configs/rec/rec_mv3_tps_bilstm_attn.yml
configs/rec/rec_mv3_tps_bilstm_attn.yml
+2
-3
doc/inference.md
doc/inference.md
+6
-0
tools/infer/predict_rec.py
tools/infer/predict_rec.py
+8
-4
未找到文件。
configs/rec/rec_chinese_lite_train.yml
浏览文件 @
9023a5c5
Global
:
Global
:
algorithm
:
CRNN
algorithm
:
CRNN
use_gpu
:
fals
e
use_gpu
:
tru
e
epoch_num
:
3000
epoch_num
:
3000
log_smooth_window
:
20
log_smooth_window
:
20
print_batch_step
:
10
print_batch_step
:
10
...
@@ -16,7 +16,7 @@ Global:
...
@@ -16,7 +16,7 @@ Global:
character_dict_path
:
./ppocr/utils/ppocr_keys_v1.txt
character_dict_path
:
./ppocr/utils/ppocr_keys_v1.txt
loss_type
:
ctc
loss_type
:
ctc
reader_yml
:
./configs/rec/rec_chinese_reader.yml
reader_yml
:
./configs/rec/rec_chinese_reader.yml
pretrain_weights
:
output/rec_CRNN/rec_mv3_crnn/best_accuracy
pretrain_weights
:
checkpoints
:
checkpoints
:
save_inference_dir
:
save_inference_dir
:
infer_img
:
infer_img
:
...
...
configs/rec/rec_icdar15_train.yml
浏览文件 @
9023a5c5
...
@@ -15,7 +15,7 @@ Global:
...
@@ -15,7 +15,7 @@ Global:
character_type
:
en
character_type
:
en
loss_type
:
ctc
loss_type
:
ctc
reader_yml
:
./configs/rec/rec_icdar15_reader.yml
reader_yml
:
./configs/rec/rec_icdar15_reader.yml
pretrain_weights
:
pretrain_weights
:
./pretrain_models/rec_mv3_none_bilstm_ctc/best_accuracy
checkpoints
:
checkpoints
:
save_inference_dir
:
save_inference_dir
:
infer_img
:
infer_img
:
...
...
configs/rec/rec_mv3_none_bilstm_ctc.yml
浏览文件 @
9023a5c5
Global
:
Global
:
algorithm
:
CRNN
algorithm
:
CRNN
use_gpu
:
fals
e
use_gpu
:
tru
e
epoch_num
:
72
epoch_num
:
72
log_smooth_window
:
20
log_smooth_window
:
20
print_batch_step
:
10
print_batch_step
:
10
...
...
configs/rec/rec_mv3_tps_bilstm_attn.yml
浏览文件 @
9023a5c5
Global
:
Global
:
algorithm
:
RARE
algorithm
:
RARE
use_gpu
:
fals
e
use_gpu
:
tru
e
epoch_num
:
72
epoch_num
:
72
log_smooth_window
:
20
log_smooth_window
:
20
print_batch_step
:
10
print_batch_step
:
10
...
@@ -12,8 +12,7 @@ Global:
...
@@ -12,8 +12,7 @@ Global:
test_batch_size_per_card
:
256
test_batch_size_per_card
:
256
image_shape
:
[
3
,
32
,
100
]
image_shape
:
[
3
,
32
,
100
]
max_text_length
:
25
max_text_length
:
25
character_type
:
ch
character_type
:
en
character_dict_path
:
./ppocr/utils/ppocr_keys_v1.txt
loss_type
:
attention
loss_type
:
attention
tps
:
true
tps
:
true
reader_yml
:
./configs/rec/rec_benchmark_reader.yml
reader_yml
:
./configs/rec/rec_benchmark_reader.yml
...
...
doc/inference.md
浏览文件 @
9023a5c5
...
@@ -165,6 +165,12 @@ STAR-Net文本识别模型推理,可以执行如下命令:
...
@@ -165,6 +165,12 @@ STAR-Net文本识别模型推理,可以执行如下命令:
```
```
python3 tools/infer/predict_rec.py --image_dir="./doc/imgs_words_en/word_336.png" --rec_model_dir="./inference/starnet/" --rec_image_shape="3, 32, 100" --rec_char_type="en"
python3 tools/infer/predict_rec.py --image_dir="./doc/imgs_words_en/word_336.png" --rec_model_dir="./inference/starnet/" --rec_image_shape="3, 32, 100" --rec_char_type="en"
```
```
RARE 文本识别模型推理,可以执行如下命令:
```
python3 tools/infer/predict_rec.py --image_dir="./doc/imgs_words_en/word_336.png" --rec_model_dir="./inference/sare/" --rec_image_shape="3, 32, 100" --rec_char_type="en" --rec_algorithm="RARE"
```
![](
imgs_words_en/word_336.png
)
![](
imgs_words_en/word_336.png
)
执行命令后,上面图像的识别结果如下:
执行命令后,上面图像的识别结果如下:
...
...
tools/infer/predict_rec.py
浏览文件 @
9023a5c5
...
@@ -32,10 +32,14 @@ class TextRecognizer(object):
...
@@ -32,10 +32,14 @@ class TextRecognizer(object):
self
.
rec_image_shape
=
image_shape
self
.
rec_image_shape
=
image_shape
self
.
character_type
=
args
.
rec_char_type
self
.
character_type
=
args
.
rec_char_type
self
.
rec_batch_num
=
args
.
rec_batch_num
self
.
rec_batch_num
=
args
.
rec_batch_num
self
.
rec_algorithm
=
args
.
rec_algorithm
char_ops_params
=
{}
char_ops_params
=
{}
char_ops_params
[
"character_type"
]
=
args
.
rec_char_type
char_ops_params
[
"character_type"
]
=
args
.
rec_char_type
char_ops_params
[
"character_dict_path"
]
=
args
.
rec_char_dict_path
char_ops_params
[
"character_dict_path"
]
=
args
.
rec_char_dict_path
char_ops_params
[
'loss_type'
]
=
'ctc'
if
self
.
rec_algorithm
!=
"RARE"
:
char_ops_params
[
'loss_type'
]
=
'ctc'
else
:
char_ops_params
[
'loss_type'
]
=
'attention'
self
.
char_ops
=
CharacterOps
(
char_ops_params
)
self
.
char_ops
=
CharacterOps
(
char_ops_params
)
def
resize_norm_img
(
self
,
img
,
max_wh_ratio
):
def
resize_norm_img
(
self
,
img
,
max_wh_ratio
):
...
@@ -81,7 +85,7 @@ class TextRecognizer(object):
...
@@ -81,7 +85,7 @@ class TextRecognizer(object):
self
.
input_tensor
.
copy_from_cpu
(
norm_img_batch
)
self
.
input_tensor
.
copy_from_cpu
(
norm_img_batch
)
self
.
predictor
.
zero_copy_run
()
self
.
predictor
.
zero_copy_run
()
if
args
.
rec_algorithm
!=
"RARE"
:
if
self
.
rec_algorithm
!=
"RARE"
:
rec_idx_batch
=
self
.
output_tensors
[
0
].
copy_to_cpu
()
rec_idx_batch
=
self
.
output_tensors
[
0
].
copy_to_cpu
()
rec_idx_lod
=
self
.
output_tensors
[
0
].
lod
()[
0
]
rec_idx_lod
=
self
.
output_tensors
[
0
].
lod
()[
0
]
predict_batch
=
self
.
output_tensors
[
1
].
copy_to_cpu
()
predict_batch
=
self
.
output_tensors
[
1
].
copy_to_cpu
()
...
@@ -104,6 +108,8 @@ class TextRecognizer(object):
...
@@ -104,6 +108,8 @@ class TextRecognizer(object):
else
:
else
:
rec_idx_batch
=
self
.
output_tensors
[
0
].
copy_to_cpu
()
rec_idx_batch
=
self
.
output_tensors
[
0
].
copy_to_cpu
()
predict_batch
=
self
.
output_tensors
[
1
].
copy_to_cpu
()
predict_batch
=
self
.
output_tensors
[
1
].
copy_to_cpu
()
elapse
=
time
.
time
()
-
starttime
predict_time
+=
elapse
for
rno
in
range
(
len
(
rec_idx_batch
)):
for
rno
in
range
(
len
(
rec_idx_batch
)):
end_pos
=
np
.
where
(
rec_idx_batch
[
rno
,
:]
==
1
)[
0
]
end_pos
=
np
.
where
(
rec_idx_batch
[
rno
,
:]
==
1
)[
0
]
if
len
(
end_pos
)
<=
1
:
if
len
(
end_pos
)
<=
1
:
...
@@ -112,8 +118,6 @@ class TextRecognizer(object):
...
@@ -112,8 +118,6 @@ class TextRecognizer(object):
else
:
else
:
preds
=
rec_idx_batch
[
rno
,
1
:
end_pos
[
1
]]
preds
=
rec_idx_batch
[
rno
,
1
:
end_pos
[
1
]]
score
=
np
.
mean
(
predict_batch
[
rno
,
1
:
end_pos
[
1
]])
score
=
np
.
mean
(
predict_batch
[
rno
,
1
:
end_pos
[
1
]])
#attenton index has 2 offset: beg and end
preds
=
preds
-
2
preds_text
=
self
.
char_ops
.
decode
(
preds
)
preds_text
=
self
.
char_ops
.
decode
(
preds
)
rec_res
.
append
([
preds_text
,
score
])
rec_res
.
append
([
preds_text
,
score
])
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录