Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
weixin_41840029
PaddleOCR
提交
f3e88b3a
P
PaddleOCR
项目概览
weixin_41840029
/
PaddleOCR
与 Fork 源项目一致
Fork自
PaddlePaddle / PaddleOCR
通知
1
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
PaddleOCR
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
未验证
提交
f3e88b3a
编写于
7月 24, 2020
作者:
D
dyning
提交者:
GitHub
7月 24, 2020
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #385 from BeyondYourself/develop
Add common code to reduce code duplication
上级
368232cf
4d541eb3
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
34 addition
and
64 deletion
+34
-64
tools/eval.py
tools/eval.py
+2
-20
tools/export_model.py
tools/export_model.py
+2
-20
tools/program.py
tools/program.py
+28
-2
tools/train.py
tools/train.py
+2
-22
未找到文件。
tools/eval.py
浏览文件 @
f3e88b3a
...
...
@@ -45,26 +45,10 @@ from ppocr.utils.save_load import init_model
from
eval_utils.eval_det_utils
import
eval_det_run
from
eval_utils.eval_rec_utils
import
test_rec_benchmark
from
eval_utils.eval_rec_utils
import
eval_rec_run
from
ppocr.utils.character
import
CharacterOps
def
main
():
config
=
program
.
load_config
(
FLAGS
.
config
)
program
.
merge_config
(
FLAGS
.
opt
)
logger
.
info
(
config
)
# check if set use_gpu=True in paddlepaddle cpu version
use_gpu
=
config
[
'Global'
][
'use_gpu'
]
program
.
check_gpu
(
use_gpu
)
alg
=
config
[
'Global'
][
'algorithm'
]
assert
alg
in
[
'EAST'
,
'DB'
,
'Rosetta'
,
'CRNN'
,
'STARNet'
,
'RARE'
]
if
alg
in
[
'Rosetta'
,
'CRNN'
,
'STARNet'
,
'RARE'
]:
config
[
'Global'
][
'char_ops'
]
=
CharacterOps
(
config
[
'Global'
])
place
=
fluid
.
CUDAPlace
(
0
)
if
use_gpu
else
fluid
.
CPUPlace
()
startup_prog
=
fluid
.
Program
()
eval_program
=
fluid
.
Program
()
startup_prog
,
eval_program
,
place
,
config
,
train_alg_type
=
program
.
preprocess
()
eval_build_outputs
=
program
.
build
(
config
,
eval_program
,
startup_prog
,
mode
=
'test'
)
eval_fetch_name_list
=
eval_build_outputs
[
1
]
...
...
@@ -75,7 +59,7 @@ def main():
init_model
(
config
,
eval_program
,
exe
)
if
alg
in
[
'EAST'
,
'DB'
]
:
if
train_alg_type
==
'det'
:
eval_reader
=
reader_main
(
config
=
config
,
mode
=
"eval"
)
eval_info_dict
=
{
'program'
:
eval_program
,
\
'reader'
:
eval_reader
,
\
...
...
@@ -101,6 +85,4 @@ def main():
if
__name__
==
'__main__'
:
parser
=
program
.
ArgsParser
()
FLAGS
=
parser
.
parse_args
()
main
()
tools/export_model.py
浏览文件 @
f3e88b3a
...
...
@@ -41,27 +41,11 @@ from paddle import fluid
from
ppocr.utils.utility
import
initial_logger
logger
=
initial_logger
()
from
ppocr.utils.save_load
import
init_model
from
ppocr.utils.character
import
CharacterOps
from
ppocr.utils.utility
import
create_module
def
main
():
config
=
program
.
load_config
(
FLAGS
.
config
)
program
.
merge_config
(
FLAGS
.
opt
)
logger
.
info
(
config
)
# check if set use_gpu=True in paddlepaddle cpu version
use_gpu
=
config
[
'Global'
][
'use_gpu'
]
program
.
check_gpu
(
use_gpu
)
alg
=
config
[
'Global'
][
'algorithm'
]
assert
alg
in
[
'EAST'
,
'DB'
,
'Rosetta'
,
'CRNN'
,
'STARNet'
,
'RARE'
]
if
alg
in
[
'Rosetta'
,
'CRNN'
,
'STARNet'
,
'RARE'
]:
config
[
'Global'
][
'char_ops'
]
=
CharacterOps
(
config
[
'Global'
])
place
=
fluid
.
CUDAPlace
(
0
)
if
use_gpu
else
fluid
.
CPUPlace
()
startup_prog
=
fluid
.
Program
()
eval_program
=
fluid
.
Program
()
def
main
():
startup_prog
,
eval_program
,
place
,
config
,
_
=
program
.
preprocess
()
feeded_var_names
,
target_vars
,
fetches_var_name
=
program
.
build_export
(
config
,
eval_program
,
startup_prog
)
...
...
@@ -88,6 +72,4 @@ def main():
if
__name__
==
'__main__'
:
parser
=
program
.
ArgsParser
()
FLAGS
=
parser
.
parse_args
()
main
()
tools/program.py
浏览文件 @
f3e88b3a
...
...
@@ -22,6 +22,7 @@ import yaml
import
os
from
ppocr.utils.utility
import
create_module
from
ppocr.utils.utility
import
initial_logger
logger
=
initial_logger
()
import
paddle.fluid
as
fluid
...
...
@@ -31,8 +32,7 @@ from eval_utils.eval_det_utils import eval_det_run
from
eval_utils.eval_rec_utils
import
eval_rec_run
from
ppocr.utils.save_load
import
save_model
import
numpy
as
np
from
ppocr.utils.character
import
cal_predicts_accuracy
from
ppocr.utils.character
import
cal_predicts_accuracy
,
CharacterOps
class
ArgsParser
(
ArgumentParser
):
def
__init__
(
self
):
...
...
@@ -374,3 +374,29 @@ def train_eval_rec_run(config, exe, train_info_dict, eval_info_dict):
save_path
=
save_model_dir
+
"/iter_epoch_%d"
%
(
epoch
)
save_model
(
train_info_dict
[
'train_program'
],
save_path
)
return
def
preprocess
():
FLAGS
=
ArgsParser
().
parse_args
()
config
=
load_config
(
FLAGS
.
config
)
merge_config
(
FLAGS
.
opt
)
logger
.
info
(
config
)
# check if set use_gpu=True in paddlepaddle cpu version
use_gpu
=
config
[
'Global'
][
'use_gpu'
]
check_gpu
(
use_gpu
)
alg
=
config
[
'Global'
][
'algorithm'
]
assert
alg
in
[
'EAST'
,
'DB'
,
'Rosetta'
,
'CRNN'
,
'STARNet'
,
'RARE'
]
if
alg
in
[
'Rosetta'
,
'CRNN'
,
'STARNet'
,
'RARE'
]:
config
[
'Global'
][
'char_ops'
]
=
CharacterOps
(
config
[
'Global'
])
place
=
fluid
.
CUDAPlace
(
0
)
if
use_gpu
else
fluid
.
CPUPlace
()
startup_program
=
fluid
.
Program
()
train_program
=
fluid
.
Program
()
if
alg
in
[
'EAST'
,
'DB'
]:
train_alg_type
=
'det'
else
:
train_alg_type
=
'rec'
return
startup_program
,
train_program
,
place
,
config
,
train_alg_type
tools/train.py
浏览文件 @
f3e88b3a
...
...
@@ -42,27 +42,10 @@ from ppocr.utils.utility import initial_logger
logger
=
initial_logger
()
from
ppocr.data.reader_main
import
reader_main
from
ppocr.utils.save_load
import
init_model
from
ppocr.utils.character
import
CharacterOps
from
paddle.fluid.contrib.model_stat
import
summary
def
main
():
config
=
program
.
load_config
(
FLAGS
.
config
)
program
.
merge_config
(
FLAGS
.
opt
)
logger
.
info
(
config
)
# check if set use_gpu=True in paddlepaddle cpu version
use_gpu
=
config
[
'Global'
][
'use_gpu'
]
program
.
check_gpu
(
use_gpu
)
alg
=
config
[
'Global'
][
'algorithm'
]
assert
alg
in
[
'EAST'
,
'DB'
,
'Rosetta'
,
'CRNN'
,
'STARNet'
,
'RARE'
]
if
alg
in
[
'Rosetta'
,
'CRNN'
,
'STARNet'
,
'RARE'
]:
config
[
'Global'
][
'char_ops'
]
=
CharacterOps
(
config
[
'Global'
])
place
=
fluid
.
CUDAPlace
(
0
)
if
use_gpu
else
fluid
.
CPUPlace
()
startup_program
=
fluid
.
Program
()
train_program
=
fluid
.
Program
()
train_build_outputs
=
program
.
build
(
config
,
train_program
,
startup_program
,
mode
=
'train'
)
train_loader
=
train_build_outputs
[
0
]
...
...
@@ -109,15 +92,13 @@ def main():
'fetch_name_list'
:
eval_fetch_name_list
,
\
'fetch_varname_list'
:
eval_fetch_varname_list
}
if
alg
in
[
'EAST'
,
'DB'
]
:
if
train_alg_type
==
'det'
:
program
.
train_eval_det_run
(
config
,
exe
,
train_info_dict
,
eval_info_dict
)
else
:
program
.
train_eval_rec_run
(
config
,
exe
,
train_info_dict
,
eval_info_dict
)
def
test_reader
():
config
=
program
.
load_config
(
FLAGS
.
config
)
program
.
merge_config
(
FLAGS
.
opt
)
logger
.
info
(
config
)
train_reader
=
reader_main
(
config
=
config
,
mode
=
"train"
)
import
time
...
...
@@ -136,7 +117,6 @@ def test_reader():
if
__name__
==
'__main__'
:
parser
=
program
.
ArgsParser
()
FLAGS
=
parser
.
parse_args
()
startup_program
,
train_program
,
place
,
config
,
train_alg_type
=
program
.
preprocess
()
main
()
# test_reader()
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录