Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
PaddleDetection
提交
4d2adab7
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看板
提交
4d2adab7
编写于
8月 15, 2017
作者:
Z
zchen0211
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
gather op added with python unittest
上级
323d4233
变更
5
显示空白变更内容
内联
并排
Showing
5 changed file
with
29 addition
and
20 deletion
+29
-20
paddle/framework/CMakeLists.txt
paddle/framework/CMakeLists.txt
+1
-0
paddle/framework/pybind.cc
paddle/framework/pybind.cc
+1
-0
paddle/operators/CMakeLists.txt
paddle/operators/CMakeLists.txt
+2
-1
paddle/operators/gather_op.cc
paddle/operators/gather_op.cc
+24
-19
python/paddle/v2/framework/tests/CMakeLists.txt
python/paddle/v2/framework/tests/CMakeLists.txt
+1
-0
未找到文件。
paddle/framework/CMakeLists.txt
浏览文件 @
4d2adab7
...
...
@@ -47,6 +47,7 @@ cc_library(paddle_pybind SHARED
SRCS pybind.cc
DEPS pybind python backward
sgd_op
gather_op
add_op
mul_op
rowwise_add_op
...
...
paddle/framework/pybind.cc
浏览文件 @
4d2adab7
...
...
@@ -42,6 +42,7 @@ USE_OP(fill_zeros_like);
USE_OP_ITSELF
(
recurrent_op
);
USE_OP
(
gaussian_random
);
USE_OP
(
uniform_random
);
USE_CPU_ONLY_OP
(
gather
);
namespace
paddle
{
namespace
framework
{
...
...
paddle/operators/CMakeLists.txt
浏览文件 @
4d2adab7
...
...
@@ -43,7 +43,8 @@ endfunction()
add_subdirectory
(
math
)
cc_test
(
gather_test SRCS gather_test.cc DEPS tensor
)
cc_library
(
gather_op SRCS gather_op.cc DEPS op_registry
)
op_library
(
gather_op SRCS gather_op.cc gather_op.cu
)
# DEPS op_registry)
# cc_test(gather_op_test SRCS gather_op_test.cc DEPS gather_op)
cc_test
(
scatter_test SRCS scatter_test.cc DEPS tensor
)
...
...
paddle/operators/gather_op.cc
浏览文件 @
4d2adab7
...
...
@@ -19,17 +19,33 @@ namespace paddle {
namespace
operators
{
class
GatherOp
:
public
framework
::
OperatorWithKernel
{
public:
using
framework
::
OperatorWithKernel
::
OperatorWithKernel
;
protected:
void
InferShape
(
const
framework
::
InferShapeContext
&
ctx
)
const
override
{
PADDLE_ENFORCE
(
ctx
.
InputSize
()
==
2
,
""
);
PADDLE_ENFORCE
(
ctx
.
OutputSize
()
==
1
,
""
);
PADDLE_ENFORCE_NOT_NULL
(
ctx
.
InputVar
(
0
),
"Inputs of GatherOp must all be set"
);
int
batch_size
=
ctx
.
Input
<
Tensor
>
(
1
)
->
dims
()[
0
];
//
PADDLE_ENFORCE(ctx.InputSize() == 2, "");
//
PADDLE_ENFORCE(ctx.OutputSize() == 1, "");
//
PADDLE_ENFORCE_NOT_NULL(ctx.InputVar(0),
//
"Inputs of GatherOp must all be set");
int
batch_size
=
ctx
.
Input
<
Tensor
>
(
"Index"
)
->
dims
()[
0
];
PADDLE_ENFORCE
(
batch_size
>
0
);
paddle
::
framework
::
DDim
output_dims
(
ctx
.
Input
<
Tensor
>
(
0
)
->
dims
());
output_dims
[
0
]
=
batch_size
;
ctx
.
Output
<
Tensor
>
(
0
)
->
Resize
(
output_dims
);
ctx
.
Output
<
Tensor
>
(
"Y"
)
->
Resize
(
output_dims
);
}
};
class
GatherGradOp
:
public
framework
::
OperatorWithKernel
{
public:
using
framework
::
OperatorWithKernel
::
OperatorWithKernel
;
protected:
void
InferShape
(
const
framework
::
InferShapeContext
&
ctx
)
const
override
{
auto
X_grad
=
ctx
.
Output
<
Tensor
>
(
framework
::
GradVarName
(
"X"
));
auto
X
=
ctx
.
Input
<
Tensor
>
(
"X"
);
X_grad
->
Resize
(
X
->
dims
());
}
};
...
...
@@ -47,25 +63,14 @@ Y = X[Index]
)DOC"
);
}
};
class
GatherGradOp
:
public
framework
::
OperatorWithKernel
{
protected:
void
InferShape
(
const
framework
::
InferShapeContext
&
ctx
)
const
override
{
auto
X_grad
=
ctx
.
Output
<
Tensor
>
(
framework
::
GradVarName
(
"X"
));
auto
X
=
ctx
.
Input
<
Tensor
>
(
"X"
);
X_grad
->
Resize
(
X
->
dims
());
}
};
}
// namespace operators
}
// namespace paddle
namespace
ops
=
paddle
::
operators
;
REGISTER_OP
(
gather
,
ops
::
GatherOp
,
ops
::
GatherOpMaker
);
REGISTER_OP
(
gather
,
ops
::
GatherOp
,
ops
::
GatherOpMaker
,
gather_grad
,
ops
::
GatherGradOp
);
REGISTER_OP_CPU_KERNEL
(
gather
,
ops
::
GatherOpKernel
<
paddle
::
platform
::
CPUPlace
,
float
>
);
REGISTER_GRADIENT_OP
(
gather
,
gather_grad
,
ops
::
GatherGradOp
);
REGISTER_OP_CPU_KERNEL
(
gather_grad
,
ops
::
GatherGradientOpKernel
<
paddle
::
platform
::
CPUPlace
,
float
>
);
python/paddle/v2/framework/tests/CMakeLists.txt
浏览文件 @
4d2adab7
...
...
@@ -13,6 +13,7 @@ py_test(test_add_two_op SRCS test_add_two_op.py)
py_test
(
test_sigmoid_op SRCS test_sigmoid_op.py
)
py_test
(
test_softmax_op SRCS test_softmax_op.py
)
py_test
(
test_cross_entropy_op SRCS test_cross_entropy_op.py
)
py_test
(
test_gather_op SRCS test_gather_op.py
)
py_test
(
test_fill_zeros_like_op SRCS test_fill_zeros_like_op.py
)
py_test
(
gradient_checker SRCS gradient_checker.py
)
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录