Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
hapi
提交
fe362526
H
hapi
项目概览
PaddlePaddle
/
hapi
通知
11
Star
2
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
4
列表
看板
标记
里程碑
合并请求
7
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
H
hapi
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
4
Issue
4
列表
看板
标记
里程碑
合并请求
7
合并请求
7
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
fe362526
编写于
4月 21, 2020
作者:
Q
qingqing01
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Change MyProgBarLogger to LoggerCallBack
上级
5e496435
变更
4
显示空白变更内容
内联
并排
Showing
4 changed file
with
12 addition
and
12 deletion
+12
-12
examples/ocr/eval.py
examples/ocr/eval.py
+3
-3
examples/ocr/train.py
examples/ocr/train.py
+2
-2
examples/ocr/utility.py
examples/ocr/utility.py
+6
-6
hapi/model.py
hapi/model.py
+1
-1
未找到文件。
examples/ocr/eval.py
浏览文件 @
fe362526
...
@@ -23,7 +23,7 @@ from hapi.model import Input, set_device
...
@@ -23,7 +23,7 @@ from hapi.model import Input, set_device
from
hapi.vision.transforms
import
BatchCompose
from
hapi.vision.transforms
import
BatchCompose
from
utility
import
add_arguments
,
print_arguments
from
utility
import
add_arguments
,
print_arguments
from
utility
import
SeqAccuracy
,
MyProgBarLogger
,
SeqBeamAccuracy
from
utility
import
SeqAccuracy
,
LoggerCallBack
,
SeqBeamAccuracy
from
utility
import
postprocess
from
utility
import
postprocess
from
seq2seq_attn
import
Seq2SeqAttModel
,
Seq2SeqAttInferModel
,
WeightCrossEntropy
from
seq2seq_attn
import
Seq2SeqAttModel
,
Seq2SeqAttInferModel
,
WeightCrossEntropy
import
data
import
data
...
@@ -91,7 +91,7 @@ def main(FLAGS):
...
@@ -91,7 +91,7 @@ def main(FLAGS):
model
.
evaluate
(
model
.
evaluate
(
eval_data
=
test_loader
,
eval_data
=
test_loader
,
callbacks
=
[
MyProgBarLogger
(
10
,
2
,
FLAGS
.
batch_size
)])
callbacks
=
[
LoggerCallBack
(
10
,
2
,
FLAGS
.
batch_size
)])
def
beam_search
(
FLAGS
):
def
beam_search
(
FLAGS
):
...
@@ -140,7 +140,7 @@ def beam_search(FLAGS):
...
@@ -140,7 +140,7 @@ def beam_search(FLAGS):
model
.
evaluate
(
model
.
evaluate
(
eval_data
=
test_loader
,
eval_data
=
test_loader
,
callbacks
=
[
MyProgBarLogger
(
10
,
2
,
FLAGS
.
batch_size
)])
callbacks
=
[
LoggerCallBack
(
10
,
2
,
FLAGS
.
batch_size
)])
if
__name__
==
'__main__'
:
if
__name__
==
'__main__'
:
...
...
examples/ocr/train.py
浏览文件 @
fe362526
...
@@ -28,7 +28,7 @@ from hapi.model import Input, set_device
...
@@ -28,7 +28,7 @@ from hapi.model import Input, set_device
from
hapi.vision.transforms
import
BatchCompose
from
hapi.vision.transforms
import
BatchCompose
from
utility
import
add_arguments
,
print_arguments
from
utility
import
add_arguments
,
print_arguments
from
utility
import
SeqAccuracy
,
MyProgBarLogger
from
utility
import
SeqAccuracy
,
LoggerCallBack
from
seq2seq_attn
import
Seq2SeqAttModel
,
WeightCrossEntropy
from
seq2seq_attn
import
Seq2SeqAttModel
,
WeightCrossEntropy
import
data
import
data
...
@@ -129,7 +129,7 @@ def main(FLAGS):
...
@@ -129,7 +129,7 @@ def main(FLAGS):
eval_data
=
test_loader
,
eval_data
=
test_loader
,
epochs
=
FLAGS
.
epoch
,
epochs
=
FLAGS
.
epoch
,
save_dir
=
FLAGS
.
checkpoint_path
,
save_dir
=
FLAGS
.
checkpoint_path
,
callbacks
=
[
MyProgBarLogger
(
10
,
2
,
FLAGS
.
batch_size
)])
callbacks
=
[
LoggerCallBack
(
10
,
2
,
FLAGS
.
batch_size
)])
if
__name__
==
'__main__'
:
if
__name__
==
'__main__'
:
...
...
examples/ocr/utility.py
浏览文件 @
fe362526
...
@@ -102,31 +102,31 @@ class SeqAccuracy(Metric):
...
@@ -102,31 +102,31 @@ class SeqAccuracy(Metric):
return
self
.
_name
return
self
.
_name
class
MyProgBarLogger
(
ProgBarLogger
):
class
LoggerCallBack
(
ProgBarLogger
):
def
__init__
(
self
,
log_freq
=
1
,
verbose
=
2
,
train_bs
=
None
,
eval_bs
=
None
):
def
__init__
(
self
,
log_freq
=
1
,
verbose
=
2
,
train_bs
=
None
,
eval_bs
=
None
):
super
(
MyProgBarLogger
,
self
).
__init__
(
log_freq
,
verbose
)
super
(
LoggerCallBack
,
self
).
__init__
(
log_freq
,
verbose
)
self
.
train_bs
=
train_bs
self
.
train_bs
=
train_bs
self
.
eval_bs
=
eval_bs
if
eval_bs
else
train_bs
self
.
eval_bs
=
eval_bs
if
eval_bs
else
train_bs
def
on_train_batch_end
(
self
,
step
,
logs
=
None
):
def
on_train_batch_end
(
self
,
step
,
logs
=
None
):
logs
=
logs
or
{}
logs
=
logs
or
{}
logs
[
'loss'
]
=
[
l
/
self
.
train_bs
for
l
in
logs
[
'loss'
]]
logs
[
'loss'
]
=
[
l
/
self
.
train_bs
for
l
in
logs
[
'loss'
]]
super
(
MyProgBarLogger
,
self
).
on_train_batch_end
(
step
,
logs
)
super
(
LoggerCallBack
,
self
).
on_train_batch_end
(
step
,
logs
)
def
on_epoch_end
(
self
,
epoch
,
logs
=
None
):
def
on_epoch_end
(
self
,
epoch
,
logs
=
None
):
logs
=
logs
or
{}
logs
=
logs
or
{}
logs
[
'loss'
]
=
[
l
/
self
.
train_bs
for
l
in
logs
[
'loss'
]]
logs
[
'loss'
]
=
[
l
/
self
.
train_bs
for
l
in
logs
[
'loss'
]]
super
(
MyProgBarLogger
,
self
).
on_epoch_end
(
epoch
,
logs
)
super
(
LoggerCallBack
,
self
).
on_epoch_end
(
epoch
,
logs
)
def
on_eval_batch_end
(
self
,
step
,
logs
=
None
):
def
on_eval_batch_end
(
self
,
step
,
logs
=
None
):
logs
=
logs
or
{}
logs
=
logs
or
{}
logs
[
'loss'
]
=
[
l
/
self
.
eval_bs
for
l
in
logs
[
'loss'
]]
logs
[
'loss'
]
=
[
l
/
self
.
eval_bs
for
l
in
logs
[
'loss'
]]
super
(
MyProgBarLogger
,
self
).
on_eval_batch_end
(
step
,
logs
)
super
(
LoggerCallBack
,
self
).
on_eval_batch_end
(
step
,
logs
)
def
on_eval_end
(
self
,
logs
=
None
):
def
on_eval_end
(
self
,
logs
=
None
):
logs
=
logs
or
{}
logs
=
logs
or
{}
logs
[
'loss'
]
=
[
l
/
self
.
eval_bs
for
l
in
logs
[
'loss'
]]
logs
[
'loss'
]
=
[
l
/
self
.
eval_bs
for
l
in
logs
[
'loss'
]]
super
(
MyProgBarLogger
,
self
).
on_eval_end
(
logs
)
super
(
LoggerCallBack
,
self
).
on_eval_end
(
logs
)
def
index2word
(
ids
):
def
index2word
(
ids
):
...
...
hapi/model.py
浏览文件 @
fe362526
...
@@ -1267,7 +1267,7 @@ class Model(fluid.dygraph.Layer):
...
@@ -1267,7 +1267,7 @@ class Model(fluid.dygraph.Layer):
if
mode
==
'train'
:
if
mode
==
'train'
:
assert
epoch
is
not
None
,
'when mode is train, epoch must be given'
assert
epoch
is
not
None
,
'when mode is train, epoch must be given'
callbacks
.
on_epoch_end
(
epoch
)
callbacks
.
on_epoch_end
(
epoch
,
logs
)
return
logs
return
logs
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录