Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
机器未来
Paddle
提交
b709af61
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看板
提交
b709af61
编写于
8月 29, 2017
作者:
L
Luo Tao
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
HuberTwoClassification only support one dimension
上级
e63ad0a6
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
12 addition
and
19 deletion
+12
-19
paddle/gserver/layers/CostLayer.cpp
paddle/gserver/layers/CostLayer.cpp
+12
-19
未找到文件。
paddle/gserver/layers/CostLayer.cpp
浏览文件 @
b709af61
...
@@ -672,10 +672,10 @@ void HuberTwoClassification::forwardImp(Matrix& output,
...
@@ -672,10 +672,10 @@ void HuberTwoClassification::forwardImp(Matrix& output,
Matrix
&
target
)
{
Matrix
&
target
)
{
HuberCost
::
forwardImp
(
output
,
label
,
target
);
HuberCost
::
forwardImp
(
output
,
label
,
target
);
size_t
numSamples
=
target
.
getHeight
();
size_t
numSamples
=
target
.
getHeight
();
size_t
dim
=
output
.
getWidth
();
CHECK
(
label
.
ids
);
CHECK
(
label
.
ids
);
CHECK_EQ
((
*
label
.
ids
).
getSize
(),
numSamples
);
CHECK_EQ
((
*
label
.
ids
).
getSize
(),
numSamples
);
CHECK_EQ
(
output
.
getHeight
(),
numSamples
);
CHECK_EQ
(
output
.
getHeight
(),
numSamples
);
CHECK_EQ
(
output
.
getWidth
(),
(
size_t
)
1
);
CHECK_EQ
(
target
.
getWidth
(),
(
size_t
)
1
);
CHECK_EQ
(
target
.
getWidth
(),
(
size_t
)
1
);
real
*
out
=
useGpu_
?
tmpCpuInput_
[
0
].
value
->
getData
()
:
output
.
getData
();
real
*
out
=
useGpu_
?
tmpCpuInput_
[
0
].
value
->
getData
()
:
output
.
getData
();
...
@@ -683,14 +683,11 @@ void HuberTwoClassification::forwardImp(Matrix& output,
...
@@ -683,14 +683,11 @@ void HuberTwoClassification::forwardImp(Matrix& output,
std
::
vector
<
real
>
cost
(
numSamples
,
0
);
std
::
vector
<
real
>
cost
(
numSamples
,
0
);
for
(
size_t
i
=
0
;
i
<
numSamples
;
++
i
)
{
for
(
size_t
i
=
0
;
i
<
numSamples
;
++
i
)
{
int
y
=
2
*
lbl
[
i
]
-
1
;
int
y
=
2
*
lbl
[
i
]
-
1
;
for
(
size_t
j
=
0
;
j
<
dim
;
++
j
)
{
real
a
=
out
[
i
]
*
y
;
int
index
=
i
*
dim
+
j
;
if
(
a
<
-
1
)
real
a
=
out
[
index
]
*
y
;
cost
[
i
]
=
-
4
*
a
;
if
(
a
<
-
1
)
else
if
(
a
<
1
)
cost
[
i
]
+=
-
4
*
a
;
cost
[
i
]
=
(
1
-
a
)
*
(
1
-
a
);
else
if
(
a
<
1
)
cost
[
i
]
+=
(
1
-
a
)
*
(
1
-
a
);
}
}
}
target
.
copyFrom
(
cost
.
data
(),
numSamples
);
target
.
copyFrom
(
cost
.
data
(),
numSamples
);
}
}
...
@@ -699,22 +696,18 @@ void HuberTwoClassification::backwardImp(Matrix& output,
...
@@ -699,22 +696,18 @@ void HuberTwoClassification::backwardImp(Matrix& output,
Argument
&
label
,
Argument
&
label
,
Matrix
&
outputG
)
{
Matrix
&
outputG
)
{
size_t
numSamples
=
output
.
getHeight
();
size_t
numSamples
=
output
.
getHeight
();
size_t
dim
=
output
.
getWidth
();
real
*
out
=
useGpu_
?
tmpCpuInput_
[
0
].
value
->
getData
()
:
output
.
getData
();
real
*
out
=
useGpu_
?
tmpCpuInput_
[
0
].
value
->
getData
()
:
output
.
getData
();
int
*
lbl
=
useGpu_
?
tmpCpuInput_
[
1
].
ids
->
getData
()
:
(
*
label
.
ids
).
getData
();
int
*
lbl
=
useGpu_
?
tmpCpuInput_
[
1
].
ids
->
getData
()
:
(
*
label
.
ids
).
getData
();
real
*
grad
=
useGpu_
?
tmpCpuInput_
[
0
].
grad
->
getData
()
:
outputG
.
getData
();
real
*
grad
=
useGpu_
?
tmpCpuInput_
[
0
].
grad
->
getData
()
:
outputG
.
getData
();
for
(
size_t
i
=
0
;
i
<
numSamples
;
++
i
)
{
for
(
size_t
i
=
0
;
i
<
numSamples
;
++
i
)
{
int
y
=
2
*
lbl
[
i
]
-
1
;
int
y
=
2
*
lbl
[
i
]
-
1
;
for
(
size_t
j
=
0
;
j
<
dim
;
++
j
)
{
real
a
=
out
[
i
]
*
y
;
int
index
=
i
*
dim
+
j
;
if
(
a
<
-
1
)
real
a
=
out
[
index
]
*
y
;
grad
[
i
]
+=
-
4
*
y
;
if
(
a
<
-
1
)
else
if
(
a
<
1
)
grad
[
index
]
+=
-
4
*
y
;
grad
[
i
]
+=
-
2
*
(
1
-
a
)
*
y
;
else
if
(
a
<
1
)
grad
[
index
]
+=
-
2
*
(
1
-
a
)
*
y
;
}
}
}
if
(
useGpu_
)
outputG
.
copyFrom
(
grad
,
numSamples
*
dim
);
if
(
useGpu_
)
outputG
.
copyFrom
(
grad
,
numSamples
);
}
}
/**
/**
* This cost layer compute the sum of its input as loss.
* This cost layer compute the sum of its input as loss.
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录