Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle-Lite
提交
f1671532
P
Paddle-Lite
项目概览
PaddlePaddle
/
Paddle-Lite
通知
331
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看板
提交
f1671532
编写于
10月 25, 2018
作者:
L
lijiancheng0614
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
add reshape2 op
上级
d019e470
变更
9
显示空白变更内容
内联
并排
Showing
9 changed file
with
292 addition
and
0 deletion
+292
-0
src/common/types.cpp
src/common/types.cpp
+2
-0
src/framework/load_ops.h
src/framework/load_ops.h
+3
-0
src/operators/kernel/arm/reshape2_kernel.cpp
src/operators/kernel/arm/reshape2_kernel.cpp
+37
-0
src/operators/kernel/central-arm-func/reshape2_arm_func.h
src/operators/kernel/central-arm-func/reshape2_arm_func.h
+59
-0
src/operators/kernel/reshape2_kernel.h
src/operators/kernel/reshape2_kernel.h
+36
-0
src/operators/op_param.h
src/operators/op_param.h
+49
-0
src/operators/reshape2_op.cpp
src/operators/reshape2_op.cpp
+47
-0
src/operators/reshape2_op.h
src/operators/reshape2_op.h
+54
-0
tools/op.cmake
tools/op.cmake
+5
-0
未找到文件。
src/common/types.cpp
浏览文件 @
f1671532
...
...
@@ -40,6 +40,7 @@ const char *G_OP_TYPE_POOL2D = "pool2d";
const
char
*
G_OP_TYPE_PRIOR_BOX
=
"prior_box"
;
const
char
*
G_OP_TYPE_RELU
=
"relu"
;
const
char
*
G_OP_TYPE_RESHAPE
=
"reshape"
;
const
char
*
G_OP_TYPE_RESHAPE2
=
"reshape2"
;
const
char
*
G_OP_TYPE_SIGMOID
=
"sigmoid"
;
const
char
*
G_OP_TYPE_SOFTMAX
=
"softmax"
;
const
char
*
G_OP_TYPE_TRANSPOSE
=
"transpose"
;
...
...
@@ -99,6 +100,7 @@ std::unordered_map<
{
G_OP_TYPE_POLYGON_BOX_TRANSFORM
,
{{
"Input"
},
{
"Output"
}}},
{
G_OP_TYPE_FC
,
{{
"X"
,
"Y"
,
"Z"
},
{
"Out"
}}},
{
G_OP_TYPE_RESHAPE
,
{{
"X"
},
{
"Out"
}}},
{
G_OP_TYPE_RESHAPE2
,
{{
"X"
},
{
"Out"
,
"XShape"
}}},
{
G_OP_TYPE_DEPTHWISE_CONV
,
{{
"Input"
},
{
"Output"
}}},
{
G_OP_TYPE_FILL_CONSTANT
,
{{},
{
"Out"
}}},
{
G_OP_TYPE_FUSION_CONV_ADD_RELU
,
{{
"Input"
},
{
"Out"
}}},
...
...
src/framework/load_ops.h
浏览文件 @
f1671532
...
...
@@ -109,6 +109,9 @@ LOAD_FUSION_MATCHER(fusion_conv_add_bn_relu);
#ifdef RESHAPE_OP
LOAD_OP2
(
reshape
,
CPU
,
MALI_GPU
);
#endif
#ifdef RESHAPE2_OP
LOAD_OP2
(
reshape2
,
CPU
,
MALI_GPU
);
#endif
#ifdef TRANSPOSE_OP
LOAD_OP1
(
transpose
,
CPU
);
#endif
...
...
src/operators/kernel/arm/reshape2_kernel.cpp
0 → 100644
浏览文件 @
f1671532
/* Copyright (c) 2018 PaddlePaddle Authors. All Rights Reserved.
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. */
#ifdef RESHAPE2_OP
#include "operators/kernel/reshape2_kernel.h"
#include "operators/kernel/central-arm-func/reshape2_arm_func.h"
namespace
paddle_mobile
{
namespace
operators
{
template
<
>
bool
Reshape2Kernel
<
CPU
,
float
>::
Init
(
Reshape2Param
<
CPU
>
*
param
)
{
return
true
;
}
template
<
>
void
Reshape2Kernel
<
CPU
,
float
>::
Compute
(
const
Reshape2Param
<
CPU
>
&
param
)
const
{
Reshape2Compute
<
float
>
(
param
);
}
}
// namespace operators
}
// namespace paddle_mobile
#endif
src/operators/kernel/central-arm-func/reshape2_arm_func.h
0 → 100644
浏览文件 @
f1671532
/* Copyright (c) 2018 PaddlePaddle Authors. All Rights Reserved.
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. */
#ifdef RESHAPE2_OP
#pragma once
#include <vector>
#include "operators/kernel/reshape_kernel.h"
#include "operators/op_param.h"
namespace
paddle_mobile
{
namespace
operators
{
template
<
typename
P
>
void
Reshape2Compute
(
const
Reshape2Param
<
CPU
>
&
param
)
{
const
auto
*
input_x
=
param
.
InputX
();
const
auto
&
input_x_dims
=
input_x
->
dims
();
auto
*
out
=
param
.
Out
();
framework
::
DDim
out_dims
=
out
->
dims
();
const
auto
*
input_shape
=
param
.
InputShape
();
if
(
input_shape
)
{
auto
*
shape_data
=
input_shape
->
data
<
int
>
();
framework
::
Tensor
cpu_shape_tensor
;
auto
shape
=
std
::
vector
<
int
>
(
shape_data
,
shape_data
+
input_shape
->
numel
());
out_dims
=
ValidateShape
(
shape
,
input_x
->
dims
());
}
else
{
auto
&
shape
=
param
.
Shape
();
out_dims
=
ValidateShape
(
shape
,
input_x_dims
);
}
bool
inplace
=
param
.
Inplace
();
out
->
Resize
(
out_dims
);
if
(
!
inplace
)
{
out
->
mutable_data
<
float
>
();
framework
::
TensorCopy
(
*
input_x
,
out
);
out
->
Resize
(
out_dims
);
}
else
{
out
->
ShareDataWith
(
*
input_x
);
out
->
Resize
(
out_dims
);
}
}
}
// namespace operators
}
// namespace paddle_mobile
#endif
src/operators/kernel/reshape2_kernel.h
0 → 100644
浏览文件 @
f1671532
/* Copyright (c) 2018 PaddlePaddle Authors. All Rights Reserved.
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. */
#ifdef RESHAPE2_OP
#pragma once
#include <vector>
#include "framework/operator.h"
#include "operators/op_param.h"
namespace
paddle_mobile
{
namespace
operators
{
template
<
typename
DeviceType
,
typename
T
>
class
Reshape2Kernel
:
public
framework
::
OpKernelBase
<
DeviceType
,
Reshape2Param
<
DeviceType
>>
{
public:
void
Compute
(
const
Reshape2Param
<
DeviceType
>&
param
)
const
;
bool
Init
(
Reshape2Param
<
DeviceType
>*
param
);
};
}
// namespace operators
}
// namespace paddle_mobile
#endif
src/operators/op_param.h
浏览文件 @
f1671532
...
...
@@ -243,6 +243,12 @@ class OpParam {
return
GetVarValue
<
T
>
(
"Y"
,
outputs
,
scope
);
}
template
<
typename
T
>
static
T
*
OutputXShapeFrom
(
const
VariableNameMap
&
outputs
,
const
Scope
&
scope
)
{
return
GetVarValue
<
T
>
(
"XShape"
,
outputs
,
scope
);
}
template
<
typename
T
>
static
T
*
OutputBoxesFrom
(
const
VariableNameMap
&
outputs
,
const
Scope
&
scope
)
{
...
...
@@ -1233,6 +1239,49 @@ class ReshapeParam : public OpParam {
};
#endif
#ifdef RESHAPE2_OP
template
<
typename
Dtype
>
class
Reshape2Param
:
public
OpParam
{
typedef
typename
DtypeTensorTrait
<
Dtype
>::
gtype
GType
;
typedef
typename
DtypeTensorTrait
<
Dtype
>::
rtype
RType
;
public:
Reshape2Param
(
const
VariableNameMap
&
inputs
,
const
VariableNameMap
&
outputs
,
const
AttributeMap
&
attrs
,
const
Scope
&
scope
)
{
input_x_
=
InputXFrom
<
GType
>
(
inputs
,
scope
);
input_shape_
=
InputShapeFrom
<
GType
>
(
inputs
,
scope
);
out_
=
OutFrom
<
GType
>
(
outputs
,
scope
);
output_xshape_
=
OutputXShapeFrom
<
GType
>
(
outputs
,
scope
);
shape_
=
GetAttr
<
vector
<
int
>>
(
"shape"
,
attrs
);
if
(
HasAttr
(
"inplace"
,
attrs
))
{
inplace_
=
GetAttr
<
bool
>
(
"inplace"
,
attrs
);
}
else
{
inplace_
=
false
;
}
}
const
RType
*
InputX
()
const
{
return
input_x_
;
}
const
RType
*
InputShape
()
const
{
return
input_shape_
;
}
RType
*
Out
()
const
{
return
out_
;
}
RType
*
OutputXShape
()
const
{
return
output_xshape_
;
}
const
vector
<
int
>
&
Shape
()
const
{
return
shape_
;
}
const
bool
&
Inplace
()
const
{
return
inplace_
;
}
private:
RType
*
input_x_
;
RType
*
input_shape_
;
RType
*
out_
;
RType
*
output_xshape_
;
vector
<
int
>
shape_
;
bool
inplace_
;
};
#endif
#ifdef SCALE_OP
template
<
typename
Dtype
>
class
ScaleParam
:
public
OpParam
{
...
...
src/operators/reshape2_op.cpp
0 → 100644
浏览文件 @
f1671532
/* Copyright (c) 2018 PaddlePaddle Authors. All Rights Reserved.
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. */
#ifdef RESHAPE2_OP
#include "operators/reshape2_op.h"
#include <vector>
#include "operators/kernel/reshape_kernel.h"
namespace
paddle_mobile
{
namespace
operators
{
template
<
typename
Dtype
,
typename
T
>
void
Reshape2Op
<
Dtype
,
T
>::
InferShape
()
const
{
auto
&
shape
=
this
->
param_
.
Shape
();
auto
input_x_dims
=
this
->
param_
.
InputX
()
->
dims
();
auto
out_dims
=
ValidateShape
(
shape
,
input_x_dims
);
this
->
param_
.
Out
()
->
Resize
(
out_dims
);
std
::
vector
<
int64_t
>
xshape_dims
(
input_x_dims
.
size
()
+
1
,
0
);
for
(
int
i
=
0
;
i
<
input_x_dims
.
size
();
++
i
)
{
xshape_dims
[
i
+
1
]
=
input_x_dims
[
i
];
}
this
->
param_
.
OutputXShape
()
->
Resize
(
framework
::
make_ddim
(
xshape_dims
));
}
}
// namespace operators
}
// namespace paddle_mobile
namespace
ops
=
paddle_mobile
::
operators
;
#ifdef PADDLE_MOBILE_CPU
REGISTER_OPERATOR_CPU
(
reshape2
,
ops
::
Reshape2Op
);
#endif
#ifdef PADDLE_MOBILE_MALI_GPU
REGISTER_OPERATOR_MALI_GPU
(
reshape2
,
ops
::
Reshape2Op
);
#endif
#endif
src/operators/reshape2_op.h
0 → 100644
浏览文件 @
f1671532
/* Copyright (c) 2018 PaddlePaddle Authors. All Rights Reserved.
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. */
#ifdef RESHAPE2_OP
#pragma once
#include <string>
#include "framework/operator.h"
#include "operators/kernel/reshape2_kernel.h"
#include "operators/op_param.h"
namespace
paddle_mobile
{
namespace
operators
{
using
paddle_mobile
::
framework
::
Tensor
;
template
<
typename
DeviceType
,
typename
T
>
class
Reshape2Op
:
public
framework
::
OperatorWithKernel
<
DeviceType
,
Reshape2Param
<
DeviceType
>
,
operators
::
Reshape2Kernel
<
DeviceType
,
T
>>
{
public:
Reshape2Op
(
const
std
::
string
&
type
,
const
VariableNameMap
&
inputs
,
const
VariableNameMap
&
outputs
,
const
framework
::
AttributeMap
&
attrs
,
std
::
shared_ptr
<
framework
::
Scope
>
scope
)
:
framework
::
OperatorWithKernel
<
DeviceType
,
Reshape2Param
<
DeviceType
>
,
operators
::
Reshape2Kernel
<
DeviceType
,
T
>>
(
type
,
inputs
,
outputs
,
attrs
,
scope
)
{}
using
framework
::
OperatorWithKernel
<
DeviceType
,
Reshape2Param
<
DeviceType
>
,
operators
::
Reshape2Kernel
<
DeviceType
,
T
>>::
OperatorWithKernel
;
void
InferShape
()
const
override
;
protected:
};
}
// namespace operators
}
// namespace paddle_mobile
#endif
tools/op.cmake
浏览文件 @
f1671532
...
...
@@ -201,6 +201,7 @@ if(NOT FOUND_MATCH)
set
(
PRIORBOX_OP ON
)
set
(
RELU_OP ON
)
set
(
RESHAPE_OP ON
)
set
(
RESHAPE2_OP ON
)
set
(
SIGMOID_OP ON
)
set
(
SOFTMAX_OP ON
)
set
(
TRANSPOSE_OP ON
)
...
...
@@ -246,6 +247,7 @@ endif()
# option(PRIORBOX_OP "" ON)
# option(RELU_OP "" ON)
# option(RESHAPE_OP "" ON)
# option(RESHAPE2_OP "" ON)
# option(SIGMOID_OP "" ON)
# option(SOFTMAX_OP "" ON)
# option(TRANSPOSE_OP "" ON)
...
...
@@ -314,6 +316,9 @@ endif()
if
(
RESHAPE_OP
)
add_definitions
(
-DRESHAPE_OP
)
endif
()
if
(
RESHAPE2_OP
)
add_definitions
(
-DRESHAPE2_OP
)
endif
()
if
(
SIGMOID_OP
)
add_definitions
(
-DSIGMOID_OP
)
endif
()
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录