Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle-Lite
提交
fc280daf
P
Paddle-Lite
项目概览
PaddlePaddle
/
Paddle-Lite
通知
332
Star
4
Fork
1
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
271
列表
看板
标记
里程碑
合并请求
78
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
Paddle-Lite
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
271
Issue
271
列表
看板
标记
里程碑
合并请求
78
合并请求
78
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
fc280daf
编写于
9月 08, 2018
作者:
xiebaiyuan
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
flatten op impl
上级
4c191812
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
50 addition
and
3 deletion
+50
-3
src/operators/flatten_op.cpp
src/operators/flatten_op.cpp
+40
-2
src/operators/kernel/central-arm-func/flatten_arm_func.h
src/operators/kernel/central-arm-func/flatten_arm_func.h
+5
-1
src/operators/op_param.h
src/operators/op_param.h
+5
-0
未找到文件。
src/operators/flatten_op.cpp
浏览文件 @
fc280daf
...
...
@@ -18,10 +18,48 @@ limitations under the License. */
namespace
paddle_mobile
{
namespace
operators
{
static
std
::
vector
<
int32_t
>
GetOutputShape
(
const
int
axis
,
const
framework
::
DDim
&
in_dims
)
{
int64_t
outer
=
1
,
inner
=
1
;
for
(
int
i
=
0
;
i
<
in_dims
.
size
();
++
i
)
{
if
(
i
<
axis
)
{
outer
*=
in_dims
[
i
];
}
else
{
inner
*=
in_dims
[
i
];
}
}
std
::
vector
<
int32_t
>
out_shape
(
2
);
out_shape
[
0
]
=
static_cast
<
int
>
(
outer
);
out_shape
[
1
]
=
static_cast
<
int
>
(
inner
);
return
out_shape
;
}
template
<
typename
DeviceType
,
typename
T
>
void
FlattenOp
<
DeviceType
,
T
>::
InferShape
()
const
{
// todo check
this
->
param_
.
Out
()
->
Resize
(
this
->
param_
.
InputX
()
->
dims
());
PADDLE_MOBILE_ENFORCE
(
this
->
param_
.
InputX
()
!=
nullptr
,
"Input (X) of Flatten op should not be null."
);
PADDLE_MOBILE_ENFORCE
(
this
->
param_
.
Out
()
!=
nullptr
,
"Output (Output) of Flatten op should not be null."
);
auto
&
axis
=
this
->
param_
.
Axis
();
PADDLE_MOBILE_ENFORCE
(
axis
>=
0
,
"The axis should be greater than or equal to 0."
);
auto
&
in_dims
=
this
->
param_
.
InputX
()
->
dims
();
// const auto &in_dims = ctx->GetInputDim("X");
PADDLE_MOBILE_ENFORCE
(
axis
<=
in_dims
.
size
(),
"The axis should be less than or equal to input tensor's rank."
);
const
auto
&
out_dims
=
GetOutputShape
(
axis
,
in_dims
);
this
->
param_
.
Out
()
->
Resize
(
in_dims
);
// todo supprot lodtensor
// if (in_dims[0] == out_dims[0]) {
// // Only pass LoD when the first dimension of output and Input(X)
// // are the same.
// ctx->ShareLoD("X", "Out");
// }
}
}
// namespace operators
...
...
src/operators/kernel/central-arm-func/flatten_arm_func.h
浏览文件 @
fc280daf
...
...
@@ -22,7 +22,11 @@ namespace paddle_mobile {
namespace
operators
{
template
<
typename
P
>
void
FlattenCompute
(
const
FlattenParam
<
CPU
>&
param
)
{}
void
FlattenCompute
(
const
FlattenParam
<
CPU
>
&
param
)
{
param
.
Out
()
->
mutable_data
<
float
>
();
framework
::
TensorCopy
(
*
param
.
InputX
(),
param
.
Out
());
param
.
Out
()
->
Resize
(
param
.
Out
()
->
dims
());
}
}
// namespace operators
}
// namespace paddle_mobile
...
...
src/operators/op_param.h
浏览文件 @
fc280daf
...
...
@@ -2268,13 +2268,16 @@ class FlattenParam : public OpParam {
const
AttributeMap
&
attrs
,
const
Scope
&
scope
)
{
input_x_
=
InputXFrom
<
GType
>
(
inputs
,
scope
);
out_
=
OutFrom
<
GType
>
(
outputs
,
scope
);
axis
=
GetAttr
<
int
>
(
"axis"
,
attrs
);
}
const
RType
*
InputX
()
const
{
return
input_x_
;
}
RType
*
Out
()
const
{
return
out_
;
}
const
int
&
Axis
()
const
{
return
axis
;
}
private:
RType
*
input_x_
;
RType
*
out_
;
int
axis
;
};
#endif
...
...
@@ -2289,6 +2292,7 @@ class SplitParam : public OpParam {
const
AttributeMap
&
attrs
,
const
Scope
&
scope
)
{
input_x_
=
InputXFrom
<
GType
>
(
inputs
,
scope
);
out_
=
OutFrom
<
GType
>
(
outputs
,
scope
);
axis
=
GetAttr
<
int
>
(
"axis"
,
attrs
);
}
const
RType
*
InputX
()
const
{
return
input_x_
;
}
RType
*
Out
()
const
{
return
out_
;
}
...
...
@@ -2296,6 +2300,7 @@ class SplitParam : public OpParam {
private:
RType
*
input_x_
;
RType
*
out_
;
int
axis
;
};
#endif
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录