Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
PaddleRec
提交
2cbf686a
P
PaddleRec
项目概览
PaddlePaddle
/
PaddleRec
通知
68
Star
12
Fork
5
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
27
列表
看板
标记
里程碑
合并请求
10
Wiki
1
Wiki
分析
仓库
DevOps
项目成员
Pages
P
PaddleRec
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
27
Issue
27
列表
看板
标记
里程碑
合并请求
10
合并请求
10
Pages
分析
分析
仓库分析
DevOps
Wiki
1
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
2cbf686a
编写于
7月 30, 2020
作者:
M
malin10
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
bug fix
上级
2949a20f
变更
6
显示空白变更内容
内联
并排
Showing
6 changed file
with
31 addition
and
25 deletion
+31
-25
core/metric.py
core/metric.py
+16
-9
core/metrics/binary_class/auc.py
core/metrics/binary_class/auc.py
+7
-7
core/metrics/binary_class/precision_recall.py
core/metrics/binary_class/precision_recall.py
+3
-4
core/metrics/pairwise_pn.py
core/metrics/pairwise_pn.py
+1
-1
core/metrics/recall_k.py
core/metrics/recall_k.py
+1
-1
core/trainers/framework/runner.py
core/trainers/framework/runner.py
+3
-3
未找到文件。
core/metric.py
浏览文件 @
2cbf686a
...
...
@@ -23,11 +23,13 @@ class Metric(object):
__metaclass__
=
abc
.
ABCMeta
def
__init__
(
self
,
config
):
""" """
"""R
"""
pass
def
clear
(
self
,
scope
=
None
):
""" """
"""R
"""
if
scope
is
None
:
scope
=
fluid
.
global_scope
()
...
...
@@ -41,9 +43,13 @@ class Metric(object):
data_array
=
np
.
zeros
(
var
.
_get_dims
()).
astype
(
dtype
)
var
.
set
(
data_array
,
place
)
def
get_global_metric_state
(
self
,
fleet
,
scope
,
metric_name
,
mode
=
"sum"
):
""" """
input
=
np
.
array
(
scope
.
find_var
(
metric_name
).
get_tensor
())
def
_get_global_metric_state
(
self
,
fleet
,
scope
,
metric_name
,
mode
=
"sum"
):
"""R
"""
var
=
scope
.
find_var
(
metric_name
)
if
not
var
:
return
None
input
=
np
.
array
(
var
.
get_tensor
())
if
fleet
is
None
:
return
input
fleet
.
_role_maker
.
_barrier_worker
()
...
...
@@ -54,8 +60,9 @@ class Metric(object):
output
=
output
.
reshape
(
old_shape
)
return
output
def
cal_global_metrics
(
self
,
fleet
,
scope
=
None
):
""" """
def
calc_global_metrics
(
self
,
fleet
,
scope
=
None
):
"""R
"""
if
scope
is
None
:
scope
=
fluid
.
global_scope
()
...
...
@@ -65,9 +72,9 @@ class Metric(object):
global_metrics
[
key
]
=
self
.
get_global_metric_state
(
fleet
,
scope
,
varname
)
return
self
.
calculate
(
global_metrics
)
return
self
.
_
calculate
(
global_metrics
)
def
calculate
(
self
,
global_metrics
):
def
_
calculate
(
self
,
global_metrics
):
pass
@
abc
.
abstractmethod
...
...
core/metrics/binary_class/auc.py
浏览文件 @
2cbf686a
...
...
@@ -74,7 +74,7 @@ class AUC(Metric):
self
.
metrics
[
"AUC"
]
=
auc_out
self
.
metrics
[
"BATCH_AUC"
]
=
batch_auc_out
def
calculate_bucket_error
(
self
,
global_pos
,
global_neg
):
def
_
calculate_bucket_error
(
self
,
global_pos
,
global_neg
):
"""R
"""
num_bucket
=
len
(
global_pos
)
...
...
@@ -122,7 +122,7 @@ class AUC(Metric):
bucket_error
=
error_sum
/
error_count
if
error_count
>
0
else
0.0
return
bucket_error
def
calculate_auc
(
self
,
global_pos
,
global_neg
):
def
_
calculate_auc
(
self
,
global_pos
,
global_neg
):
"""R
"""
num_bucket
=
len
(
global_pos
)
...
...
@@ -148,7 +148,7 @@ class AUC(Metric):
auc_value
=
area
/
(
pos
*
neg
)
return
auc_value
def
calculate
(
self
,
global_metrics
):
def
_
calculate
(
self
,
global_metrics
):
result
=
dict
()
for
key
in
self
.
_global_metric_state_vars
:
if
key
not
in
global_metrics
:
...
...
@@ -165,10 +165,10 @@ class AUC(Metric):
result
[
'copc'
]
=
0
result
[
'mean_q'
]
=
0
else
:
result
[
'auc'
]
=
self
.
calculate_auc
(
result
[
'stat_pos'
],
result
[
'stat_neg'
])
result
[
'bucket_error'
]
=
self
.
calculate_auc
(
result
[
'stat_pos'
],
result
[
'auc'
]
=
self
.
_calculate_auc
(
result
[
'stat_pos'
],
result
[
'stat_neg'
])
result
[
'bucket_error'
]
=
self
.
_calculate_bucket_error
(
result
[
'stat_pos'
],
result
[
'stat_neg'
])
result
[
'actual_ctr'
]
=
result
[
'pos_ins_num'
]
/
result
[
'total_ins_num'
]
result
[
'mae'
]
=
result
[
'abserr'
]
/
result
[
'total_ins_num'
]
...
...
core/metrics/binary_class/precision_recall.py
浏览文件 @
2cbf686a
...
...
@@ -29,7 +29,8 @@ class PrecisionRecall(Metric):
"""
def
__init__
(
self
,
**
kwargs
):
""" """
"""R
"""
if
"input"
not
in
kwargs
or
"label"
not
in
kwargs
or
"class_num"
not
in
kwargs
:
raise
ValueError
(
"PrecisionRecall expect input, label and class_num as inputs."
)
...
...
@@ -107,9 +108,7 @@ class PrecisionRecall(Metric):
self
.
metrics
[
"precision_recall_f1"
]
=
accum_metrics
self
.
metrics
[
"[TP FP TN FN]"
]
=
states_info
# self.metrics["batch_metrics"] = batch_metrics
def
calculate
(
self
,
global_metrics
):
def
_calculate
(
self
,
global_metrics
):
for
key
in
self
.
_global_metric_state_vars
:
if
key
not
in
global_metrics
:
raise
ValueError
(
"%s not existed"
%
key
)
...
...
core/metrics/pairwise_pn.py
浏览文件 @
2cbf686a
...
...
@@ -84,7 +84,7 @@ class PosNegRatio(Metric):
self
.
metrics
[
'RightCnt'
]
=
global_right_cnt
self
.
metrics
[
'PN'
]
=
self
.
pn
def
calculate
(
self
,
global_metrics
):
def
_
calculate
(
self
,
global_metrics
):
for
key
in
self
.
_global_communicate_var
:
if
key
not
in
global_metrics
:
raise
ValueError
(
"%s not existed"
%
key
)
...
...
core/metrics/recall_k.py
浏览文件 @
2cbf686a
...
...
@@ -88,7 +88,7 @@ class RecallK(Metric):
self
.
metrics
[
metric_name
]
=
self
.
acc
# self.metrics["batch_metrics"] = batch_metrics
def
calculate
(
self
,
global_metrics
):
def
_
calculate
(
self
,
global_metrics
):
for
key
in
self
.
_global_metric_state_vars
:
if
key
not
in
global_metrics
:
raise
ValueError
(
"%s not existed"
%
key
)
...
...
core/trainers/framework/runner.py
浏览文件 @
2cbf686a
...
...
@@ -356,7 +356,7 @@ class SingleRunner(RunnerBase):
metrics_result
=
[]
for
key
in
metrics
:
if
isinstance
(
metrics
[
key
],
Metric
):
_str
=
metrics
[
key
].
cal_global_metrics
(
_str
=
metrics
[
key
].
cal
c
_global_metrics
(
None
,
context
[
"model"
][
model_dict
[
"name"
]][
"scope"
])
metrics_result
.
append
(
_str
)
...
...
@@ -404,7 +404,7 @@ class PSRunner(RunnerBase):
metrics_result
=
[]
for
key
in
metrics
:
if
isinstance
(
metrics
[
key
],
Metric
):
_str
=
metrics
[
key
].
cal_global_metrics
(
_str
=
metrics
[
key
].
cal
c
_global_metrics
(
context
[
"fleet"
],
context
[
"model"
][
model_dict
[
"name"
]][
"scope"
])
metrics_result
.
append
(
_str
)
...
...
@@ -536,7 +536,7 @@ class SingleInferRunner(RunnerBase):
metrics_result
=
[]
for
key
in
metrics
:
if
isinstance
(
metrics
[
key
],
Metric
):
_str
=
metrics
[
key
].
cal_global_metrics
(
_str
=
metrics
[
key
].
cal
c
_global_metrics
(
None
,
context
[
"model"
][
model_dict
[
"name"
]][
"scope"
])
metrics_result
.
append
(
_str
)
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录