Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
机器未来
Paddle
提交
48556ba3
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看板
提交
48556ba3
编写于
10月 11, 2017
作者:
G
gongweibao
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
add block_expand_op
上级
23407e7a
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
169 addition
and
0 deletion
+169
-0
paddle/operators/block_expand_op.cc
paddle/operators/block_expand_op.cc
+80
-0
paddle/operators/block_expand_op.cu
paddle/operators/block_expand_op.cu
+0
-0
paddle/operators/block_expand_op.h
paddle/operators/block_expand_op.h
+89
-0
未找到文件。
paddle/operators/block_expand_op.cc
0 → 100644
浏览文件 @
48556ba3
/* Copyright (c) 2016 PaddlePaddle Authors. All Rights Reserve.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License. */
#include "paddle/operators/block_expand_op.h"
namespace
paddle
{
namespace
operators
{
class
BlockExpandOp
:
public
framework
::
OperatorWithKernel
{
public:
using
framework
::
OperatorWithKernel
::
OperatorWithKernel
;
protected:
void
InferShape
(
framework
::
InferShapeContext
*
ctx
)
const
override
{
PADDLE_ENFORCE
(
ctx
->
HasInput
(
"block"
),
"Input(block) of BlockExpandOp should not be null."
);
PADDLE_ENFORCE
(
ctx
->
HasInput
(
"padding"
),
"Input(padding) of BlockExpandOp should not be null."
);
PADDLE_ENFORCE
(
ctx
->
HasInput
(
"stride"
),
"Input(stride) of BlockExpandOp should not be null."
);
// ctx->SetOutputDim("Out", {1});
}
};
class
BlockExpandOpMaker
:
public
framework
::
OpProtoAndCheckerMaker
{
public:
BlockExpandOpMaker
(
framework
::
OpProto
*
proto
,
framework
::
OpAttrChecker
*
op_checker
)
:
OpProtoAndCheckerMaker
(
proto
,
op_checker
)
{
AddInput
(
"block"
,
"The input of block_expand op"
);
AddOutput
(
"stride"
,
"The output of block_expand op"
);
AddComment
(
R"DOC(
Expand feature map to minibatch matrix.
- matrix width is: blockH_ * blockW_ * channels_
- matirx height is: outputH_ * outputW_
outputH\_ = 1 + (2paddingH\_ + imgSizeH\_ - blockH\_ + strideH\_ - 1) /
strideH\_ \\
outputW\_ = 1 + (2paddingW\_ + imgSizeW\_ - blockW\_ + strideW\_ - 1) /
strideW\_
The expand method is the same with ExpandConvLayer, but saved the transposed
value. After expanding, output_.sequenceStartPositions will store timeline.
The number of time steps are outputH_outputW_ and the dimension of each
time step is blockH_ * blockW_ * channels_. This layer can be used after
convolution neural network, and before recurrent neural network.
)DOC"
);
}
};
class
BlockExpandGradOp
:
public
framework
::
OperatorWithKernel
{
public:
using
framework
::
OperatorWithKernel
::
OperatorWithKernel
;
protected:
void
InferShape
(
framework
::
InferShapeContext
*
ctx
)
const
override
{}
};
}
// namespace operators
}
// namespace paddle
namespace
ops
=
paddle
::
operators
;
REGISTER_OP
(
block_expand
,
ops
::
BlockExpandOp
,
ops
::
BlockExpandOpMaker
,
block_expand_grad
,
ops
::
BlockExpandOpGrad
);
REGISTER_OP_CPU_KERNEL
(
block_expand
,
ops
::
BlockExpanddKernel
<
paddle
::
platform
::
CPUPlace
,
float
>
);
REGISTER_OP_CPU_KERNEL
(
block_expand_grad
,
ops
::
BlockExpandGradKernel
<
paddle
::
platform
::
CPUPlace
,
float
>
);
paddle/operators/block_expand_op.cu
0 → 100644
浏览文件 @
48556ba3
paddle/operators/block_expand_op.h
0 → 100644
浏览文件 @
48556ba3
/* Copyright (c) 2016 PaddlePaddle Authors. All Rights Reserve.
Licensed under the Apache License, Version 2.0 (the "License");
You may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License. */
#pragma once
#include "paddle/operators/math/math_function.h"
#include "paddle/framework/eigen.h"
#include "paddle/framework/op_registry.h"
namespace
paddle
{
namespace
operators
{
template
<
typename
Place
,
typename
T
>
class
BlockExpandKernel
:
public
framework
::
OpKernel
<
T
>
{
public:
void
Compute
(
const
framework
::
ExecutionContext
&
context
)
const
override
{
using
namespace
framework
;
const
Tensor
*
input
=
context
.
Input
<
Tensor
>
(
"input"
);
const
Tensor
*
filter
=
context
.
Input
<
Tensor
>
(
"filter"
);
const
Tensor
*
stride
=
context
.
Input
<
Tensor
>
(
"stride"
);
const
Tensor
*
padding
=
context
.
Input
<
Tensor
>
(
"padding"
);
Tensor
*
out
=
context
.
Output
<
Tensor
>
(
"Out"
);
auto
input_dim
=
input
->
dims
();
size_t
N
=
input_dim
[
0
];
size_t
C
=
input_dim
[
1
];
PADDLE_ENFORCE_GE
(
N
,
1
,
"Input batchsize must >= 1."
);
PADDLE_ENFORCE_EQ
(
input_dim
.
size
(),
4
,
"Input format must be NCHW."
);
size_t
input_height
=
input_dim
[
2
];
size_t
input_height
=
input_dim
[
3
];
size_t
filter_height
=
filter
[
0
];
size_t
filter_width
=
filter
[
1
];
size_t
output_height
=
1
+
(
input_height
+
2
*
padding_height
-
block_height
()
+
stride_height
-
1
)
/
stride_height
;
size_t
output_width
=
1
+
(
input_width
+
2
*
padding_width
-
block_width
()
+
stride_width
-
1
)
/
stride_width
;
Tensor
col
;
if
(
clo_format
=
KCFO
)
{
col
.
Resize
(
{
N
,
C
,
filter_height
,
filter_width
,
output_height
,
output_width
});
}
else
{
col
.
Resize
(
{
N
,
output_height
,
output_width
,
C
,
filter_height
,
filter_width
});
}
for
(
size_t
i
=
0
;
i
<
N
;
i
++
)
{
Im2ColFunctor
<
col_format
,
place
,
T
>
(
ctx
,
one_img
,
col
,
stride
[
0
],
stride
[
1
],
padding
[
0
],
padding
[
1
]);
}
}
};
template
<
typename
Place
,
typename
T
>
class
BlockExpandGradKernel
:
public
framework
::
OpKernel
<
T
>
{
public:
void
Compute
(
const
framework
::
ExecutionContext
&
ctx
)
const
override
{
using
Tensor
=
framework
::
Tensor
;
/*
int x_num_col_dims = ctx.template Attr<int>("x_num_col_dims");
int y_num_col_dims = ctx.template Attr<int>("y_num_col_dims");
const Tensor* x = ctx.Input<Tensor>("X");
const Tensor* y = ctx.Input<Tensor>("Y");
*/
}
};
}
// namespace operators
}
// namespace paddle
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录