Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle
提交
e00f06af
P
Paddle
项目概览
PaddlePaddle
/
Paddle
1 年多 前同步成功
通知
2302
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看板
提交
e00f06af
编写于
2月 14, 2017
作者:
L
Liang Zhao
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Add top-k error
上级
5a1d9263
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
65 addition
and
5 deletion
+65
-5
paddle/gserver/evaluators/Evaluator.cpp
paddle/gserver/evaluators/Evaluator.cpp
+60
-1
paddle/math/Matrix.cpp
paddle/math/Matrix.cpp
+3
-1
paddle/parameter/Parameter.cpp
paddle/parameter/Parameter.cpp
+2
-2
python/paddle/trainer_config_helpers/evaluators.py
python/paddle/trainer_config_helpers/evaluators.py
+0
-1
未找到文件。
paddle/gserver/evaluators/Evaluator.cpp
浏览文件 @
e00f06af
...
@@ -76,9 +76,55 @@ public:
...
@@ -76,9 +76,55 @@ public:
1
,
1
,
/* trans= */
false
,
/* trans= */
false
,
useGpu
(
arguments
[
0
].
deviceId
));
useGpu
(
arguments
[
0
].
deviceId
));
const
MatrixPtr
errorMat2
=
Matrix
::
create
(
output
->
getHeight
(),
1
,
/* trans= */
false
,
false
);
// useGpu(arguments[0].deviceId));
errorMat
->
zeroMem
();
errorMat
->
zeroMem
();
if
(
label
!=
nullptr
)
{
if
(
label
!=
nullptr
)
{
errorMat
->
classificationError
(
*
output
,
*
label
);
errorMat
->
classificationError
(
output
,
label
);
// top-1 error
size_t
height
=
output
->
getHeight
();
size_t
width
=
5
;
// config_.num_results();
IVector
::
resizeOrCreate
(
maxIds_
,
height
*
width
,
useGpu
(
arguments
[
0
].
deviceId
));
Matrix
::
resizeOrCreate
(
maxValues_
,
height
,
width
,
false
,
useGpu
(
arguments
[
0
].
deviceId
));
output
->
rowMax
(
*
maxIds_
,
*
maxValues_
);
// top-5 values
int
*
ids
;
int
*
lbl
;
if
(
useGpu
(
arguments
[
0
].
deviceId
))
{
IVectorPtr
dest
=
IVector
::
create
(
maxIds_
->
getSize
(),
false
);
hl_memcpy_device2host
((
void
*
)
dest
->
getData
(),
(
void
*
)
maxIds_
->
getData
(),
sizeof
(
int
)
*
maxIds_
->
getSize
());
ids
=
dest
->
getData
();
IVectorPtr
dest2
=
IVector
::
create
(
label
->
getSize
(),
false
);
hl_memcpy_device2host
((
void
*
)
dest2
->
getData
(),
(
void
*
)
label
->
getData
(),
sizeof
(
int
)
*
label
->
getSize
());
lbl
=
dest2
->
getData
();
}
else
{
ids
=
maxIds_
->
getData
();
lbl
=
label
->
getData
();
}
// real* result = errorMat->getData();
real
*
result2
=
errorMat2
->
getData
();
for
(
size_t
i
=
0
;
i
<
height
;
++
i
)
{
// result[i] = (ids[i * width] != lbl[i]); // top-1 error
result2
[
i
]
=
(
ids
[
i
*
width
]
!=
lbl
[
i
]);
// initialize top-5 error
for
(
size_t
j
=
1
;
j
<
width
;
++
j
)
{
if
(
result2
[
i
]
==
0.0
)
{
break
;
}
result2
[
i
]
=
(
ids
[
i
*
width
+
j
]
!=
lbl
[
i
]);
// top-5 error
}
}
totalScore2_
=
errorMat2
->
getSum
();
}
else
if
(
dynamic_cast
<
CpuSparseMatrix
*>
(
multiBinaryLabel
.
get
())
||
}
else
if
(
dynamic_cast
<
CpuSparseMatrix
*>
(
multiBinaryLabel
.
get
())
||
dynamic_cast
<
GpuSparseMatrix
*>
(
multiBinaryLabel
.
get
()))
{
dynamic_cast
<
GpuSparseMatrix
*>
(
multiBinaryLabel
.
get
()))
{
errorMat
->
classificationErrorMulti
(
errorMat
->
classificationErrorMulti
(
...
@@ -94,6 +140,13 @@ public:
...
@@ -94,6 +140,13 @@ public:
return
errorMat
;
return
errorMat
;
}
}
void
printStats
(
std
::
ostream
&
os
)
const
{
os
<<
"top_1_error="
<<
(
numSamples_
?
totalScore_
/
numSamples_
:
0
)
<<
" top_5_error="
<<
(
numSamples_
?
totalScore2_
/
numSamples_
:
0
);
}
virtual
real
evalImp
(
std
::
vector
<
Argument
>&
arguments
)
{
virtual
real
evalImp
(
std
::
vector
<
Argument
>&
arguments
)
{
MatrixPtr
errorMat
=
calcError
(
arguments
);
MatrixPtr
errorMat
=
calcError
(
arguments
);
return
errorMat
->
getSum
();
return
errorMat
->
getSum
();
...
@@ -102,6 +155,12 @@ public:
...
@@ -102,6 +155,12 @@ public:
virtual
void
distributeEval
(
ParameterClient2
*
client
)
{
virtual
void
distributeEval
(
ParameterClient2
*
client
)
{
mergeResultsOfAllClients
(
client
);
mergeResultsOfAllClients
(
client
);
}
}
private:
IVectorPtr
maxIds_
;
MatrixPtr
maxValues_
;
double
totalScore2_
;
};
};
/**
/**
...
...
paddle/math/Matrix.cpp
浏览文件 @
e00f06af
...
@@ -732,6 +732,7 @@ void GpuMatrix::rowMax(IVector& maxIds, Matrix& maxVal) {
...
@@ -732,6 +732,7 @@ void GpuMatrix::rowMax(IVector& maxIds, Matrix& maxVal) {
size_t
beam
=
maxVal
.
getWidth
();
size_t
beam
=
maxVal
.
getWidth
();
CHECK_EQ
(
maxIds
.
getSize
(),
numSamples
*
beam
);
CHECK_EQ
(
maxIds
.
getSize
(),
numSamples
*
beam
);
CHECK_EQ
(
maxVal
.
getHeight
(),
numSamples
);
CHECK_EQ
(
maxVal
.
getHeight
(),
numSamples
);
CHECK_EQ
(
maxVal
.
getWidth
(),
beam
);
hl_matrix_top_k
(
maxVal
.
getData
(),
hl_matrix_top_k
(
maxVal
.
getData
(),
maxVal
.
getStride
(),
maxVal
.
getStride
(),
...
@@ -3039,7 +3040,7 @@ void CpuMatrix::rowMax(Matrix& max) {
...
@@ -3039,7 +3040,7 @@ void CpuMatrix::rowMax(Matrix& max) {
max
.
maxRows
(
*
this
);
max
.
maxRows
(
*
this
);
}
}
/*
get beam size of max ids and values
*/
/*
Get the top k elements of each row of this matrix
*/
void
CpuMatrix
::
rowMax
(
IVector
&
maxIds
,
Matrix
&
maxVal
)
{
void
CpuMatrix
::
rowMax
(
IVector
&
maxIds
,
Matrix
&
maxVal
)
{
CHECK
(
isContiguous
());
CHECK
(
isContiguous
());
CHECK
(
!
maxIds
.
useGpu
()
&&
!
maxVal
.
useGpu
())
<<
"Matrix type are not equal"
;
CHECK
(
!
maxIds
.
useGpu
()
&&
!
maxVal
.
useGpu
())
<<
"Matrix type are not equal"
;
...
@@ -3047,6 +3048,7 @@ void CpuMatrix::rowMax(IVector& maxIds, Matrix& maxVal) {
...
@@ -3047,6 +3048,7 @@ void CpuMatrix::rowMax(IVector& maxIds, Matrix& maxVal) {
size_t
beam
=
maxVal
.
getWidth
();
size_t
beam
=
maxVal
.
getWidth
();
CHECK_EQ
(
maxIds
.
getSize
(),
numSamples
*
beam
);
CHECK_EQ
(
maxIds
.
getSize
(),
numSamples
*
beam
);
CHECK_EQ
(
maxVal
.
getHeight
(),
numSamples
);
CHECK_EQ
(
maxVal
.
getHeight
(),
numSamples
);
CHECK_EQ
(
maxVal
.
getWidth
(),
beam
);
real
*
a
=
getData
();
real
*
a
=
getData
();
int
*
s
=
maxIds
.
getData
();
int
*
s
=
maxIds
.
getData
();
...
...
paddle/parameter/Parameter.cpp
浏览文件 @
e00f06af
...
@@ -375,10 +375,10 @@ bool Parameter::load(const std::string& filename) {
...
@@ -375,10 +375,10 @@ bool Parameter::load(const std::string& filename) {
std
::
ifstream
fs
(
filename
,
std
::
ios_base
::
binary
);
std
::
ifstream
fs
(
filename
,
std
::
ios_base
::
binary
);
if
(
!
fs
)
{
if
(
!
fs
)
{
LOG
(
INFO
)
<<
"missing parameters ["
<<
filename
<<
"] while loading model."
;
LOG
(
INFO
)
<<
"missing parameters ["
<<
filename
<<
"] while loading model."
;
if
(
isStatic
())
{
/*
if (isStatic()) {
LOG(FATAL) << getName() << " is static but missing, not allowed.";
LOG(FATAL) << getName() << " is static but missing, not allowed.";
return false;
return false;
}
}*/
if
(
kMissParameterFail
==
FLAGS_load_missing_parameter_strategy
)
{
if
(
kMissParameterFail
==
FLAGS_load_missing_parameter_strategy
)
{
LOG
(
FATAL
)
<<
getName
()
<<
" missing, not allowed."
;
LOG
(
FATAL
)
<<
getName
()
<<
" missing, not allowed."
;
return
false
;
return
false
;
...
...
python/paddle/trainer_config_helpers/evaluators.py
浏览文件 @
e00f06af
...
@@ -495,7 +495,6 @@ def gradient_printer_evaluator(
...
@@ -495,7 +495,6 @@ def gradient_printer_evaluator(
"""
"""
evaluator_base
(
name
=
name
,
type
=
"gradient_printer"
,
input
=
input
)
evaluator_base
(
name
=
name
,
type
=
"gradient_printer"
,
input
=
input
)
@
evaluator
(
EvaluatorAttribute
.
FOR_PRINT
)
@
evaluator
(
EvaluatorAttribute
.
FOR_PRINT
)
@
wrap_name_default
()
@
wrap_name_default
()
def
maxid_printer_evaluator
(
def
maxid_printer_evaluator
(
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录