Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
booniebears
Paddle
提交
fe2ab2ee
P
Paddle
项目概览
booniebears
/
Paddle
与 Fork 源项目一致
Fork自
PaddlePaddle / Paddle
通知
1
Star
0
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看板
体验新版 GitCode,发现更多精彩内容 >>
提交
fe2ab2ee
编写于
9月 14, 2017
作者:
L
Liu Yiqun
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Set the default value of xNumColDims and rename the output to "Out" in FCOp.
上级
0b21b854
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
23 addition
and
14 deletion
+23
-14
paddle/operators/fc_op.cc
paddle/operators/fc_op.cc
+19
-9
python/paddle/v2/framework/tests/test_fc_op.py
python/paddle/v2/framework/tests/test_fc_op.py
+4
-5
未找到文件。
paddle/operators/fc_op.cc
浏览文件 @
fe2ab2ee
...
...
@@ -41,10 +41,19 @@ class FCOp : public NetOp {
"The size of inputs X(%d) should be no less than 1."
,
n
);
auto
x_num_col_dims
=
Attr
<
std
::
vector
<
int
>>
(
"xNumColDims"
);
PADDLE_ENFORCE_EQ
(
x_num_col_dims
.
size
(),
n
,
"The size of attribute xNumColDims(%d) should be the "
"same as that of inputs X(%d)."
,
x_num_col_dims
.
size
(),
n
);
// Set all values or set no values (use the default value)
if
(
!
x_num_col_dims
.
empty
())
{
PADDLE_ENFORCE_EQ
(
x_num_col_dims
.
size
(),
n
,
"The size of attribute xNumColDims(%d) should be the "
"same as that of inputs X(%d)."
,
x_num_col_dims
.
size
(),
n
);
}
else
{
x_num_col_dims
.
resize
(
n
);
for
(
size_t
i
=
0
;
i
<
n
;
i
++
)
{
x_num_col_dims
[
i
]
=
1
;
}
}
// mul_out[i] = X[i] * W[i]
for
(
size_t
i
=
0
;
i
<
n
;
i
++
)
{
...
...
@@ -81,7 +90,7 @@ class FCOp : public NetOp {
auto
activation
=
Attr
<
std
::
string
>
(
"activation"
);
AppendOp
(
framework
::
OpRegistry
::
CreateOp
(
activation
,
{{
"X"
,
{
Output
(
add_out
)}}},
{{
"Y"
,
{
Output
(
"
Y
"
)}}},
{}));
activation
,
{{
"X"
,
{
Output
(
add_out
)}}},
{{
"Y"
,
{
Output
(
"
Out
"
)}}},
{}));
CompleteAddOp
(
false
);
}
};
...
...
@@ -105,7 +114,7 @@ class FCOpMaker : public framework::OpProtoAndCheckerMaker {
"(Tensor) the bias of FC operator, a 1-D vector of size "
"number_of_neurons."
);
AddOutput
(
"
Y
"
,
AddOutput
(
"
Out
"
,
"(Tensor) the activated output matrix of FC operator, a 2-D "
"matrix of size (minibatch, number_of_neurons)."
);
AddOutput
(
"MulOut"
,
...
...
@@ -137,7 +146,8 @@ class FCOpMaker : public framework::OpProtoAndCheckerMaker {
"`X_i.dims[0] x ... x X_i.dims[xNumColDims_i - 1]`. "
"The matrix's second dimension (the length of row) will be the product "
"of `X_i`'s first `rank - xNumColDims_i` dimensions, that is "
"`X_i.dims[xNumColDims_i] x ... x X_i.dims[rank - 1]`)"
);
"`X_i.dims[xNumColDims_i] x ... x X_i.dims[rank - 1]`)"
)
.
SetDefault
(
std
::
vector
<
int
>
{});
AddComment
(
R"DOC(
Fully Connected Operator, known as Fully Connected Layer or Inner Product Layer
...
...
@@ -148,13 +158,13 @@ learned weights with a matrix multiplication followed by a bias offset
(optionally).
Equation:
Y
= Act(sum_n{X_i * W_i} + B)
Out
= Act(sum_n{X_i * W_i} + B)
where X_i is Tensor that will be reshaped to a 2-D matrix of size (M x K),
usually M is the minibatch size and K is the number of input features.
W_i is a 2-D matrix of size (K x N), where N means the number of neurons
in the fully connected layer. B is a 1-D vector of size N.
Thus, the output
Y
is a 2-D matrix of size (M x N).
Thus, the output
Out
is a 2-D matrix of size (M x N).
Activation type can be set to `identity` (default), `sigmoid` or `softmax`.
)DOC"
);
}
...
...
python/paddle/v2/framework/tests/test_fc_op.py
浏览文件 @
fe2ab2ee
...
...
@@ -20,15 +20,14 @@ class TestFCOp1(OpTest):
"MulOut"
:
[(
"MulOut0"
,
mul_out0
)],
"SumOut"
:
sum_out
,
"AddOut"
:
add_out
,
"
Y
"
:
identity_out
"
Out
"
:
identity_out
}
self
.
attrs
=
{
"xNumColDims"
:
[
1
]}
def
test_check_output
(
self
):
self
.
check_output
()
def
test_check_grad
(
self
):
self
.
check_grad
([
"X0"
,
"W0"
,
"B"
],
"
Y
"
,
max_relative_error
=
0.01
)
self
.
check_grad
([
"X0"
,
"W0"
,
"B"
],
"
Out
"
,
max_relative_error
=
0.01
)
class
TestFCOp2
(
OpTest
):
...
...
@@ -56,7 +55,7 @@ class TestFCOp2(OpTest):
"MulOut"
:
[(
"MulOut0"
,
mul_out0
),
(
"MulOut1"
,
mul_out1
)],
"SumOut"
:
sum_out
,
"AddOut"
:
add_out
,
"
Y
"
:
sigmoid_out
"
Out
"
:
sigmoid_out
}
def
test_check_output
(
self
):
...
...
@@ -64,7 +63,7 @@ class TestFCOp2(OpTest):
def
test_check_grad
(
self
):
self
.
check_grad
(
[
"X0"
,
"X1"
,
"W0"
,
"W1"
,
"B"
],
"
Y
"
,
max_relative_error
=
0.01
)
[
"X0"
,
"X1"
,
"W0"
,
"W1"
,
"B"
],
"
Out
"
,
max_relative_error
=
0.01
)
if
__name__
==
'__main__'
:
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录