Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
PaddleDetection
提交
77a15b67
P
PaddleDetection
项目概览
PaddlePaddle
/
PaddleDetection
大约 1 年 前同步成功
通知
695
Star
11112
Fork
2696
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
184
列表
看板
标记
里程碑
合并请求
40
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
PaddleDetection
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
184
Issue
184
列表
看板
标记
里程碑
合并请求
40
合并请求
40
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
77a15b67
编写于
9月 04, 2017
作者:
C
Cao Ying
提交者:
GitHub
9月 04, 2017
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #3844 from lcy-seso/fix_ctc_evaluator
fix ctc edit distance evaluator can not print information in v2 API.
上级
35420274
a523bea8
变更
3
显示空白变更内容
内联
并排
Showing
3 changed file
with
67 addition
and
17 deletion
+67
-17
paddle/gserver/evaluators/CTCErrorEvaluator.cpp
paddle/gserver/evaluators/CTCErrorEvaluator.cpp
+52
-11
paddle/gserver/evaluators/ChunkEvaluator.cpp
paddle/gserver/evaluators/ChunkEvaluator.cpp
+7
-1
paddle/gserver/evaluators/Evaluator.h
paddle/gserver/evaluators/Evaluator.h
+8
-5
未找到文件。
paddle/gserver/evaluators/CTCErrorEvaluator.cpp
浏览文件 @
77a15b67
...
@@ -14,18 +14,20 @@ limitations under the License. */
...
@@ -14,18 +14,20 @@ limitations under the License. */
#include "Evaluator.h"
#include "Evaluator.h"
#include "paddle/gserver/gradientmachines/NeuralNetwork.h"
#include "paddle/gserver/gradientmachines/NeuralNetwork.h"
#include "paddle/utils/StringUtil.h"
namespace
paddle
{
namespace
paddle
{
/**
/**
* calculate sequence-to-sequence edit distance
* calculate sequence-to-sequence edit distance
*/
*/
class
CTCErrorEvaluator
:
public
NotGetable
Evaluator
{
class
CTCErrorEvaluator
:
public
Evaluator
{
private:
private:
MatrixPtr
outActivations_
;
MatrixPtr
outActivations_
;
int
numTimes_
,
numClasses_
,
numSequences_
,
blank_
;
int
numTimes_
,
numClasses_
,
numSequences_
,
blank_
;
real
deletions_
,
insertions_
,
substitutions_
;
real
deletions_
,
insertions_
,
substitutions_
;
int
seqClassficationError_
;
int
seqClassficationError_
;
mutable
std
::
unordered_map
<
std
::
string
,
real
>
evalResults_
;
std
::
vector
<
int
>
path2String
(
const
std
::
vector
<
int
>&
path
)
{
std
::
vector
<
int
>
path2String
(
const
std
::
vector
<
int
>&
path
)
{
std
::
vector
<
int
>
str
;
std
::
vector
<
int
>
str
;
...
@@ -183,6 +185,18 @@ private:
...
@@ -183,6 +185,18 @@ private:
return
stringAlignment
(
gtStr
,
recogStr
);
return
stringAlignment
(
gtStr
,
recogStr
);
}
}
void
storeLocalValues
()
const
{
evalResults_
[
"error"
]
=
numSequences_
?
totalScore_
/
numSequences_
:
0
;
evalResults_
[
"deletion_error"
]
=
numSequences_
?
deletions_
/
numSequences_
:
0
;
evalResults_
[
"insertion_error"
]
=
numSequences_
?
insertions_
/
numSequences_
:
0
;
evalResults_
[
"substitution_error"
]
=
numSequences_
?
substitutions_
/
numSequences_
:
0
;
evalResults_
[
"sequence_error"
]
=
(
real
)
seqClassficationError_
/
numSequences_
;
}
public:
public:
CTCErrorEvaluator
()
CTCErrorEvaluator
()
:
numTimes_
(
0
),
:
numTimes_
(
0
),
...
@@ -245,16 +259,12 @@ public:
...
@@ -245,16 +259,12 @@ public:
}
}
virtual
void
printStats
(
std
::
ostream
&
os
)
const
{
virtual
void
printStats
(
std
::
ostream
&
os
)
const
{
os
<<
config_
.
name
()
<<
"="
storeLocalValues
();
<<
(
numSequences_
?
totalScore_
/
numSequences_
:
0
);
os
<<
config_
.
name
()
<<
" error = "
<<
evalResults_
[
"error"
];
os
<<
" deletions error"
os
<<
" deletions error = "
<<
evalResults_
[
"deletion_error"
];
<<
"="
<<
(
numSequences_
?
deletions_
/
numSequences_
:
0
);
os
<<
" insertions error = "
<<
evalResults_
[
"insertion_error"
];
os
<<
" insertions error"
os
<<
" substitution error = "
<<
evalResults_
[
"substitution_error"
];
<<
"="
<<
(
numSequences_
?
insertions_
/
numSequences_
:
0
);
os
<<
" sequence error = "
<<
evalResults_
[
"sequence_error"
];
os
<<
" substitutions error"
<<
"="
<<
(
numSequences_
?
substitutions_
/
numSequences_
:
0
);
os
<<
" sequences error"
<<
"="
<<
(
real
)
seqClassficationError_
/
numSequences_
;
}
}
virtual
void
distributeEval
(
ParameterClient2
*
client
)
{
virtual
void
distributeEval
(
ParameterClient2
*
client
)
{
...
@@ -272,6 +282,37 @@ public:
...
@@ -272,6 +282,37 @@ public:
seqClassficationError_
=
(
int
)
buf
[
4
];
seqClassficationError_
=
(
int
)
buf
[
4
];
numSequences_
=
(
int
)
buf
[
5
];
numSequences_
=
(
int
)
buf
[
5
];
}
}
void
getNames
(
std
::
vector
<
std
::
string
>*
names
)
{
storeLocalValues
();
names
->
reserve
(
names
->
size
()
+
evalResults_
.
size
());
for
(
auto
it
=
evalResults_
.
begin
();
it
!=
evalResults_
.
end
();
++
it
)
{
names
->
push_back
(
config_
.
name
()
+
"."
+
it
->
first
);
}
}
real
getValue
(
const
std
::
string
&
name
,
Error
*
err
)
const
{
storeLocalValues
();
std
::
vector
<
std
::
string
>
buffers
;
paddle
::
str
::
split
(
name
,
'.'
,
&
buffers
);
auto
it
=
evalResults_
.
find
(
buffers
[
buffers
.
size
()
-
1
]);
if
(
it
==
evalResults_
.
end
())
{
*
err
=
Error
(
"Evaluator does not have the key %s"
,
name
.
c_str
());
return
0.0
f
;
}
return
it
->
second
;
}
std
::
string
getType
(
const
std
::
string
&
name
,
Error
*
err
)
const
{
this
->
getValue
(
name
,
err
);
if
(
!
err
->
isOK
())
{
return
""
;
}
return
"ctc_edit_distance"
;
}
};
};
REGISTER_EVALUATOR
(
ctc_edit_distance
,
CTCErrorEvaluator
);
REGISTER_EVALUATOR
(
ctc_edit_distance
,
CTCErrorEvaluator
);
...
...
paddle/gserver/evaluators/ChunkEvaluator.cpp
浏览文件 @
77a15b67
...
@@ -268,7 +268,13 @@ public:
...
@@ -268,7 +268,13 @@ public:
}
}
// get type of evaluator
// get type of evaluator
std
::
string
getTypeImpl
()
const
{
return
"chunk"
;
}
std
::
string
getType
(
const
std
::
string
&
name
,
Error
*
err
)
const
{
this
->
getValue
(
name
,
err
);
if
(
!
err
->
isOK
())
{
return
""
;
}
return
"chunk"
;
}
private:
private:
void
storeLocalValues
()
const
{
void
storeLocalValues
()
const
{
...
...
paddle/gserver/evaluators/Evaluator.h
浏览文件 @
77a15b67
...
@@ -211,6 +211,7 @@ public:
...
@@ -211,6 +211,7 @@ public:
*
err
=
Error
(
"Not implemented"
);
*
err
=
Error
(
"Not implemented"
);
return
.0
f
;
return
.0
f
;
}
}
std
::
string
getType
(
const
std
::
string
&
name
,
Error
*
err
)
const
{
std
::
string
getType
(
const
std
::
string
&
name
,
Error
*
err
)
const
{
*
err
=
Error
(
"Not implemented"
);
*
err
=
Error
(
"Not implemented"
);
return
""
;
return
""
;
...
@@ -331,6 +332,7 @@ private:
...
@@ -331,6 +332,7 @@ private:
protected:
protected:
std
::
string
getTypeImpl
()
const
;
std
::
string
getTypeImpl
()
const
;
};
};
/**
/**
* @brief precision, recall and f1 score Evaluator
* @brief precision, recall and f1 score Evaluator
* \f[
* \f[
...
@@ -358,6 +360,12 @@ public:
...
@@ -358,6 +360,12 @@ public:
virtual
void
distributeEval
(
ParameterClient2
*
client
);
virtual
void
distributeEval
(
ParameterClient2
*
client
);
void
getNames
(
std
::
vector
<
std
::
string
>*
names
);
real
getValue
(
const
std
::
string
&
name
,
Error
*
err
)
const
;
std
::
string
getType
(
const
std
::
string
&
name
,
Error
*
err
)
const
;
struct
StatsInfo
{
struct
StatsInfo
{
/// numbers of true positives
/// numbers of true positives
double
TP
;
double
TP
;
...
@@ -428,11 +436,6 @@ private:
...
@@ -428,11 +436,6 @@ private:
mutable
std
::
unordered_map
<
std
::
string
,
real
>
values_
;
mutable
std
::
unordered_map
<
std
::
string
,
real
>
values_
;
void
storeLocalValues
()
const
;
void
storeLocalValues
()
const
;
// Evaluator interface
public:
void
getNames
(
std
::
vector
<
std
::
string
>*
names
);
real
getValue
(
const
std
::
string
&
name
,
Error
*
err
)
const
;
std
::
string
getType
(
const
std
::
string
&
name
,
Error
*
err
)
const
;
};
};
/*
/*
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录