Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
BaiXuePrincess
Paddle
提交
5b4e7d5c
P
Paddle
项目概览
BaiXuePrincess
/
Paddle
与 Fork 源项目一致
Fork自
PaddlePaddle / Paddle
通知
1
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
Paddle
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
5b4e7d5c
编写于
2月 19, 2017
作者:
Y
Yu Yang
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
complete value printer
上级
5ecc1a21
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
80 addition
and
10 deletion
+80
-10
paddle/gserver/evaluators/Evaluator.cpp
paddle/gserver/evaluators/Evaluator.cpp
+80
-10
未找到文件。
paddle/gserver/evaluators/Evaluator.cpp
浏览文件 @
5b4e7d5c
...
...
@@ -13,9 +13,9 @@ See the License for the specific language governing permissions and
limitations under the License. */
#include "paddle/gserver/evaluators/Evaluator.h"
#include "paddle/utils/Stat.h"
#include "paddle/gserver/gradientmachines/NeuralNetwork.h"
#include "paddle/utils/Stat.h"
#include "paddle/utils/StringUtil.h"
DECLARE_int32
(
trainer_id
);
...
...
@@ -801,7 +801,9 @@ void PrecisionRecallEvaluator::getNames(std::vector<std::string>* names) {
real
PrecisionRecallEvaluator
::
getValue
(
const
std
::
string
&
name
,
Error
*
err
)
const
{
this
->
storeLocalValues
();
auto
it
=
this
->
values_
.
find
(
name
);
std
::
vector
<
std
::
string
>
buffers
;
paddle
::
str
::
split
(
name
,
'.'
,
&
buffers
);
auto
it
=
this
->
values_
.
find
(
buffers
[
buffers
.
size
()
-
1
]);
if
(
it
!=
this
->
values_
.
end
()
&&
err
!=
nullptr
)
{
*
err
=
Error
(
"No such key %s"
,
name
.
c_str
());
return
.0
f
;
...
...
@@ -812,10 +814,12 @@ real PrecisionRecallEvaluator::getValue(const std::string& name,
std
::
string
PrecisionRecallEvaluator
::
getType
(
const
std
::
string
&
name
,
Error
*
err
)
const
{
this
->
storeLocalValues
();
auto
it
=
this
->
values_
.
find
(
name
);
if
(
it
!=
this
->
values_
.
end
()
&&
err
!=
nullptr
)
{
*
err
=
Error
(
"No such key %s"
,
name
.
c_str
());
Error
localErr
;
if
(
err
==
nullptr
)
{
err
=
&
localErr
;
}
this
->
getValue
(
name
,
err
);
if
(
!
err
->
isOK
())
{
return
""
;
}
return
"precision_recall"
;
...
...
@@ -989,12 +993,12 @@ static InitFunction __reg_type_auc_sum__([]() {
*/
class
ValuePrinter
:
public
Evaluator
{
public:
ValuePrinter
()
{}
virtual
void
eval
(
const
NeuralNetwork
&
nn
)
{
layerOutputs_
.
clear
();
for
(
const
std
::
string
&
name
:
config_
.
input_layers
())
{
auto
&
argu
=
nn
.
getLayer
(
name
)
->
getOutput
();
std
::
unordered_map
<
std
::
string
,
std
::
string
>
out
;
layerOutputs_
[
name
]
=
std
::
unordered_map
<
std
::
string
,
std
::
string
>
();
auto
&
out
=
layerOutputs_
[
name
];
argu
.
getValueString
(
&
out
);
for
(
auto
field
:
{
"value"
,
"id"
,
"sequence pos"
,
"sub-sequence pos"
})
{
auto
it
=
out
.
find
(
field
);
...
...
@@ -1008,6 +1012,72 @@ public:
virtual
void
updateSamplesNum
(
const
std
::
vector
<
Argument
>&
arguments
)
{}
virtual
real
evalImp
(
std
::
vector
<
Argument
>&
arguments
)
{
return
0
;
}
private:
std
::
unordered_map
<
std
::
string
,
std
::
unordered_map
<
std
::
string
,
std
::
string
>>
layerOutputs_
;
// Evaluator interface
public:
void
getNames
(
std
::
vector
<
std
::
string
>*
names
)
{
for
(
auto
layerIt
=
layerOutputs_
.
begin
();
layerIt
!=
layerOutputs_
.
end
();
++
layerIt
)
{
for
(
auto
it
=
layerIt
->
second
.
begin
();
it
!=
layerIt
->
second
.
end
();
++
it
)
{
names
->
push_back
(
config_
.
name
()
+
"."
+
layerIt
->
first
+
"."
+
it
->
second
);
}
}
}
real
getValue
(
const
std
::
string
&
name
,
Error
*
err
)
const
{
(
void
)(
name
);
if
(
err
!=
nullptr
)
{
*
err
=
Error
(
"ValuePrinter do not support getValue, use getValueString instead."
);
}
return
.0
f
;
}
std
::
string
getValueStr
(
const
std
::
string
&
name
,
Error
*
err
)
const
{
std
::
vector
<
std
::
string
>
buffer
;
str
::
split
(
name
,
'.'
,
&
buffer
);
if
(
buffer
.
size
()
<
2
)
{
if
(
err
!=
nullptr
)
{
*
err
=
Error
(
"No such key %s"
,
name
.
c_str
());
}
return
""
;
}
auto
fieldName
=
buffer
[
buffer
.
size
()
-
1
];
auto
layerName
=
buffer
[
buffer
.
size
()
-
2
];
auto
layerIt
=
layerOutputs_
.
find
(
layerName
);
if
(
layerIt
==
layerOutputs_
.
end
())
{
if
(
err
!=
nullptr
)
{
*
err
=
Error
(
"No such layer %s"
,
layerName
.
c_str
());
}
return
""
;
}
auto
fieldIt
=
layerIt
->
second
.
find
(
fieldName
);
if
(
fieldIt
==
layerIt
->
second
.
end
())
{
if
(
err
!=
nullptr
)
{
*
err
=
Error
(
"No such value field %s"
,
fieldName
.
c_str
());
}
return
""
;
}
return
fieldIt
->
second
;
}
std
::
string
getType
(
const
std
::
string
&
name
,
Error
*
err
)
const
{
Error
localErr
;
if
(
err
==
nullptr
)
{
err
=
&
localErr
;
}
this
->
getValueStr
(
name
,
err
);
if
(
!
err
->
isOK
())
{
return
""
;
}
return
"value_printer"
;
}
};
REGISTER_EVALUATOR
(
value_printer
,
ValuePrinter
);
/**
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录