Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
机器未来
Paddle
提交
d1e6d552
P
Paddle
项目概览
机器未来
/
Paddle
与 Fork 源项目一致
Fork自
PaddlePaddle / Paddle
通知
1
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
Paddle
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1
Issue
1
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
d1e6d552
编写于
9月 12, 2017
作者:
T
typhoonzero
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
update
上级
4d988ed2
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
19 addition
and
18 deletion
+19
-18
paddle/operators/auc_op.cc
paddle/operators/auc_op.cc
+2
-2
paddle/operators/auc_op.h
paddle/operators/auc_op.h
+16
-16
paddle/pybind/pybind.cc
paddle/pybind/pybind.cc
+1
-0
未找到文件。
paddle/operators/auc_op.cc
浏览文件 @
d1e6d552
...
...
@@ -17,7 +17,7 @@ limitations under the License. */
namespace
paddle
{
namespace
operators
{
class
A
ccuracy
Op
:
public
framework
::
OperatorWithKernel
{
class
A
uc
Op
:
public
framework
::
OperatorWithKernel
{
public:
using
framework
::
OperatorWithKernel
::
OperatorWithKernel
;
...
...
@@ -76,5 +76,5 @@ class AucOpMaker : public framework::OpProtoAndCheckerMaker {
}
// namespace paddle
namespace
ops
=
paddle
::
operators
;
REGISTER_OP_WITHOUT_GRADIENT
(
auc
,
ops
::
A
ccuracyOp
,
ops
::
Accuracy
OpMaker
);
REGISTER_OP_WITHOUT_GRADIENT
(
auc
,
ops
::
A
ucOp
,
ops
::
Auc
OpMaker
);
REGISTER_OP_CPU_KERNEL
(
auc
,
ops
::
AucKernel
<
paddle
::
platform
::
CPUPlace
,
float
>
);
paddle/operators/auc_op.h
浏览文件 @
d1e6d552
...
...
@@ -23,7 +23,7 @@ namespace operators {
using
Tensor
=
framework
::
Tensor
;
template
<
typename
Place
,
typename
T
>
class
A
ccuracy
Kernel
:
public
framework
::
OpKernel
{
class
A
uc
Kernel
:
public
framework
::
OpKernel
{
public:
void
Compute
(
const
framework
::
ExecutionContext
&
ctx
)
const
override
{
auto
*
inference
=
ctx
.
Input
<
Tensor
>
(
"Inference"
);
...
...
@@ -45,7 +45,7 @@ class AccuracyKernel : public framework::OpKernel {
thresholds_list
[
num_thresholds
-
1
]
=
1.0
f
+
kEpsilon
;
const
int
*
inference_data
=
inference
->
data
<
int
>
();
const
T
*
inference_prob_data
=
inference
->
data
<
T
>
();
const
T
*
inference_prob_data
=
inference
_prob
->
data
<
T
>
();
const
T
*
label_data
=
label
->
data
<
T
>
();
size_t
num_samples
=
inference
->
dims
()[
0
];
...
...
@@ -54,17 +54,17 @@ class AccuracyKernel : public framework::OpKernel {
// create local tensor for storing the curve: TP, FN, TN, FP
// TODO(typhoonzero): put these tensors in Scope
// TODO(typhoonzero): use op to caculate these values.
Tensor
true_positive
,
false_posit
e
ve
,
true_negative
,
false_negative
;
Tensor
true_positive
,
false_posit
i
ve
,
true_negative
,
false_negative
;
true_positive
.
Resize
({
num_thresholds
});
false_negative
.
Resize
({
num_thresholds
});
true_negative
.
Resize
({
num_thresholds
});
false_positive
.
Resize
({
num_thresholds
});
int
*
tp_data
=
true_positive
.
mutable_data
<
int
>
();
int
*
fn_data
=
false_negative
.
mutable_data
<
int
>
();
int
*
tn_data
=
true_negative
.
mutable_data
<
int
>
();
int
*
fp_data
=
false_positive
.
mutable_data
<
int
>
();
int
*
tp_data
=
true_positive
.
mutable_data
<
int
>
(
ctx
.
GetPlace
()
);
int
*
fn_data
=
false_negative
.
mutable_data
<
int
>
(
ctx
.
GetPlace
()
);
int
*
tn_data
=
true_negative
.
mutable_data
<
int
>
(
ctx
.
GetPlace
()
);
int
*
fp_data
=
false_positive
.
mutable_data
<
int
>
(
ctx
.
GetPlace
()
);
for
(
auto
thresh
=
thresholds_list
.
begin
();
thresh
!=
thresholds_list
.
end
();
thresh
++
)
{
...
...
@@ -101,15 +101,15 @@ class AccuracyKernel : public framework::OpKernel {
tp_rate
.
Resize
({
num_thresholds
});
fp_rate
.
Resize
({
num_thresholds
});
rec_rate
.
Resize
({
num_thresholds
});
float
*
tp_rate_data
=
tp_rate
.
mutable_data
<
float
>
();
float
*
fp_rate_data
=
fp_rate
.
mutable_data
<
float
>
();
float
*
rec_rate_data
=
rec_rate
.
mutable_data
<
float
>
();
float
*
tp_rate_data
=
tp_rate
.
mutable_data
<
float
>
(
ctx
.
GetPlace
()
);
float
*
fp_rate_data
=
fp_rate
.
mutable_data
<
float
>
(
ctx
.
GetPlace
()
);
float
*
rec_rate_data
=
rec_rate
.
mutable_data
<
float
>
(
ctx
.
GetPlace
()
);
for
(
int
i
=
0
;
i
<
num_thresholds
;
i
++
)
{
tp_rate_data
[
i
]
=
((
float
)
tp_data
[
i
+
epsilon
)
/
(
tp_data
[
i
]
+
fn_data
[
i
]
+
epsilon
);
fp_rate_data
[
i
]
=
(
float
)
fp_data
[
i
]
/
(
fp_data
[
i
]
+
tn_data
[
i
]
+
epsilon
);
rec_rate_data
[
i
]
=
((
float
)
tp_data
[
i
]
+
epsilon
)
/
(
tp_data
[
i
]
+
fp_data
[
i
]
+
epsilon
);
tp_rate_data
[
i
]
=
((
float
)
tp_data
[
i
]
+
epsilon
)
/
(
tp_data
[
i
]
+
fn_data
[
i
]
+
epsilon
);
fp_rate_data
[
i
]
=
(
float
)
fp_data
[
i
]
/
(
fp_data
[
i
]
+
tn_data
[
i
]
+
epsilon
);
rec_rate_data
[
i
]
=
((
float
)
tp_data
[
i
]
+
epsilon
)
/
(
tp_data
[
i
]
+
fp_data
[
i
]
+
epsilon
);
}
if
(
curve
==
"ROC"
)
{
...
...
@@ -118,7 +118,7 @@ class AccuracyKernel : public framework::OpKernel {
auto
y
=
(
tp_rate_data
[
i
]
+
tp_rate_data
[
i
-
1
])
/
2.0
f
;
*
auc_data
=
*
auc_data
+
dx
*
y
;
}
}
else
if
(
curve
=
"PR"
)
{
}
else
if
(
curve
=
=
"PR"
)
{
for
(
int
i
=
1
;
i
<
num_thresholds
;
i
++
)
{
auto
dx
=
tp_rate_data
[
i
]
-
tp_rate_data
[
i
-
1
];
auto
y
=
(
rec_rate_data
[
i
]
+
rec_rate_data
[
i
-
1
])
/
2.0
f
;
...
...
paddle/pybind/pybind.cc
浏览文件 @
d1e6d552
...
...
@@ -50,6 +50,7 @@ USE_OP(cos_sim);
USE_CPU_ONLY_OP
(
gather
);
USE_CPU_ONLY_OP
(
scatter
);
USE_OP
(
top_k
);
USE_CPU_ONLY_OP
(
auc
);
USE_OP
(
squared_l2_distance
);
namespace
paddle
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录