Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
天天代码码天天
PaddleOCR
提交
115955f7
P
PaddleOCR
项目概览
天天代码码天天
/
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看板
体验新版 GitCode,发现更多精彩内容 >>
提交
115955f7
编写于
6月 04, 2021
作者:
littletomatodonkey
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix metric
上级
0343756e
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
85 addition
and
3 deletion
+85
-3
configs/rec/ch_ppocr_v2.0/rec_chinese_lite_train_distillation_v2.1.yml
...h_ppocr_v2.0/rec_chinese_lite_train_distillation_v2.1.yml
+1
-1
ppocr/metrics/distillation_metric.py
ppocr/metrics/distillation_metric.py
+76
-0
tools/infer_rec.py
tools/infer_rec.py
+8
-2
未找到文件。
configs/rec/ch_ppocr_v2.0/rec_chinese_lite_train_distillation_v2.1.yml
浏览文件 @
115955f7
...
...
@@ -98,7 +98,7 @@ Loss:
PostProcess
:
name
:
DistillationCTCLabelDecode
model_name
:
[
"
Student"
,
"
Teacher"
]
model_name
:
[
"
Student"
]
key
:
head_out
Metric
:
...
...
ppocr/metrics/distillation_metric.py
0 → 100644
浏览文件 @
115955f7
# copyright (c) 2020 PaddlePaddle Authors. All Rights Reserve.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import
importlib
import
copy
from
.rec_metric
import
RecMetric
from
.det_metric
import
DetMetric
from
.e2e_metric
import
E2EMetric
from
.cls_metric
import
ClsMetric
class
DistillationMetric
(
object
):
def
__init__
(
self
,
key
=
None
,
base_metric_name
=
"RecMetric"
,
main_indicator
=
'acc'
,
**
kwargs
):
self
.
main_indicator
=
main_indicator
self
.
key
=
key
self
.
main_indicator
=
main_indicator
self
.
base_metric_name
=
base_metric_name
self
.
kwargs
=
kwargs
self
.
metrics
=
None
def
_init_metrcis
(
self
,
preds
):
self
.
metrics
=
dict
()
mod
=
importlib
.
import_module
(
__name__
)
for
key
in
preds
:
self
.
metrics
[
key
]
=
getattr
(
mod
,
self
.
base_metric_name
)(
main_indicator
=
self
.
main_indicator
,
**
self
.
kwargs
)
self
.
metrics
[
key
].
reset
()
def
__call__
(
self
,
preds
,
*
args
,
**
kwargs
):
assert
isinstance
(
preds
,
dict
)
if
self
.
metrics
is
None
:
self
.
_init_metrcis
(
preds
)
output
=
dict
()
for
key
in
preds
:
metric
=
self
.
metrics
[
key
].
__call__
(
preds
[
key
],
*
args
,
**
kwargs
)
for
sub_key
in
metric
:
output
[
"{}_{}"
.
format
(
key
,
sub_key
)]
=
metric
[
sub_key
]
return
output
def
get_metric
(
self
):
"""
return metrics {
'acc': 0,
'norm_edit_dis': 0,
}
"""
output
=
dict
()
for
key
in
self
.
metrics
:
metric
=
self
.
metrics
[
key
].
get_metric
()
# main indicator
if
key
==
self
.
key
:
output
.
update
(
metric
)
else
:
for
sub_key
in
metric
:
output
[
"{}_{}"
.
format
(
key
,
sub_key
)]
=
metric
[
sub_key
]
return
output
def
reset
(
self
):
for
key
in
self
.
metrics
:
self
.
metrics
[
key
].
reset
()
tools/infer_rec.py
浏览文件 @
115955f7
...
...
@@ -46,8 +46,14 @@ def main():
# build model
if
hasattr
(
post_process_class
,
'character'
):
config
[
'Architecture'
][
"Head"
][
'out_channels'
]
=
len
(
getattr
(
post_process_class
,
'character'
))
char_num
=
len
(
getattr
(
post_process_class
,
'character'
))
if
config
[
'Architecture'
][
"algorithm"
]
in
[
"Distillation"
,
]:
# distillation model
for
key
in
config
[
'Architecture'
][
"Models"
]:
config
[
'Architecture'
][
"Models"
][
key
][
"Head"
][
'out_channels'
]
=
char_num
else
:
# base rec model
config
[
'Architecture'
][
"Head"
][
'out_channels'
]
=
char_num
model
=
build_model
(
config
[
'Architecture'
])
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录