Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
PaddleRec
提交
71824d93
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看板
提交
71824d93
编写于
7月 21, 2020
作者:
M
malin10
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
update
上级
91a870d4
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
20 addition
and
2 deletion
+20
-2
core/metric.py
core/metric.py
+13
-2
core/metrics/precision.py
core/metrics/precision.py
+2
-0
core/trainers/framework/runner.py
core/trainers/framework/runner.py
+5
-0
未找到文件。
core/metric.py
浏览文件 @
71824d93
...
@@ -13,6 +13,8 @@
...
@@ -13,6 +13,8 @@
# limitations under the License.
# limitations under the License.
import
abc
import
abc
import
paddle.fluid
as
fluid
import
numpy
as
np
class
Metric
(
object
):
class
Metric
(
object
):
...
@@ -24,14 +26,23 @@ class Metric(object):
...
@@ -24,14 +26,23 @@ class Metric(object):
""" """
""" """
pass
pass
def
clear
(
self
,
scope
,
param
s
):
def
clear
(
self
,
scope
=
None
,
**
kwarg
s
):
"""
"""
clear current value
clear current value
Args:
Args:
scope: value container
scope: value container
params: extend varilable for clear
params: extend varilable for clear
"""
"""
pass
if
scope
is
None
:
scope
=
fluid
.
global_scope
()
place
=
fluid
.
CPUPlace
()
for
(
varname
,
dtype
)
in
self
.
_need_clear_list
:
if
scope
.
find_var
(
varname
)
is
None
:
continue
var
=
scope
.
var
(
varname
).
get_tensor
()
data_array
=
np
.
zeros
(
var
.
_get_dims
()).
astype
(
dtype
)
var
.
set
(
data_array
,
place
)
def
calculate
(
self
,
scope
,
params
):
def
calculate
(
self
,
scope
,
params
):
"""
"""
...
...
core/metrics/precision.py
浏览文件 @
71824d93
...
@@ -99,6 +99,8 @@ class Precision(Metric):
...
@@ -99,6 +99,8 @@ class Precision(Metric):
self
.
accuracy
=
local_pos_num
/
local_ins_num
self
.
accuracy
=
local_pos_num
/
local_ins_num
self
.
_need_clear_list
=
[(
"local_ins_num"
,
"float32"
),
(
"local_pos_num"
,
"float32"
)]
self
.
metrics
=
dict
()
self
.
metrics
=
dict
()
metric_varname
=
"P@%d"
%
kwargs
.
get
(
"k"
)
metric_varname
=
"P@%d"
%
kwargs
.
get
(
"k"
)
self
.
metrics
[
metric_varname
]
=
self
.
accuracy
self
.
metrics
[
metric_varname
]
=
self
.
accuracy
...
...
core/trainers/framework/runner.py
浏览文件 @
71824d93
...
@@ -221,6 +221,7 @@ class RunnerBase(object):
...
@@ -221,6 +221,7 @@ class RunnerBase(object):
program
=
context
[
"model"
][
model_name
][
"main_program"
].
clone
()
program
=
context
[
"model"
][
model_name
][
"main_program"
].
clone
()
_exe_strategy
,
_build_strategy
=
self
.
_get_strategy
(
model_dict
,
_exe_strategy
,
_build_strategy
=
self
.
_get_strategy
(
model_dict
,
context
)
context
)
program
=
fluid
.
compiler
.
CompiledProgram
(
program
).
with_data_parallel
(
program
=
fluid
.
compiler
.
CompiledProgram
(
program
).
with_data_parallel
(
loss_name
=
model_class
.
get_avg_cost
().
name
,
loss_name
=
model_class
.
get_avg_cost
().
name
,
build_strategy
=
_build_strategy
,
build_strategy
=
_build_strategy
,
...
@@ -497,6 +498,10 @@ class SingleInferRunner(RunnerBase):
...
@@ -497,6 +498,10 @@ class SingleInferRunner(RunnerBase):
with
fluid
.
program_guard
(
train_prog
,
startup_prog
):
with
fluid
.
program_guard
(
train_prog
,
startup_prog
):
fluid
.
io
.
load_persistables
(
fluid
.
io
.
load_persistables
(
context
[
"exe"
],
model_path
,
main_program
=
train_prog
)
context
[
"exe"
],
model_path
,
main_program
=
train_prog
)
clear_metrics
=
context
[
"model"
][
model_dict
[
"name"
]][
"model"
].
get_clear_metrics
()
for
var
in
clear_metrics
:
var
.
clear
()
def
_dir_check
(
self
,
context
):
def
_dir_check
(
self
,
context
):
dirname
=
envs
.
get_global_env
(
dirname
=
envs
.
get_global_env
(
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录