Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle-Lite
提交
68d24507
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看板
提交
68d24507
编写于
2月 20, 2019
作者:
H
hjchen2
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
add pad2d op, and fix bugs
上级
89fc6315
变更
9
显示空白变更内容
内联
并排
Showing
9 changed file
with
208 addition
and
37 deletion
+208
-37
src/common/types.cpp
src/common/types.cpp
+4
-1
src/common/types.h
src/common/types.h
+2
-0
src/framework/executor.cpp
src/framework/executor.cpp
+24
-36
src/framework/load_ops.h
src/framework/load_ops.h
+3
-0
src/operators/kernel/arm/pad2d_kernel.cpp
src/operators/kernel/arm/pad2d_kernel.cpp
+45
-0
src/operators/kernel/pad2d_kernel.h
src/operators/kernel/pad2d_kernel.h
+52
-0
src/operators/pad2d.cpp
src/operators/pad2d.cpp
+42
-0
src/operators/pad2d.h
src/operators/pad2d.h
+32
-0
tools/op.cmake
tools/op.cmake
+4
-0
未找到文件。
src/common/types.cpp
浏览文件 @
68d24507
...
@@ -112,6 +112,8 @@ const char *G_OP_TYPE_GENERATE_PROPOSALS = "generate_proposals";
...
@@ -112,6 +112,8 @@ const char *G_OP_TYPE_GENERATE_PROPOSALS = "generate_proposals";
const
char
*
G_OP_TYPE_PSROI_POOL
=
"psroi_pool"
;
const
char
*
G_OP_TYPE_PSROI_POOL
=
"psroi_pool"
;
const
char
*
G_OP_TYPE_ROI_PERSPECTIVE
=
"roi_perspective_transform"
;
const
char
*
G_OP_TYPE_ROI_PERSPECTIVE
=
"roi_perspective_transform"
;
const
char
*
G_OP_TYPE_PAD2D
=
"pad2d"
;
std
::
unordered_map
<
std
::
unordered_map
<
std
::
string
,
std
::
pair
<
std
::
vector
<
std
::
string
>
,
std
::
vector
<
std
::
string
>>>
std
::
string
,
std
::
pair
<
std
::
vector
<
std
::
string
>
,
std
::
vector
<
std
::
string
>>>
op_input_output_key
=
{
op_input_output_key
=
{
...
@@ -210,5 +212,6 @@ std::unordered_map<
...
@@ -210,5 +212,6 @@ std::unordered_map<
{{
"Scores"
,
"BboxDeltas"
,
"ImInfo"
,
"Anchors"
,
"Variances"
},
{{
"Scores"
,
"BboxDeltas"
,
"ImInfo"
,
"Anchors"
,
"Variances"
},
{
"RpnRois"
,
"RpnRoiProbs"
}}},
{
"RpnRois"
,
"RpnRoiProbs"
}}},
{
G_OP_TYPE_PSROI_POOL
,
{{
"X"
,
"ROIs"
},
{
"Out"
}}},
{
G_OP_TYPE_PSROI_POOL
,
{{
"X"
,
"ROIs"
},
{
"Out"
}}},
{
G_OP_TYPE_ROI_PERSPECTIVE
,
{{
"X"
,
"ROIs"
},
{
"Out"
}}}};
{
G_OP_TYPE_ROI_PERSPECTIVE
,
{{
"X"
,
"ROIs"
},
{
"Out"
}}},
{
G_OP_TYPE_PAD2D
,
{{
"X"
},
{
"Out"
}}}};
}
// namespace paddle_mobile
}
// namespace paddle_mobile
src/common/types.h
浏览文件 @
68d24507
...
@@ -200,6 +200,8 @@ extern const char *G_OP_TYPE_GENERATE_PROPOSALS;
...
@@ -200,6 +200,8 @@ extern const char *G_OP_TYPE_GENERATE_PROPOSALS;
extern
const
char
*
G_OP_TYPE_PSROI_POOL
;
extern
const
char
*
G_OP_TYPE_PSROI_POOL
;
extern
const
char
*
G_OP_TYPE_ROI_PERSPECTIVE
;
extern
const
char
*
G_OP_TYPE_ROI_PERSPECTIVE
;
extern
const
char
*
G_OP_TYPE_PAD2D
;
extern
std
::
unordered_map
<
extern
std
::
unordered_map
<
std
::
string
,
std
::
pair
<
std
::
vector
<
std
::
string
>
,
std
::
vector
<
std
::
string
>>>
std
::
string
,
std
::
pair
<
std
::
vector
<
std
::
string
>
,
std
::
vector
<
std
::
string
>>>
op_input_output_key
;
op_input_output_key
;
...
...
src/framework/executor.cpp
浏览文件 @
68d24507
...
@@ -378,18 +378,14 @@ std::vector<T> Executor<Device, T>::Predict(const std::vector<T> &input,
...
@@ -378,18 +378,14 @@ std::vector<T> Executor<Device, T>::Predict(const std::vector<T> &input,
template
<
typename
Device
,
typename
T
>
template
<
typename
Device
,
typename
T
>
void
Executor
<
Device
,
T
>::
SetInput
(
const
Tensor
&
input
,
void
Executor
<
Device
,
T
>::
SetInput
(
const
Tensor
&
input
,
const
std
::
string
&
var_name
)
{
const
std
::
string
&
var_name
)
{
framework
::
LoDTensor
*
target
=
nullptr
;
int
index
=
0
;
if
(
feed_indices_
.
find
(
var_name
)
!=
feed_indices_
.
end
())
{
if
(
feed_indices_
.
find
(
var_name
)
!=
feed_indices_
.
end
())
{
int
index
=
feed_indices_
.
find
(
var_name
)
->
second
;
index
=
feed_indices_
.
find
(
var_name
)
->
second
;
auto
*
feed_var
=
program_
.
scope
->
Var
(
"feed"
);
target
=
&
(
feed_var
->
template
GetMutable
<
framework
::
LoDTensorArray
>()
->
at
(
index
));
}
else
{
auto
*
target_var
=
program_
.
scope
->
FindVar
(
var_name
);
PADDLE_MOBILE_ENFORCE
(
target_var
!=
nullptr
,
"Variable %s is not exist"
,
var_name
.
c_str
());
target
=
target_var
->
template
GetMutable
<
LoDTensor
>();
}
}
auto
*
feed_var
=
program_
.
scope
->
Var
(
"feed"
);
framework
::
LoDTensor
&
target
=
feed_var
->
template
GetMutable
<
framework
::
LoDTensorArray
>()
->
at
(
index
);
if
(
config_
.
load_when_predict
)
{
if
(
config_
.
load_when_predict
)
{
if
(
input_dim_last_
!=
input
.
dims
())
{
if
(
input_dim_last_
!=
input
.
dims
())
{
InitNoPersistableMemory
(
input
);
InitNoPersistableMemory
(
input
);
...
@@ -397,25 +393,21 @@ void Executor<Device, T>::SetInput(const Tensor &input,
...
@@ -397,25 +393,21 @@ void Executor<Device, T>::SetInput(const Tensor &input,
}
}
}
}
target
->
Resize
(
input
.
dims
());
target
.
Resize
(
input
.
dims
());
target
->
ShareDataWith
(
input
);
target
.
ShareDataWith
(
input
);
}
}
template
<
typename
Device
,
typename
T
>
template
<
typename
Device
,
typename
T
>
void
Executor
<
Device
,
T
>::
SetInput
(
const
LoDTensor
&
input
,
void
Executor
<
Device
,
T
>::
SetInput
(
const
LoDTensor
&
input
,
const
std
::
string
&
var_name
)
{
const
std
::
string
&
var_name
)
{
framework
::
LoDTensor
*
target
=
nullptr
;
int
index
=
0
;
if
(
feed_indices_
.
find
(
var_name
)
!=
feed_indices_
.
end
())
{
if
(
feed_indices_
.
find
(
var_name
)
!=
feed_indices_
.
end
())
{
int
index
=
feed_indices_
.
find
(
var_name
)
->
second
;
index
=
feed_indices_
.
find
(
var_name
)
->
second
;
auto
*
feed_var
=
program_
.
scope
->
Var
(
"feed"
);
target
=
&
(
feed_var
->
template
GetMutable
<
framework
::
LoDTensorArray
>()
->
at
(
index
));
}
else
{
auto
*
target_var
=
program_
.
scope
->
FindVar
(
var_name
);
PADDLE_MOBILE_ENFORCE
(
target_var
!=
nullptr
,
"Variable %s is not exist"
,
var_name
.
c_str
());
target
=
target_var
->
template
GetMutable
<
LoDTensor
>();
}
}
auto
*
feed_var
=
program_
.
scope
->
Var
(
"feed"
);
framework
::
LoDTensor
&
target
=
feed_var
->
template
GetMutable
<
framework
::
LoDTensorArray
>()
->
at
(
index
);
if
(
config_
.
load_when_predict
)
{
if
(
config_
.
load_when_predict
)
{
if
(
input_dim_last_
!=
input
.
dims
())
{
if
(
input_dim_last_
!=
input
.
dims
())
{
InitNoPersistableMemory
(
input
);
InitNoPersistableMemory
(
input
);
...
@@ -423,27 +415,23 @@ void Executor<Device, T>::SetInput(const LoDTensor &input,
...
@@ -423,27 +415,23 @@ void Executor<Device, T>::SetInput(const LoDTensor &input,
}
}
}
}
target
->
Resize
(
input
.
dims
());
target
.
Resize
(
input
.
dims
());
target
->
ShareDataWith
(
input
);
target
.
ShareDataWith
(
input
);
target
->
set_lod
(
input
.
lod
());
target
.
set_lod
(
input
.
lod
());
}
}
template
<
typename
Device
,
typename
T
>
template
<
typename
Device
,
typename
T
>
std
::
shared_ptr
<
LoDTensor
>
Executor
<
Device
,
T
>::
GetOutput
(
std
::
shared_ptr
<
LoDTensor
>
Executor
<
Device
,
T
>::
GetOutput
(
const
std
::
string
&
var_name
)
{
const
std
::
string
&
var_name
)
{
framework
::
LoDTensor
*
target
=
nullptr
;
int
index
=
0
;
if
(
fetch_indices_
.
find
(
var_name
)
!=
fetch_indices_
.
end
())
{
if
(
fetch_indices_
.
find
(
var_name
)
!=
fetch_indices_
.
end
())
{
int
index
=
fetch_indices_
.
find
(
var_name
)
->
second
;
index
=
fetch_indices_
.
find
(
var_name
)
->
second
;
auto
*
fetch_var
=
program_
.
scope
->
Var
(
"fetch"
);
target
=
&
(
fetch_var
->
template
GetMutable
<
framework
::
LoDTensorArray
>()
->
at
(
index
));
}
else
{
auto
*
target_var
=
program_
.
scope
->
FindVar
(
var_name
);
PADDLE_MOBILE_ENFORCE
(
target_var
!=
nullptr
,
"Variable %s is not exist"
,
var_name
.
c_str
());
target
=
target_var
->
template
GetMutable
<
LoDTensor
>();
}
}
return
std
::
make_shared
<
LoDTensor
>
(
*
target
);
auto
*
fetch_var
=
program_
.
scope
->
Var
(
"fetch"
);
framework
::
LoDTensor
&
target
=
fetch_var
->
template
GetMutable
<
framework
::
LoDTensorArray
>()
->
at
(
index
);
return
std
::
make_shared
<
LoDTensor
>
(
target
);
}
}
template
<
typename
Device
,
typename
T
>
template
<
typename
Device
,
typename
T
>
...
...
src/framework/load_ops.h
浏览文件 @
68d24507
...
@@ -327,3 +327,6 @@ LOAD_OP1(roi_perspective_transform, CPU);
...
@@ -327,3 +327,6 @@ LOAD_OP1(roi_perspective_transform, CPU);
#ifdef BEAM_SEARCH_DECODE_OP
#ifdef BEAM_SEARCH_DECODE_OP
LOAD_OP1
(
beam_search_decode
,
CPU
);
LOAD_OP1
(
beam_search_decode
,
CPU
);
#endif
#endif
#ifdef PAD2D_OP
LOAD_OP1
(
pad2d
,
CPU
);
#endif
src/operators/kernel/arm/pad2d_kernel.cpp
0 → 100644
浏览文件 @
68d24507
/* 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 PAD2D_OP
#include "operators/kernel/pad2d_kernel.h"
#include "operators/math/pad.h"
namespace
paddle_mobile
{
namespace
operators
{
template
<
>
bool
Pad2DKernel
<
CPU
,
float
>::
Init
(
Pad2DParam
<
CPU
>
*
param
)
{
return
true
;
}
template
<
>
void
Pad2DKernel
<
CPU
,
float
>::
Compute
(
const
Pad2DParam
<
CPU
>
&
param
)
{
const
auto
*
input
=
param
.
input_
;
auto
*
output
=
param
.
output_
;
const
auto
&
paddings
=
param
.
paddings_
;
// if (param.mode_ == "constant" && param.pad_value_ == 0) {
math
::
PadFunctor
<
CPU
,
float
>
pad
;
pad
(
*
input
,
paddings
[
0
],
paddings
[
1
],
paddings
[
2
],
paddings
[
3
],
output
);
// } else {
// PADDLE_MOBILE_THROW_EXCEPTION("Pad2D has not been implemented.");
// }
output
->
set_lod
(
input
->
lod
());
}
}
// namespace operators
}
// namespace paddle_mobile
#endif // PAD2D_OP
src/operators/kernel/pad2d_kernel.h
0 → 100644
浏览文件 @
68d24507
/* 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 PAD2D_OP
#pragma once
#include <string>
#include <vector>
#include "framework/operator.h"
#include "operators/op_param.h"
namespace
paddle_mobile
{
namespace
operators
{
template
<
typename
Dtype
>
class
Pad2DParam
:
public
OpParam
{
public:
Pad2DParam
(
const
VariableNameMap
&
inputs
,
const
VariableNameMap
&
outputs
,
const
AttributeMap
&
attrs
,
const
Scope
&
scope
)
{
input_
=
OpParam
::
GetVarValue
<
framework
::
LoDTensor
>
(
"X"
,
inputs
,
scope
);
output_
=
OpParam
::
GetVarValue
<
framework
::
LoDTensor
>
(
"Out"
,
outputs
,
scope
);
paddings_
=
OpParam
::
GetAttr
<
std
::
vector
<
int
>>
(
"paddings"
,
attrs
);
pad_value_
=
OpParam
::
GetAttr
<
float
>
(
"pad_value"
,
attrs
);
mode_
=
OpParam
::
GetStringAttr
(
"mode"
,
attrs
);
}
public:
framework
::
LoDTensor
*
input_
;
framework
::
LoDTensor
*
output_
;
std
::
vector
<
int
>
paddings_
;
float
pad_value_
;
std
::
string
mode_
;
};
DECLARE_KERNEL
(
Pad2D
,
Pad2DParam
);
}
// namespace operators
}
// namespace paddle_mobile
#endif // PAD2D_OP
src/operators/pad2d.cpp
0 → 100644
浏览文件 @
68d24507
/* 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 PAD2D_OP
#include "operators/pad2d.h"
namespace
paddle_mobile
{
namespace
operators
{
template
<
typename
Dtype
,
typename
T
>
void
Pad2DOp
<
Dtype
,
T
>::
InferShape
()
const
{
auto
input_dims
=
this
->
param_
.
input_
->
dims
();
const
auto
&
paddings
=
this
->
param_
.
paddings_
;
PADDLE_MOBILE_ENFORCE
(
paddings
.
size
()
==
4
,
"Size of paddings should be equal to 4."
);
input_dims
[
2
]
+=
paddings
[
0
]
+
paddings
[
1
];
input_dims
[
3
]
+=
paddings
[
2
]
+
paddings
[
3
];
this
->
param_
.
output_
->
Resize
(
input_dims
);
}
}
// namespace operators
}
// namespace paddle_mobile
namespace
ops
=
paddle_mobile
::
operators
;
#ifdef PADDLE_MOBILE_CPU
REGISTER_OPERATOR_CPU
(
pad2d
,
ops
::
Pad2DOp
);
#endif
#endif // PAD2D_OP
src/operators/pad2d.h
0 → 100644
浏览文件 @
68d24507
/* 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 PAD2D_OP
#pragma once
#include <string>
#include "framework/operator.h"
#include "operators/kernel/pad2d_kernel.h"
#include "operators/op_param.h"
namespace
paddle_mobile
{
namespace
operators
{
DECLARE_OPERATOR
(
Pad2D
,
Pad2DParam
,
Pad2DKernel
);
}
// namespace operators
}
// namespace paddle_mobile
#endif // PAD2D_OP
tools/op.cmake
浏览文件 @
68d24507
...
@@ -300,6 +300,7 @@ if(NOT FOUND_MATCH)
...
@@ -300,6 +300,7 @@ if(NOT FOUND_MATCH)
set
(
PSROI_POOL_OP ON
)
set
(
PSROI_POOL_OP ON
)
set
(
ROI_PERSPECTIVE_OP ON
)
set
(
ROI_PERSPECTIVE_OP ON
)
set
(
BEAM_SEARCH_DECODE_OP ON
)
set
(
BEAM_SEARCH_DECODE_OP ON
)
set
(
PAD2D_OP ON
)
endif
()
endif
()
# option(BATCHNORM_OP "" ON)
# option(BATCHNORM_OP "" ON)
...
@@ -606,3 +607,6 @@ endif()
...
@@ -606,3 +607,6 @@ endif()
if
(
BEAM_SEARCH_DECODE_OP
)
if
(
BEAM_SEARCH_DECODE_OP
)
add_definitions
(
-DBEAM_SEARCH_DECODE_OP
)
add_definitions
(
-DBEAM_SEARCH_DECODE_OP
)
endif
()
endif
()
if
(
PAD2D_OP
)
add_definitions
(
-DPAD2D_OP
)
endif
()
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录