Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
BaiXuePrincess
Paddle
提交
07205c7b
P
Paddle
项目概览
BaiXuePrincess
/
Paddle
与 Fork 源项目一致
Fork自
PaddlePaddle / Paddle
通知
1
Star
1
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看板
提交
07205c7b
编写于
10月 19, 2017
作者:
Q
qijun
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix elementwise add bug
上级
090372f2
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
32 addition
and
18 deletion
+32
-18
paddle/operators/elementwise_op.h
paddle/operators/elementwise_op.h
+0
-2
paddle/operators/elementwise_op_function.h
paddle/operators/elementwise_op_function.h
+1
-7
python/paddle/v2/framework/tests/test_elementwise_add_op.py
python/paddle/v2/framework/tests/test_elementwise_add_op.py
+28
-0
python/paddle/v2/framework/tests/test_fit_a_line.py
python/paddle/v2/framework/tests/test_fit_a_line.py
+3
-9
未找到文件。
paddle/operators/elementwise_op.h
浏览文件 @
07205c7b
...
@@ -34,8 +34,6 @@ class ElementwiseOp : public framework::OperatorWithKernel {
...
@@ -34,8 +34,6 @@ class ElementwiseOp : public framework::OperatorWithKernel {
auto
x_dim
=
ctx
->
GetInputDim
(
"X"
);
auto
x_dim
=
ctx
->
GetInputDim
(
"X"
);
auto
y_dim
=
ctx
->
GetInputDim
(
"Y"
);
auto
y_dim
=
ctx
->
GetInputDim
(
"Y"
);
LOG
(
INFO
)
<<
x_dim
;
LOG
(
INFO
)
<<
y_dim
;
PADDLE_ENFORCE_GE
(
x_dim
.
size
(),
y_dim
.
size
(),
PADDLE_ENFORCE_GE
(
x_dim
.
size
(),
y_dim
.
size
(),
"Rank of first input must >= rank of second input."
)
"Rank of first input must >= rank of second input."
)
ctx
->
SetOutputDim
(
"Out"
,
x_dim
);
ctx
->
SetOutputDim
(
"Out"
,
x_dim
);
...
...
paddle/operators/elementwise_op_function.h
浏览文件 @
07205c7b
...
@@ -108,7 +108,7 @@ void ElementwiseCompute(const framework::ExecutionContext& ctx) {
...
@@ -108,7 +108,7 @@ void ElementwiseCompute(const framework::ExecutionContext& ctx) {
PADDLE_ENFORCE_GE
(
x_dims
.
size
(),
y_dims
.
size
(),
PADDLE_ENFORCE_GE
(
x_dims
.
size
(),
y_dims
.
size
(),
"Rank of first input must >= rank of second input."
)
"Rank of first input must >= rank of second input."
)
if
(
x_dims
==
y_dims
||
product
(
y_dims
)
==
1
)
{
if
(
x_dims
==
y_dims
)
{
functor
f
;
functor
f
;
f
.
template
Run
<
Place
,
T
>(
x
,
y
,
z
,
ctx
);
f
.
template
Run
<
Place
,
T
>(
x
,
y
,
z
,
ctx
);
return
;
return
;
...
@@ -174,12 +174,6 @@ void ElementwiseGradCompute(const framework::ExecutionContext& ctx) {
...
@@ -174,12 +174,6 @@ void ElementwiseGradCompute(const framework::ExecutionContext& ctx) {
return
;
return
;
}
}
if
(
product
(
y_dims
)
==
1
)
{
functor1
f
;
f
(
place
,
x
,
y
,
out
,
dx
,
dy
,
dout
);
return
;
}
int
axis
=
ctx
.
Attr
<
int
>
(
"axis"
);
int
axis
=
ctx
.
Attr
<
int
>
(
"axis"
);
axis
=
(
axis
==
-
1
?
x_dims
.
size
()
-
y_dims
.
size
()
:
axis
);
axis
=
(
axis
==
-
1
?
x_dims
.
size
()
-
y_dims
.
size
()
:
axis
);
...
...
python/paddle/v2/framework/tests/test_elementwise_add_op.py
浏览文件 @
07205c7b
...
@@ -92,5 +92,33 @@ class TestElementwiseAddOp_broadcast_3(TestElementwiseOp):
...
@@ -92,5 +92,33 @@ class TestElementwiseAddOp_broadcast_3(TestElementwiseOp):
}
}
class
TestElementwiseAddOp_rowwise_add_0
(
TestElementwiseOp
):
def
setUp
(
self
):
self
.
op_type
=
"elementwise_add"
self
.
inputs
=
{
'X'
:
np
.
random
.
rand
(
2
,
3
,
4
).
astype
(
np
.
float32
),
'Y'
:
np
.
random
.
rand
(
3
,
4
).
astype
(
np
.
float32
)
}
self
.
attrs
=
{
'axis'
:
1
}
self
.
outputs
=
{
'Out'
:
self
.
inputs
[
'X'
]
+
self
.
inputs
[
'Y'
].
reshape
(
1
,
3
,
4
)
}
class
TestElementwiseAddOp_rowwise_add_1
(
TestElementwiseOp
):
def
setUp
(
self
):
self
.
op_type
=
"elementwise_add"
self
.
inputs
=
{
'X'
:
np
.
random
.
rand
(
2
,
1
).
astype
(
np
.
float32
),
'Y'
:
np
.
random
.
rand
(
1
).
astype
(
np
.
float32
)
}
self
.
attrs
=
{
'axis'
:
1
}
self
.
outputs
=
{
'Out'
:
self
.
inputs
[
'X'
]
+
self
.
inputs
[
'Y'
].
reshape
(
1
,
1
)
}
if
__name__
==
'__main__'
:
if
__name__
==
'__main__'
:
unittest
.
main
()
unittest
.
main
()
python/paddle/v2/framework/tests/test_fit_a_line.py
浏览文件 @
07205c7b
...
@@ -17,12 +17,12 @@ y = layers.data(name='y', shape=[1], data_type='float32', program=program)
...
@@ -17,12 +17,12 @@ y = layers.data(name='y', shape=[1], data_type='float32', program=program)
cost
=
layers
.
square_error_cost
(
input
=
y_predict
,
label
=
y
,
program
=
program
)
cost
=
layers
.
square_error_cost
(
input
=
y_predict
,
label
=
y
,
program
=
program
)
avg_cost
=
layers
.
mean
(
x
=
cost
,
program
=
program
)
avg_cost
=
layers
.
mean
(
x
=
cost
,
program
=
program
)
sgd_optimizer
=
optimizer
.
SGDOptimizer
(
learning_rate
=
0.0
1
)
sgd_optimizer
=
optimizer
.
SGDOptimizer
(
learning_rate
=
0.0
05
)
opts
=
sgd_optimizer
.
minimize
(
avg_cost
)
opts
=
sgd_optimizer
.
minimize
(
avg_cost
)
# print str(program)
# print str(program)
BATCH_SIZE
=
2
BATCH_SIZE
=
16
train_reader
=
paddle
.
batch
(
train_reader
=
paddle
.
batch
(
paddle
.
reader
.
shuffle
(
paddle
.
reader
.
shuffle
(
...
@@ -32,23 +32,17 @@ train_reader = paddle.batch(
...
@@ -32,23 +32,17 @@ train_reader = paddle.batch(
place
=
core
.
CPUPlace
()
place
=
core
.
CPUPlace
()
exe
=
Executor
(
place
)
exe
=
Executor
(
place
)
PASS_NUM
=
1
PASS_NUM
=
5
for
pass_id
in
range
(
PASS_NUM
):
for
pass_id
in
range
(
PASS_NUM
):
for
data
in
train_reader
():
for
data
in
train_reader
():
x_data
=
np
.
array
(
map
(
lambda
x
:
x
[
0
],
data
)).
astype
(
"float32"
)
x_data
=
np
.
array
(
map
(
lambda
x
:
x
[
0
],
data
)).
astype
(
"float32"
)
y_data
=
np
.
array
(
map
(
lambda
x
:
x
[
1
],
data
)).
astype
(
"float32"
)
y_data
=
np
.
array
(
map
(
lambda
x
:
x
[
1
],
data
)).
astype
(
"float32"
)
# y_data = np.expand_dims(y_data, axis=1)
# print x_data
# print type(x_data)
# print y_data
tensor_x
=
core
.
LoDTensor
()
tensor_x
=
core
.
LoDTensor
()
tensor_x
.
set
(
x_data
,
place
)
tensor_x
.
set
(
x_data
,
place
)
# print tensor_x.get_dims()
tensor_y
=
core
.
LoDTensor
()
tensor_y
=
core
.
LoDTensor
()
tensor_y
.
set
(
y_data
,
place
)
tensor_y
.
set
(
y_data
,
place
)
# print tensor_y.get_dims()
outs
=
exe
.
run
(
program
,
outs
=
exe
.
run
(
program
,
feed
=
{
'x'
:
tensor_x
,
feed
=
{
'x'
:
tensor_x
,
'y'
:
tensor_y
},
'y'
:
tensor_y
},
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录