Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle
提交
2c3799d1
P
Paddle
项目概览
PaddlePaddle
/
Paddle
大约 1 年 前同步成功
通知
2299
Star
20931
Fork
5422
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1423
列表
看板
标记
里程碑
合并请求
543
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
Paddle
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1,423
Issue
1,423
列表
看板
标记
里程碑
合并请求
543
合并请求
543
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
未验证
提交
2c3799d1
编写于
1月 18, 2021
作者:
1
123malin
提交者:
GitHub
1月 18, 2021
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
test=develop, fix fleet.metric (#30438) (#30473)
* test=develop, fix fleet.metrics(mse, rmse, mae)
上级
27c2f1ea
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
34 addition
and
15 deletion
+34
-15
python/paddle/distributed/fleet/metrics/metric.py
python/paddle/distributed/fleet/metrics/metric.py
+25
-6
python/paddle/fluid/tests/unittests/test_fleet_metric.py
python/paddle/fluid/tests/unittests/test_fleet_metric.py
+9
-9
未找到文件。
python/paddle/distributed/fleet/metrics/metric.py
浏览文件 @
2c3799d1
...
@@ -228,7 +228,7 @@ def mae(abserr, total_ins_num, scope=None, util=None):
...
@@ -228,7 +228,7 @@ def mae(abserr, total_ins_num, scope=None, util=None):
Args:
Args:
abserr(numpy.array|Variable|string): abserr in output of fluid.contrib.layers.ctr_metric_bundle
abserr(numpy.array|Variable|string): abserr in output of fluid.contrib.layers.ctr_metric_bundle
total_ins_num(
int|float): total train/infer instance count
total_ins_num(
numpy.array|Variable|string): total variable
scope(Scope): specific scope
scope(Scope): specific scope
Returns:
Returns:
...
@@ -253,6 +253,11 @@ def mae(abserr, total_ins_num, scope=None, util=None):
...
@@ -253,6 +253,11 @@ def mae(abserr, total_ins_num, scope=None, util=None):
abserr
=
np
.
array
(
scope
.
find_var
(
abserr
.
name
).
get_tensor
())
abserr
=
np
.
array
(
scope
.
find_var
(
abserr
.
name
).
get_tensor
())
elif
isinstance
(
abserr
,
str
):
elif
isinstance
(
abserr
,
str
):
abserr
=
np
.
array
(
scope
.
find_var
(
abserr
).
get_tensor
())
abserr
=
np
.
array
(
scope
.
find_var
(
abserr
).
get_tensor
())
if
isinstance
(
total_ins_num
,
Variable
):
total_ins_num
=
np
.
array
(
scope
.
find_var
(
total_ins_num
.
name
).
get_tensor
())
elif
isinstance
(
total_ins_num
,
str
):
total_ins_num
=
np
.
array
(
scope
.
find_var
(
total_ins_num
).
get_tensor
())
old_metric_shape
=
np
.
array
(
abserr
.
shape
)
old_metric_shape
=
np
.
array
(
abserr
.
shape
)
abserr
=
abserr
.
reshape
(
-
1
)
abserr
=
abserr
.
reshape
(
-
1
)
...
@@ -260,8 +265,9 @@ def mae(abserr, total_ins_num, scope=None, util=None):
...
@@ -260,8 +265,9 @@ def mae(abserr, total_ins_num, scope=None, util=None):
global_metric
=
util
.
all_reduce
(
abserr
,
"sum"
)
global_metric
=
util
.
all_reduce
(
abserr
,
"sum"
)
global_metric
=
global_metric
.
reshape
(
old_metric_shape
)
global_metric
=
global_metric
.
reshape
(
old_metric_shape
)
global_total_num
=
util
.
all_reduce
(
total_ins_num
,
"sum"
)
mae_value
=
global_metric
[
0
]
/
total_ins_num
mae_value
=
float
(
global_metric
[
0
])
/
float
(
global_total_num
[
0
])
return
mae_value
return
mae_value
...
@@ -271,7 +277,7 @@ def rmse(sqrerr, total_ins_num, scope=None, util=None):
...
@@ -271,7 +277,7 @@ def rmse(sqrerr, total_ins_num, scope=None, util=None):
Args:
Args:
sqrerr(numpy.array|Variable|string): sqrerr in output of fluid.contrib.layers.ctr_metric_bundle
sqrerr(numpy.array|Variable|string): sqrerr in output of fluid.contrib.layers.ctr_metric_bundle
total_ins_num(
int|float): total train/infer instance count
total_ins_num(
numpy.array|Variable|string): total variable
scope(Scope): specific scope
scope(Scope): specific scope
Returns:
Returns:
...
@@ -296,14 +302,21 @@ def rmse(sqrerr, total_ins_num, scope=None, util=None):
...
@@ -296,14 +302,21 @@ def rmse(sqrerr, total_ins_num, scope=None, util=None):
sqrerr
=
np
.
array
(
scope
.
find_var
(
sqrerr
.
name
).
get_tensor
())
sqrerr
=
np
.
array
(
scope
.
find_var
(
sqrerr
.
name
).
get_tensor
())
elif
isinstance
(
sqrerr
,
str
):
elif
isinstance
(
sqrerr
,
str
):
sqrerr
=
np
.
array
(
scope
.
find_var
(
sqrerr
).
get_tensor
())
sqrerr
=
np
.
array
(
scope
.
find_var
(
sqrerr
).
get_tensor
())
if
isinstance
(
total_ins_num
,
Variable
):
total_ins_num
=
np
.
array
(
scope
.
find_var
(
total_ins_num
.
name
).
get_tensor
())
elif
isinstance
(
total_ins_num
,
str
):
total_ins_num
=
np
.
array
(
scope
.
find_var
(
total_ins_num
).
get_tensor
())
old_metric_shape
=
np
.
array
(
sqrerr
.
shape
)
old_metric_shape
=
np
.
array
(
sqrerr
.
shape
)
sqrerr
=
sqrerr
.
reshape
(
-
1
)
sqrerr
=
sqrerr
.
reshape
(
-
1
)
global_metric
=
np
.
copy
(
sqrerr
)
*
0
global_metric
=
np
.
copy
(
sqrerr
)
*
0
global_metric
=
util
.
all_reduce
(
sqrerr
,
"sum"
)
global_metric
=
util
.
all_reduce
(
sqrerr
,
"sum"
)
global_metric
=
global_metric
.
reshape
(
old_metric_shape
)
global_metric
=
global_metric
.
reshape
(
old_metric_shape
)
global_total_num
=
util
.
all_reduce
(
total_ins_num
,
"sum"
)
rmse_value
=
math
.
sqrt
(
float
(
global_metric
[
0
])
/
float
(
global_total_num
[
0
]))
rmse_value
=
math
.
sqrt
(
global_metric
[
0
]
/
total_ins_num
)
return
rmse_value
return
rmse_value
...
@@ -313,7 +326,7 @@ def mse(sqrerr, total_ins_num, scope=None, util=None):
...
@@ -313,7 +326,7 @@ def mse(sqrerr, total_ins_num, scope=None, util=None):
Args:
Args:
sqrerr(numpy.array|Variable|string): sqrerr in output of fluid.contrib.layers.ctr_metric_bundle
sqrerr(numpy.array|Variable|string): sqrerr in output of fluid.contrib.layers.ctr_metric_bundle
total_ins_num(
int|float): total train/infer instance count
total_ins_num(
numpy.array|Variable|string): total variable
scope(Scope): specific scope
scope(Scope): specific scope
Returns:
Returns:
...
@@ -338,14 +351,20 @@ def mse(sqrerr, total_ins_num, scope=None, util=None):
...
@@ -338,14 +351,20 @@ def mse(sqrerr, total_ins_num, scope=None, util=None):
sqrerr
=
np
.
array
(
scope
.
find_var
(
sqrerr
.
name
).
get_tensor
())
sqrerr
=
np
.
array
(
scope
.
find_var
(
sqrerr
.
name
).
get_tensor
())
elif
isinstance
(
sqrerr
,
str
):
elif
isinstance
(
sqrerr
,
str
):
sqrerr
=
np
.
array
(
scope
.
find_var
(
sqrerr
).
get_tensor
())
sqrerr
=
np
.
array
(
scope
.
find_var
(
sqrerr
).
get_tensor
())
if
isinstance
(
total_ins_num
,
Variable
):
total_ins_num
=
np
.
array
(
scope
.
find_var
(
total_ins_num
.
name
).
get_tensor
())
elif
isinstance
(
total_ins_num
,
str
):
total_ins_num
=
np
.
array
(
scope
.
find_var
(
total_ins_num
).
get_tensor
())
old_metric_shape
=
np
.
array
(
sqrerr
.
shape
)
old_metric_shape
=
np
.
array
(
sqrerr
.
shape
)
sqrerr
=
sqrerr
.
reshape
(
-
1
)
sqrerr
=
sqrerr
.
reshape
(
-
1
)
global_metric
=
np
.
copy
(
sqrerr
)
*
0
global_metric
=
np
.
copy
(
sqrerr
)
*
0
global_metric
=
util
.
all_reduce
(
sqrerr
,
"sum"
)
global_metric
=
util
.
all_reduce
(
sqrerr
,
"sum"
)
global_metric
=
global_metric
.
reshape
(
old_metric_shape
)
global_metric
=
global_metric
.
reshape
(
old_metric_shape
)
global_total_num
=
util
.
all_reduce
(
total_ins_num
,
"sum"
)
mse_value
=
global_metric
[
0
]
/
total_ins_num
mse_value
=
float
(
global_metric
[
0
])
/
float
(
global_total_num
[
0
])
return
mse_value
return
mse_value
...
...
python/paddle/fluid/tests/unittests/test_fleet_metric.py
浏览文件 @
2c3799d1
...
@@ -101,17 +101,17 @@ class TestFleetMetric(unittest.TestCase):
...
@@ -101,17 +101,17 @@ class TestFleetMetric(unittest.TestCase):
metric
.
max
(
t
,
scope
,
self
.
util
)
metric
.
max
(
t
,
scope
,
self
.
util
)
metric
.
min
(
t
,
scope
,
self
.
util
)
metric
.
min
(
t
,
scope
,
self
.
util
)
metric
.
auc
(
t
,
t1
,
scope
,
self
.
util
)
metric
.
auc
(
t
,
t1
,
scope
,
self
.
util
)
metric
.
mae
(
t
1
,
3
,
scope
,
self
.
util
)
metric
.
mae
(
t
,
t1
,
scope
,
self
.
util
)
metric
.
rmse
(
t
1
,
3
,
scope
,
self
.
util
)
metric
.
rmse
(
t
,
t1
,
scope
,
self
.
util
)
metric
.
mse
(
t
1
,
3
,
scope
,
self
.
util
)
metric
.
mse
(
t
,
t1
,
scope
,
self
.
util
)
metric
.
acc
(
t
,
t1
,
scope
,
self
.
util
)
metric
.
acc
(
t
,
t1
,
scope
,
self
.
util
)
metric
.
sum
(
str
(
t
.
name
))
metric
.
sum
(
str
(
t
.
name
))
metric
.
max
(
str
(
t
.
name
))
metric
.
max
(
str
(
t
.
name
))
metric
.
min
(
str
(
t
.
name
))
metric
.
min
(
str
(
t
.
name
))
metric
.
auc
(
str
(
t1
.
name
),
str
(
t
.
name
))
metric
.
auc
(
str
(
t1
.
name
),
str
(
t
.
name
))
metric
.
mae
(
str
(
t1
.
name
),
3
)
metric
.
mae
(
str
(
t1
.
name
),
str
(
t
.
name
)
)
metric
.
rmse
(
str
(
t1
.
name
),
3
)
metric
.
rmse
(
str
(
t1
.
name
),
str
(
t
.
name
)
)
metric
.
mse
(
str
(
t1
.
name
),
3
)
metric
.
mse
(
str
(
t1
.
name
),
str
(
t
.
name
)
)
metric
.
acc
(
str
(
t
.
name
),
str
(
t1
.
name
))
metric
.
acc
(
str
(
t
.
name
),
str
(
t1
.
name
))
arr
=
np
.
array
([
1
,
2
,
3
,
4
])
arr
=
np
.
array
([
1
,
2
,
3
,
4
])
metric
.
sum
(
arr
,
util
=
self
.
util
)
metric
.
sum
(
arr
,
util
=
self
.
util
)
...
@@ -121,9 +121,9 @@ class TestFleetMetric(unittest.TestCase):
...
@@ -121,9 +121,9 @@ class TestFleetMetric(unittest.TestCase):
arr2
=
np
.
array
([[
1
,
2
,
3
,
4
]])
arr2
=
np
.
array
([[
1
,
2
,
3
,
4
]])
arr3
=
np
.
array
([
1
,
2
,
3
,
4
])
arr3
=
np
.
array
([
1
,
2
,
3
,
4
])
metric
.
auc
(
arr1
,
arr2
,
util
=
self
.
util
)
metric
.
auc
(
arr1
,
arr2
,
util
=
self
.
util
)
metric
.
mae
(
arr
,
3
,
util
=
self
.
util
)
metric
.
mae
(
arr
,
arr
3
,
util
=
self
.
util
)
metric
.
rmse
(
arr
,
3
,
util
=
self
.
util
)
metric
.
rmse
(
arr
,
arr
3
,
util
=
self
.
util
)
metric
.
mse
(
arr
,
3
,
util
=
self
.
util
)
metric
.
mse
(
arr
,
arr
3
,
util
=
self
.
util
)
metric
.
acc
(
arr
,
arr3
,
util
=
self
.
util
)
metric
.
acc
(
arr
,
arr3
,
util
=
self
.
util
)
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录