Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
wangsen
paddle_dbnet
Commits
115955f7
Commit
115955f7
authored
Jun 04, 2021
by
littletomatodonkey
Browse files
fix metric
parent
0343756e
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
85 additions
and
3 deletions
+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
No files found.
configs/rec/ch_ppocr_v2.0/rec_chinese_lite_train_distillation_v2.1.yml
View file @
115955f7
...
@@ -98,7 +98,7 @@ Loss:
...
@@ -98,7 +98,7 @@ Loss:
PostProcess
:
PostProcess
:
name
:
DistillationCTCLabelDecode
name
:
DistillationCTCLabelDecode
model_name
:
[
"
Student"
,
"
Teacher"
]
model_name
:
[
"
Student"
]
key
:
head_out
key
:
head_out
Metric
:
Metric
:
...
...
ppocr/metrics/distillation_metric.py
0 → 100644
View file @
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
View file @
115955f7
...
@@ -46,8 +46,14 @@ def main():
...
@@ -46,8 +46,14 @@ def main():
# build model
# build model
if
hasattr
(
post_process_class
,
'character'
):
if
hasattr
(
post_process_class
,
'character'
):
config
[
'Architecture'
][
"Head"
][
'out_channels'
]
=
len
(
char_num
=
len
(
getattr
(
post_process_class
,
'character'
))
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'
])
model
=
build_model
(
config
[
'Architecture'
])
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment