Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
PaddleOCR
提交
be3a1644
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看板
提交
be3a1644
编写于
6月 03, 2020
作者:
T
tink2123
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix inference in tps
上级
b722eb56
变更
6
显示空白变更内容
内联
并排
Showing
6 changed file
with
30 addition
and
7 deletion
+30
-7
configs/rec/rec_mv3_tps_bilstm_attn.yml
configs/rec/rec_mv3_tps_bilstm_attn.yml
+3
-1
configs/rec/rec_mv3_tps_bilstm_ctc.yml
configs/rec/rec_mv3_tps_bilstm_ctc.yml
+1
-0
ppocr/data/rec/dataset_traversal.py
ppocr/data/rec/dataset_traversal.py
+4
-1
ppocr/data/rec/img_tools.py
ppocr/data/rec/img_tools.py
+7
-2
ppocr/modeling/architectures/rec_model.py
ppocr/modeling/architectures/rec_model.py
+13
-1
tools/infer/predict_rec.py
tools/infer/predict_rec.py
+2
-2
未找到文件。
configs/rec/rec_mv3_tps_bilstm_attn.yml
浏览文件 @
be3a1644
...
@@ -12,8 +12,10 @@ Global:
...
@@ -12,8 +12,10 @@ 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
:
en
character_type
:
ch
character_dict_path
:
./ppocr/utils/ppocr_keys_v1.txt
loss_type
:
attention
loss_type
:
attention
tps
:
true
reader_yml
:
./configs/rec/rec_benchmark_reader.yml
reader_yml
:
./configs/rec/rec_benchmark_reader.yml
pretrain_weights
:
pretrain_weights
:
checkpoints
:
checkpoints
:
...
...
configs/rec/rec_mv3_tps_bilstm_ctc.yml
浏览文件 @
be3a1644
...
@@ -14,6 +14,7 @@ Global:
...
@@ -14,6 +14,7 @@ Global:
max_text_length
:
25
max_text_length
:
25
character_type
:
en
character_type
:
en
loss_type
:
ctc
loss_type
:
ctc
tps
:
true
reader_yml
:
./configs/rec/rec_benchmark_reader.yml
reader_yml
:
./configs/rec/rec_benchmark_reader.yml
pretrain_weights
:
pretrain_weights
:
checkpoints
:
checkpoints
:
...
...
ppocr/data/rec/dataset_traversal.py
浏览文件 @
be3a1644
...
@@ -41,6 +41,8 @@ class LMDBReader(object):
...
@@ -41,6 +41,8 @@ class LMDBReader(object):
self
.
loss_type
=
params
[
'loss_type'
]
self
.
loss_type
=
params
[
'loss_type'
]
self
.
max_text_length
=
params
[
'max_text_length'
]
self
.
max_text_length
=
params
[
'max_text_length'
]
self
.
mode
=
params
[
'mode'
]
self
.
mode
=
params
[
'mode'
]
if
"tps"
in
params
:
self
.
tps
=
True
if
params
[
'mode'
]
==
'train'
:
if
params
[
'mode'
]
==
'train'
:
self
.
batch_size
=
params
[
'train_batch_size_per_card'
]
self
.
batch_size
=
params
[
'train_batch_size_per_card'
]
self
.
drop_last
=
params
[
'drop_last'
]
self
.
drop_last
=
params
[
'drop_last'
]
...
@@ -109,7 +111,8 @@ class LMDBReader(object):
...
@@ -109,7 +111,8 @@ class LMDBReader(object):
norm_img
=
process_image
(
norm_img
=
process_image
(
img
=
img
,
img
=
img
,
image_shape
=
self
.
image_shape
,
image_shape
=
self
.
image_shape
,
char_ops
=
self
.
char_ops
)
char_ops
=
self
.
char_ops
,
tps
=
self
.
tps
)
yield
norm_img
yield
norm_img
else
:
else
:
lmdb_sets
=
self
.
load_hierarchical_lmdb_dataset
()
lmdb_sets
=
self
.
load_hierarchical_lmdb_dataset
()
...
...
ppocr/data/rec/img_tools.py
浏览文件 @
be3a1644
...
@@ -92,9 +92,14 @@ def process_image(img,
...
@@ -92,9 +92,14 @@ def process_image(img,
label
=
None
,
label
=
None
,
char_ops
=
None
,
char_ops
=
None
,
loss_type
=
None
,
loss_type
=
None
,
max_text_length
=
None
):
max_text_length
=
None
,
tps
=
None
):
if
char_ops
.
character_type
==
"en"
:
if
char_ops
.
character_type
==
"en"
:
norm_img
=
resize_norm_img
(
img
,
image_shape
)
norm_img
=
resize_norm_img
(
img
,
image_shape
)
else
:
if
tps
:
image_shape
=
[
3
,
32
,
320
]
norm_img
=
resize_norm_img
(
img
,
image_shape
)
else
:
else
:
norm_img
=
resize_norm_img_chinese
(
img
,
image_shape
)
norm_img
=
resize_norm_img_chinese
(
img
,
image_shape
)
norm_img
=
norm_img
[
np
.
newaxis
,
:]
norm_img
=
norm_img
[
np
.
newaxis
,
:]
...
...
ppocr/modeling/architectures/rec_model.py
浏览文件 @
be3a1644
...
@@ -30,6 +30,7 @@ class RecModel(object):
...
@@ -30,6 +30,7 @@ class RecModel(object):
global_params
=
params
[
'Global'
]
global_params
=
params
[
'Global'
]
char_num
=
global_params
[
'char_ops'
].
get_char_num
()
char_num
=
global_params
[
'char_ops'
].
get_char_num
()
global_params
[
'char_num'
]
=
char_num
global_params
[
'char_num'
]
=
char_num
self
.
char_type
=
global_params
[
'character_type'
]
if
"TPS"
in
params
:
if
"TPS"
in
params
:
tps_params
=
deepcopy
(
params
[
"TPS"
])
tps_params
=
deepcopy
(
params
[
"TPS"
])
tps_params
.
update
(
global_params
)
tps_params
.
update
(
global_params
)
...
@@ -60,8 +61,8 @@ class RecModel(object):
...
@@ -60,8 +61,8 @@ class RecModel(object):
def
create_feed
(
self
,
mode
):
def
create_feed
(
self
,
mode
):
image_shape
=
deepcopy
(
self
.
image_shape
)
image_shape
=
deepcopy
(
self
.
image_shape
)
image_shape
.
insert
(
0
,
-
1
)
image_shape
.
insert
(
0
,
-
1
)
image
=
fluid
.
data
(
name
=
'image'
,
shape
=
image_shape
,
dtype
=
'float32'
)
if
mode
==
"train"
:
if
mode
==
"train"
:
image
=
fluid
.
data
(
name
=
'image'
,
shape
=
image_shape
,
dtype
=
'float32'
)
if
self
.
loss_type
==
"attention"
:
if
self
.
loss_type
==
"attention"
:
label_in
=
fluid
.
data
(
label_in
=
fluid
.
data
(
name
=
'label_in'
,
name
=
'label_in'
,
...
@@ -86,6 +87,17 @@ class RecModel(object):
...
@@ -86,6 +87,17 @@ class RecModel(object):
use_double_buffer
=
True
,
use_double_buffer
=
True
,
iterable
=
False
)
iterable
=
False
)
else
:
else
:
if
self
.
char_type
==
"ch"
:
image_shape
[
-
1
]
=
-
1
if
self
.
tps
!=
None
:
logger
.
info
(
"WARNRNG!!!
\n
"
"TPS does not support variable shape in chinese!"
"We set default shape=[3,32,320], it may affect the inference effect"
)
image_shape
[
-
1
]
=
320
image
=
fluid
.
data
(
name
=
'image'
,
shape
=
image_shape
,
dtype
=
'float32'
)
labels
=
None
labels
=
None
loader
=
None
loader
=
None
return
image
,
labels
,
loader
return
image
,
labels
,
loader
...
...
tools/infer/predict_rec.py
浏览文件 @
be3a1644
...
@@ -112,7 +112,7 @@ class TextRecognizer(object):
...
@@ -112,7 +112,7 @@ 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
]])
#
todo: why index has 2 offset
#
attenton index has 2 offset: beg and end
preds
=
preds
-
2
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
])
...
@@ -138,7 +138,7 @@ if __name__ == "__main__":
...
@@ -138,7 +138,7 @@ if __name__ == "__main__":
except
:
except
:
logger
.
info
(
logger
.
info
(
"ERROR!!
\n
Input image shape is not equal with config. TPS does not support variable shape.
\n
"
"ERROR!!
\n
Input image shape is not equal with config. TPS does not support variable shape.
\n
"
"Please set --rec_image_shape=input_shape and --rec_char_type='
ch
' "
)
"Please set --rec_image_shape=input_shape and --rec_char_type='
en
' "
)
exit
()
exit
()
for
ino
in
range
(
len
(
img_list
)):
for
ino
in
range
(
len
(
img_list
)):
print
(
"Predicts of %s:%s"
%
(
valid_image_file_list
[
ino
],
rec_res
[
ino
]))
print
(
"Predicts of %s:%s"
%
(
valid_image_file_list
[
ino
],
rec_res
[
ino
]))
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录