Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle-Lite
提交
5b229a61
P
Paddle-Lite
项目概览
PaddlePaddle
/
Paddle-Lite
通知
337
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看板
提交
5b229a61
编写于
3月 12, 2019
作者:
H
hjchen2
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
update
上级
82f57756
变更
19
隐藏空白更改
内联
并排
Showing
19 changed file
with
120 addition
and
363 deletion
+120
-363
src/common/types.cpp
src/common/types.cpp
+0
-2
src/framework/operator.h
src/framework/operator.h
+1
-23
src/operators/fill_constant_op.h
src/operators/fill_constant_op.h
+1
-1
src/operators/kernel/arm/conv_kernel.cpp
src/operators/kernel/arm/conv_kernel.cpp
+0
-137
src/operators/kernel/arm/convolution/conv_add_bn_relu_kernel.cpp
...rators/kernel/arm/convolution/conv_add_bn_relu_kernel.cpp
+2
-2
src/operators/kernel/arm/convolution/conv_bn_add_relu_kernel.cpp
...rators/kernel/arm/convolution/conv_bn_add_relu_kernel.cpp
+3
-2
src/operators/kernel/arm/convolution/conv_bn_relu_kernel.cpp
src/operators/kernel/arm/convolution/conv_bn_relu_kernel.cpp
+2
-2
src/operators/kernel/beam_search_decode_kernel.h
src/operators/kernel/beam_search_decode_kernel.h
+6
-5
src/operators/kernel/beam_search_kernel.h
src/operators/kernel/beam_search_kernel.h
+11
-9
src/operators/kernel/one_hot_kernel.h
src/operators/kernel/one_hot_kernel.h
+4
-3
src/operators/kernel/pad2d_kernel.h
src/operators/kernel/pad2d_kernel.h
+5
-3
src/operators/kernel/while_kernel.h
src/operators/kernel/while_kernel.h
+2
-5
src/operators/op_param.h
src/operators/op_param.h
+44
-44
src/operators/pad2d.cpp
src/operators/pad2d.cpp
+0
-42
src/operators/pad2d.h
src/operators/pad2d.h
+0
-32
src/operators/pad2d_op.cpp
src/operators/pad2d_op.cpp
+11
-13
src/operators/pad2d_op.h
src/operators/pad2d_op.h
+4
-21
test/net/test_ocr.cpp
test/net/test_ocr.cpp
+23
-17
tools/op.cmake
tools/op.cmake
+1
-0
未找到文件。
src/common/types.cpp
100755 → 100644
浏览文件 @
5b229a61
...
...
@@ -116,8 +116,6 @@ const char *G_OP_TYPE_FUSION_DECONV_ADD_BN_RELU = "fusion_deconv_add_bn_relu";
const
char
*
G_OP_TYPE_FUSION_DECONV_ADD_BN
=
"fusion_deconv_add_bn"
;
const
char
*
G_OP_TYPE_FUSION_DECONV_BN_RELU
=
"fusion_deconv_bn_relu"
;
const
char
*
G_OP_TYPE_PAD2D
=
"pad2d"
;
std
::
unordered_map
<
std
::
string
,
std
::
pair
<
std
::
vector
<
std
::
string
>
,
std
::
vector
<
std
::
string
>>>
op_input_output_key
=
{
...
...
src/framework/operator.h
浏览文件 @
5b229a61
...
...
@@ -15,7 +15,6 @@ limitations under the License. */
#pragma once
#include <map>
#include <memory>
#include <string>
#include <utility>
#include <vector>
...
...
@@ -81,7 +80,6 @@ class OperatorBase {
}
#ifdef PADDLE_MOBILE_FPGA
void
InsertTensors
();
void
ChangeNameMap
(
string
key
,
std
::
vector
<
string
>
value
);
#endif
protected:
...
...
@@ -98,35 +96,15 @@ class OperatorBase {
template
<
typename
Dtype
,
typename
ParamType
,
typename
KernelType
>
class
OperatorWithKernel
:
public
OperatorBase
<
Dtype
>
{
public:
#ifndef PADDLE_MOBILE_FPGA1
OperatorWithKernel
(
const
std
::
string
&
type
,
const
VariableNameMap
&
inputs
,
const
VariableNameMap
&
outputs
,
const
AttributeMap
&
attrs
,
framework
::
Scope
*
scope
)
:
OperatorBase
<
Dtype
>
(
type
,
inputs
,
outputs
,
attrs
,
scope
),
param_
(
inputs
,
outputs
,
attrs
,
scope
.
get
()
)
{
param_
(
inputs
,
outputs
,
attrs
,
scope
)
{
#ifdef PADDLE_MOBILE_CL
kernel_
.
InitCLHelper
(
scope
->
GetCLScpoe
());
#endif
}
#else
OperatorWithKernel
(
const
std
::
string
&
type
,
const
VariableNameMap
inputs
,
const
VariableNameMap
&
outputs
,
const
AttributeMap
&
attrs
,
std
::
shared_ptr
<
Scope
>
scope
)
:
OperatorBase
<
Dtype
>
(
type
,
inputs
,
outputs
,
attrs
,
scope
)
{
static
int
feed_num
=
0
;
static
int
fetch_num
=
0
;
if
(
type
==
"feed"
)
{
auto
new_name
=
string
(
"feed"
)
+
std
::
to_string
(
feed_num
++
);
auto
var
=
scope
->
Var
(
new_name
);
(
const_cast
<
VariableNameMap
&>
(
inputs
)).
at
(
"X"
)
=
{
string
(
new_name
)};
}
else
if
(
type
==
"fetch"
)
{
auto
new_name
=
string
(
"fetch"
)
+
std
::
to_string
(
fetch_num
++
);
auto
var
=
scope
->
Var
(
new_name
);
(
const_cast
<
VariableNameMap
&>
(
outputs
)).
at
(
"Out"
)
=
{
string
(
new_name
)};
}
param_
=
ParamType
(
inputs
,
outputs
,
attrs
,
*
scope
);
}
#endif
virtual
void
RunImpl
()
{
this
->
kernel_
.
Compute
(
this
->
param_
);
}
virtual
void
InferShape
()
const
=
0
;
...
...
src/operators/fill_constant_op.h
浏览文件 @
5b229a61
...
...
@@ -34,7 +34,7 @@ class FillConstantOp : public framework::OperatorBase<DeviceType> {
const
framework
::
AttributeMap
attrs
,
framework
::
Scope
*
scope
)
:
framework
::
OperatorBase
<
DeviceType
>
(
type
,
inputs
,
outputs
,
attrs
,
scope
),
param_
(
inputs
,
outputs
,
attrs
,
scope
.
get
()
)
{}
param_
(
inputs
,
outputs
,
attrs
,
scope
)
{}
void
RunImpl
()
{
auto
data_type
=
static_cast
<
_PaddleMobile__Framework__Proto__VarType__Type
>
(
...
...
src/operators/kernel/arm/conv_kernel.cpp
已删除
100644 → 0
浏览文件 @
82f57756
/* 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 CONV_OP
#include "operators/kernel/conv_kernel.h"
#include "operators/kernel/central-arm-func/conv_arm_func.h"
namespace
paddle_mobile
{
namespace
operators
{
template
<
>
bool
ConvKernel
<
CPU
,
float
>::
Init
(
ConvParam
<
CPU
>
*
param
)
{
bool
conv3x3
=
param
->
Filter
()
->
dims
()[
2
]
==
param
->
Filter
()
->
dims
()[
3
]
&&
param
->
Filter
()
->
dims
()[
2
]
==
3
;
bool
conv5x5
=
param
->
Filter
()
->
dims
()[
2
]
==
param
->
Filter
()
->
dims
()[
3
]
&&
param
->
Filter
()
->
dims
()[
2
]
==
5
;
bool
depth3x3
=
conv3x3
&&
param
->
Groups
()
==
param
->
Input
()
->
dims
()[
1
]
&&
param
->
Input
()
->
dims
()[
1
]
==
param
->
Output
()
->
dims
()[
1
];
bool
depth5x5
=
conv5x5
&&
param
->
Groups
()
==
param
->
Input
()
->
dims
()[
1
]
&&
param
->
Input
()
->
dims
()[
1
]
==
param
->
Output
()
->
dims
()[
1
];
if
(
param
->
Filter
()
->
type
()
==
typeid
(
int8_t
))
{
#ifndef __aarch64__
if
(
depth3x3
&&
param
->
Strides
()[
0
]
<
3
&&
param
->
Strides
()[
0
]
==
param
->
Strides
()[
1
])
{
param
->
ExecMode
()
=
ConvParam
<
CPU
>::
EXEC_DEPTHWISE3x3_INT8
;
}
else
if
(
depth5x5
&&
param
->
Strides
()[
0
]
<
2
&&
param
->
Strides
()[
0
]
==
param
->
Strides
()[
1
])
{
param
->
ExecMode
()
=
ConvParam
<
CPU
>::
EXEC_DEPTHWISE5x5_INT8
;
}
else
{
#endif // __aarch64__
param
->
ExecMode
()
=
ConvParam
<
CPU
>::
EXEC_GEMM_INT8
;
#ifndef __aarch64__
}
#endif // __aarch64__
}
else
{
if
(
depth3x3
&&
param
->
Strides
()[
0
]
==
param
->
Strides
()[
1
]
&&
param
->
Strides
()[
0
]
==
1
&&
param
->
Paddings
()[
0
]
==
1
&&
param
->
Paddings
()[
0
]
==
param
->
Paddings
()[
1
])
{
param
->
ExecMode
()
=
ConvParam
<
CPU
>::
EXEC_DEPTHWISE3x3S1P1_FLOAT
;
}
else
if
(
depth3x3
&&
param
->
Strides
()[
0
]
==
param
->
Strides
()[
1
]
&&
param
->
Strides
()[
0
]
==
2
&&
param
->
Paddings
()[
0
]
==
0
&&
param
->
Paddings
()[
0
]
==
param
->
Paddings
()[
1
])
{
param
->
ExecMode
()
=
ConvParam
<
CPU
>::
EXEC_DEPTHWISE3x3S2P0_FLOAT
;
}
else
if
(
depth3x3
&&
param
->
Strides
()[
0
]
==
param
->
Strides
()[
1
]
&&
param
->
Strides
()[
0
]
==
2
&&
param
->
Paddings
()[
0
]
==
1
&&
param
->
Paddings
()[
0
]
==
param
->
Paddings
()[
1
])
{
param
->
ExecMode
()
=
ConvParam
<
CPU
>::
EXEC_DEPTHWISE3x3S2P1_FLOAT
;
}
else
if
(
depth3x3
)
{
param
->
ExecMode
()
=
ConvParam
<
CPU
>::
EXEC_DEPTHWISE3x3_FLOAT
;
#ifndef __aarch64__
}
else
if
(
depth5x5
&&
param
->
Strides
()[
0
]
==
param
->
Strides
()[
1
]
&&
param
->
Strides
()[
0
]
==
1
)
{
param
->
ExecMode
()
=
ConvParam
<
CPU
>::
EXEC_DEPTHWISE5x5_FLOAT
;
}
else
if
(
conv3x3
&&
param
->
Strides
()[
0
]
==
param
->
Strides
()[
1
]
&&
param
->
Dilations
()[
0
]
==
param
->
Dilations
()[
1
]
&&
param
->
Strides
()[
0
]
==
1
&&
param
->
Dilations
()[
0
]
==
1
&&
param
->
Output
()
->
dims
()[
1
]
>=
16
&&
param
->
Input
()
->
dims
()[
1
]
>=
16
&&
param
->
Input
()
->
dims
()[
2
]
<=
140
/* refered from ncnn */
)
{
param
->
ExecMode
()
=
ConvParam
<
CPU
>::
EXEC_WINOGRAD3X3_FLOAT
;
// transform weight
param
->
transformed_filter_
=
new
framework
::
Tensor
;
operators
::
math
::
winograd_transform_weight
<
8
,
3
>
(
*
param
->
Filter
(),
param
->
transformed_filter_
);
#endif
}
else
{
param
->
ExecMode
()
=
ConvParam
<
CPU
>::
EXEC_GEMM_FLOAT
;
}
}
return
true
;
}
template
<
>
void
ConvKernel
<
CPU
,
float
>::
Compute
(
const
ConvParam
<
CPU
>
&
param
)
{
switch
(
param
.
ExecMode
())
{
case
ConvParam
<
CPU
>::
EXEC_GEMM_INT8
:
GemmConv
<
int8_t
,
int32_t
>
(
param
);
break
;
#ifndef __aarch64__
case
ConvParam
<
CPU
>::
EXEC_DEPTHWISE3x3_INT8
:
DepthwiseConv3x3
<
int8_t
,
int32_t
>
(
param
);
break
;
case
ConvParam
<
CPU
>::
EXEC_DEPTHWISE5x5_INT8
:
DepthwiseConv5x5
<
int8_t
,
int32_t
>
(
param
);
break
;
#endif // __aarch64__
case
ConvParam
<
CPU
>::
EXEC_DEPTHWISE3x3S1P1_FLOAT
:
math
::
DepthwiseConv3x3s1p1
(
param
.
Input
(),
param
.
Filter
(),
param
.
Output
(),
nullptr
,
false
,
false
);
break
;
case
ConvParam
<
CPU
>::
EXEC_DEPTHWISE3x3S2P1_FLOAT
:
math
::
DepthwiseConv3x3s2p1v2
(
param
.
Input
(),
param
.
Filter
(),
param
.
Output
(),
nullptr
,
false
,
false
);
break
;
case
ConvParam
<
CPU
>::
EXEC_DEPTHWISE3x3S2P0_FLOAT
:
math
::
DepthwiseConv3x3s2p0
(
param
.
Input
(),
param
.
Filter
(),
param
.
Output
(),
nullptr
,
false
,
false
);
break
;
case
ConvParam
<
CPU
>::
EXEC_DEPTHWISE3x3_FLOAT
:
math
::
DepthwiseConv3x3
(
param
.
Input
(),
param
.
Strides
(),
param
.
Paddings
(),
param
.
Filter
(),
nullptr
,
param
.
Output
(),
false
);
break
;
#ifndef __aarch64__
case
ConvParam
<
CPU
>::
EXEC_DEPTHWISE5x5_FLOAT
:
DepthwiseConv5x5
<
float
,
float
>
(
param
);
break
;
case
ConvParam
<
CPU
>::
EXEC_WINOGRAD3X3_FLOAT
:
WinogradConv3x3
<
8
,
3
>
(
param
);
break
;
#endif // __aarch64__
case
ConvParam
<
CPU
>::
EXEC_GEMM_FLOAT
:
GemmConv
<
float
,
float
>
(
param
);
break
;
default:
PADDLE_MOBILE_THROW_EXCEPTION
(
"Invalid convolution execute mode %d"
,
param
.
ExecMode
());
}
}
template
class
ConvKernel
<
CPU
,
float
>;
}
// namespace operators
}
// namespace paddle_mobile
#endif
src/operators/kernel/arm/convolution/conv_add_bn_relu_kernel.cpp
浏览文件 @
5b229a61
...
...
@@ -45,8 +45,8 @@ bool ConvAddBNReluKernel<CPU, float>::Init(
}
// Tensor *new_scale = new Tensor();
// Tensor *new_bias = new Tensor();
Tensor
*
new_scale
=
param
->
CreateNewScale
<
Tensor
>
();
Tensor
*
new_bias
=
param
->
CreateNewBiase
<
Tensor
>
();
auto
*
new_scale
=
param
->
CreateNewScale
<
framework
::
LoD
Tensor
>
();
auto
*
new_bias
=
param
->
CreateNewBiase
<
framework
::
LoD
Tensor
>
();
auto
new_scale_ptr
=
new_scale
->
mutable_data
<
float
>
({
C
});
auto
new_bias_ptr
=
new_bias
->
mutable_data
<
float
>
({
C
});
...
...
src/operators/kernel/arm/convolution/conv_bn_add_relu_kernel.cpp
浏览文件 @
5b229a61
...
...
@@ -43,8 +43,9 @@ bool ConvBNAddReluKernel<CPU, float>::Init(
inv_std_ptr
[
i
]
=
1
/
static_cast
<
float
>
(
pow
((
variance_ptr
[
i
]
+
epsilon
),
0.5
));
}
LoDTensor
*
new_scale
=
new
LoDTensor
();
LoDTensor
*
new_bias
=
new
LoDTensor
();
auto
*
new_scale
=
param
->
CreateNewScale
<
framework
::
LoDTensor
>
();
auto
*
new_bias
=
param
->
CreateNewBiase
<
framework
::
LoDTensor
>
();
auto
new_scale_ptr
=
new_scale
->
mutable_data
<
float
>
({
C
});
auto
new_bias_ptr
=
new_bias
->
mutable_data
<
float
>
({
C
});
for
(
int
i
=
0
;
i
<
C
;
i
++
)
{
...
...
src/operators/kernel/arm/convolution/conv_bn_relu_kernel.cpp
浏览文件 @
5b229a61
...
...
@@ -43,8 +43,8 @@ bool ConvBNReluKernel<CPU, float>::Init(FusionConvBNReluParam<CPU> *param) {
1
/
static_cast
<
float
>
(
pow
((
variance_ptr
[
i
]
+
epsilon
),
0.5
));
}
Tensor
*
new_scale
=
param
->
CreateNewScale
<
Tensor
>
();
Tensor
*
new_bias
=
param
->
CreateNewBiase
<
Tensor
>
();
auto
*
new_scale
=
param
->
CreateNewScale
<
framework
::
LoD
Tensor
>
();
auto
*
new_bias
=
param
->
CreateNewBiase
<
framework
::
LoD
Tensor
>
();
auto
new_scale_ptr
=
new_scale
->
mutable_data
<
float
>
({
C
});
auto
new_bias_ptr
=
new_bias
->
mutable_data
<
float
>
({
C
});
for
(
int
i
=
0
;
i
<
C
;
i
++
)
{
...
...
src/operators/kernel/beam_search_decode_kernel.h
浏览文件 @
5b229a61
...
...
@@ -27,15 +27,16 @@ class BeamSearchDecodeParam : public OpParam {
public:
BeamSearchDecodeParam
(
const
VariableNameMap
&
inputs
,
const
VariableNameMap
&
outputs
,
const
AttributeMap
&
attrs
,
const
Scope
&
scope
)
{
const
AttributeMap
&
attrs
,
Scope
*
scope
)
:
OpParam
(
inputs
,
outputs
,
attrs
,
scope
)
{
ids_
=
OpParam
::
GetVarValue
<
framework
::
LoDTensorArray
>
(
"Ids"
,
inputs
,
scope
);
OpParam
::
GetVarValue
<
framework
::
LoDTensorArray
>
(
"Ids"
,
inputs
,
*
scope
);
scores_
=
OpParam
::
GetVarValue
<
framework
::
LoDTensorArray
>
(
"Scores"
,
inputs
,
scope
);
*
scope
);
sentence_ids_
=
OpParam
::
GetVarValue
<
framework
::
LoDTensor
>
(
"SentenceIds"
,
outputs
,
scope
);
outputs
,
*
scope
);
sentence_scores_
=
OpParam
::
GetVarValue
<
framework
::
LoDTensor
>
(
"SentenceScores"
,
outputs
,
scope
);
"SentenceScores"
,
outputs
,
*
scope
);
beam_size_
=
OpParam
::
GetAttr
<
int
>
(
"beam_size"
,
attrs
);
end_id_
=
OpParam
::
GetAttr
<
int
>
(
"end_id"
,
attrs
);
}
...
...
src/operators/kernel/beam_search_kernel.h
浏览文件 @
5b229a61
...
...
@@ -29,16 +29,18 @@ template <typename Dtype>
class
BeamSearchParam
:
public
OpParam
{
public:
BeamSearchParam
(
const
VariableNameMap
&
inputs
,
const
VariableNameMap
&
outputs
,
const
AttributeMap
&
attrs
,
const
Scope
&
scope
)
{
pre_ids_
=
GET_VAR_AS_LOD_TENSOR
(
"pre_ids"
,
inputs
,
scope
);
pre_scores_
=
GET_VAR_AS_LOD_TENSOR
(
"pre_scores"
,
inputs
,
scope
);
ids_
=
GET_VAR_AS_LOD_TENSOR
(
"ids"
,
inputs
,
scope
);
scores_
=
GET_VAR_AS_LOD_TENSOR
(
"scores"
,
inputs
,
scope
);
selected_ids_
=
GET_VAR_AS_LOD_TENSOR
(
"selected_ids"
,
outputs
,
scope
);
selected_scores_
=
GET_VAR_AS_LOD_TENSOR
(
"selected_scores"
,
outputs
,
scope
);
const
AttributeMap
&
attrs
,
Scope
*
scope
)
:
OpParam
(
inputs
,
outputs
,
attrs
,
scope
)
{
pre_ids_
=
GET_VAR_AS_LOD_TENSOR
(
"pre_ids"
,
inputs
,
*
scope
);
pre_scores_
=
GET_VAR_AS_LOD_TENSOR
(
"pre_scores"
,
inputs
,
*
scope
);
ids_
=
GET_VAR_AS_LOD_TENSOR
(
"ids"
,
inputs
,
*
scope
);
scores_
=
GET_VAR_AS_LOD_TENSOR
(
"scores"
,
inputs
,
*
scope
);
selected_ids_
=
GET_VAR_AS_LOD_TENSOR
(
"selected_ids"
,
outputs
,
*
scope
);
selected_scores_
=
GET_VAR_AS_LOD_TENSOR
(
"selected_scores"
,
outputs
,
*
scope
);
if
(
outputs
.
count
(
"parent_idx"
))
{
parent_idx_
=
GET_VAR_AS_LOD_TENSOR
(
"parent_idx"
,
outputs
,
scope
);
parent_idx_
=
GET_VAR_AS_LOD_TENSOR
(
"parent_idx"
,
outputs
,
*
scope
);
}
else
{
parent_idx_
=
new
framework
::
Tensor
();
}
...
...
src/operators/kernel/one_hot_kernel.h
浏览文件 @
5b229a61
...
...
@@ -29,9 +29,10 @@ template <typename Dtype>
class
OnehotParam
:
public
OpParam
{
public:
OnehotParam
(
const
VariableNameMap
&
inputs
,
const
VariableNameMap
&
outputs
,
const
AttributeMap
&
attrs
,
const
Scope
&
scope
)
{
input_
=
GET_VAR_AS_LOD_TENSOR
(
"X"
,
inputs
,
scope
);
output_
=
GET_VAR_AS_LOD_TENSOR
(
"Out"
,
outputs
,
scope
);
const
AttributeMap
&
attrs
,
Scope
*
scope
)
:
OpParam
(
inputs
,
outputs
,
attrs
,
scope
)
{
input_
=
GET_VAR_AS_LOD_TENSOR
(
"X"
,
inputs
,
*
scope
);
output_
=
GET_VAR_AS_LOD_TENSOR
(
"Out"
,
outputs
,
*
scope
);
depth_
=
OpParam
::
GetAttr
<
int
>
(
"depth"
,
attrs
);
dtype_
=
OpParam
::
GetAttr
<
int
>
(
"dtype"
,
attrs
);
...
...
src/operators/kernel/pad2d_kernel.h
浏览文件 @
5b229a61
...
...
@@ -28,9 +28,11 @@ 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
);
const
AttributeMap
&
attrs
,
Scope
*
scope
)
:
OpParam
(
inputs
,
outputs
,
attrs
,
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
);
...
...
src/operators/kernel/while_kernel.h
浏览文件 @
5b229a61
...
...
@@ -26,13 +26,10 @@ class WhileParam : public OpParam {
public:
WhileParam
(
const
VariableNameMap
&
inputs
,
const
VariableNameMap
&
outputs
,
const
AttributeMap
&
attrs
,
Scope
*
scope
)
:
inputs_
(
inputs
),
outputs_
(
outputs
),
scope_
(
*
scope
),
OpParam
(
inputs
,
outputs
,
attrs
,
scope
)
{
:
scope_
(
scope
),
OpParam
(
inputs
,
outputs
,
attrs
,
scope
)
{
cond_
=
OpParam
::
GetVarValue
<
framework
::
LoDTensor
>
(
"Condition"
,
inputs
,
*
scope
);
sub_block_
=
OpParam
::
GetAttr
<
int
>
(
"sub_block"
,
attrs
);
sub_block_
=
OpParam
::
GetAttr
<
framework
::
BlockDesc
*
>
(
"sub_block"
,
attrs
);
}
public:
...
...
src/operators/op_param.h
浏览文件 @
5b229a61
...
...
@@ -1222,12 +1222,12 @@ class FeedParam : public OpParam {
public:
FeedParam
(
const
VariableNameMap
&
inputs
,
const
VariableNameMap
&
outputs
,
const
AttributeMap
&
attrs
,
const
Scope
&
scope
)
const
AttributeMap
&
attrs
,
Scope
*
scope
)
:
OpParam
(
inputs
,
outputs
,
attrs
,
scope
)
{
input_x_
=
InputXFrom
<
framework
::
LoDTensorArray
>
(
inputs
,
scope
);
out_
=
OutFrom
<
GType
>
(
outputs
,
scope
);
input_x_
=
InputXFrom
<
framework
::
LoDTensorArray
>
(
inputs
,
*
scope
);
out_
=
OutFrom
<
GType
>
(
outputs
,
*
scope
);
col_
=
GetAttr
<
int
>
(
"col"
,
attrs
);
auto
var
=
scope
.
FindVar
(
"batch_size"
);
auto
var
=
scope
->
FindVar
(
"batch_size"
);
batch_size
=
var
->
GetValue
<
int
>
();
}
const
framework
::
LoDTensorArray
*
InputX
()
const
{
return
input_x_
;
}
...
...
@@ -1249,10 +1249,10 @@ class FetchParam : public OpParam {
public:
FetchParam
(
const
VariableNameMap
&
inputs
,
const
VariableNameMap
&
outputs
,
const
AttributeMap
&
attrs
,
const
Scope
&
scope
)
const
AttributeMap
&
attrs
,
Scope
*
scope
)
:
OpParam
(
inputs
,
outputs
,
attrs
,
scope
)
{
input_x_
=
InputXFrom
<
framework
::
LoDTensor
>
(
inputs
,
scope
);
out_
=
OutFrom
<
framework
::
LoDTensorArray
>
(
outputs
,
scope
);
input_x_
=
InputXFrom
<
framework
::
LoDTensor
>
(
inputs
,
*
scope
);
out_
=
OutFrom
<
framework
::
LoDTensorArray
>
(
outputs
,
*
scope
);
col_
=
GetAttr
<
int
>
(
"col"
,
attrs
);
}
...
...
@@ -1821,7 +1821,7 @@ class FusionConvAddParam : public ConvParam<Dtype> {
:
ConvParam
<
Dtype
>
(
inputs
,
outputs
,
attrs
,
scope
)
{
bias_
=
OpParam
::
InputYFrom
<
GType
>
(
inputs
,
*
scope
);
axis_
=
OpParam
::
GetAttr
<
int
>
(
"axis"
,
attrs
);
this
->
output_
=
OpParam
::
OutFrom
<
GType
>
(
outputs
,
scope
);
this
->
output_
=
OpParam
::
OutFrom
<
GType
>
(
outputs
,
*
scope
);
}
GType
*
Bias
()
const
{
return
bias_
;
}
...
...
@@ -1862,7 +1862,7 @@ class FusionConvAddPReluParam : public ConvParam<Dtype> {
framework
::
DDim
dims
=
alpha_
->
dims
();
bias_
=
OpParam
::
InputYFrom
<
GType
>
(
inputs
,
*
scope
);
axis_
=
OpParam
::
GetAttr
<
int
>
(
"axis"
,
attrs
);
this
->
output_
=
OpParam
::
OutFrom
<
GType
>
(
outputs
,
scope
);
this
->
output_
=
OpParam
::
OutFrom
<
GType
>
(
outputs
,
*
scope
);
}
const
GType
*
InputAlpha
()
const
{
return
alpha_
;
}
const
std
::
string
&
Mode
()
const
{
return
mode_
;
}
...
...
@@ -1892,7 +1892,7 @@ class FusionConvAddAddPReluParam : public ConvParam<Dtype> {
alpha_
=
OpParam
::
InputAlphaFrom
<
GType
>
(
inputs
,
*
scope
);
mode_
=
OpParam
::
GetStringAttr
(
"mode"
,
attrs
);
framework
::
DDim
dims
=
alpha_
->
dims
();
bias_
=
OpParam
::
InputYFrom
<
GType
>
(
inputs
,
scope
);
bias_
=
OpParam
::
InputYFrom
<
GType
>
(
inputs
,
*
scope
);
axis_
=
OpParam
::
GetAttr
<
int
>
(
"axis"
,
attrs
);
keyOutput_
=
OpParam
::
Getkey
(
"addOut"
,
inputs
,
0
);
keyX1_
=
OpParam
::
Getkey
(
"addX"
,
inputs
,
1
);
...
...
@@ -1902,7 +1902,7 @@ class FusionConvAddAddPReluParam : public ConvParam<Dtype> {
}
else
if
(
keyY1_
==
keyOutput_
)
{
bias1_
=
OpParam
::
InputXFrom1
<
GType
>
(
inputs
,
*
scope
);
}
this
->
output_
=
OpParam
::
OutFrom
<
GType
>
(
outputs
,
scope
);
this
->
output_
=
OpParam
::
OutFrom
<
GType
>
(
outputs
,
*
scope
);
}
const
GType
*
InputAlpha
()
const
{
return
alpha_
;
}
const
std
::
string
&
Mode
()
const
{
return
mode_
;
}
...
...
@@ -1937,13 +1937,13 @@ class FusionConvAddBNReluParam : public ConvParam<Dtype> {
:
ConvParam
<
Dtype
>
(
inputs
,
outputs
,
attrs
,
scope
)
{
bias_
=
OpParam
::
InputYFrom
<
GType
>
(
inputs
,
*
scope
);
axis_
=
OpParam
::
GetAttr
<
int
>
(
"axis"
,
attrs
);
input_bias_
=
OpParam
::
InputBiasFrom
<
GType
>
(
inputs
,
scope
);
input_mean_
=
OpParam
::
InputMeanFrom
<
GType
>
(
inputs
,
scope
);
input_scale_
=
OpParam
::
InputScaleFrom
<
GType
>
(
inputs
,
scope
);
input_variance_
=
OpParam
::
InputVarianceFrom
<
GType
>
(
inputs
,
scope
);
input_bias_
=
OpParam
::
InputBiasFrom
<
GType
>
(
inputs
,
*
scope
);
input_mean_
=
OpParam
::
InputMeanFrom
<
GType
>
(
inputs
,
*
scope
);
input_scale_
=
OpParam
::
InputScaleFrom
<
GType
>
(
inputs
,
*
scope
);
input_variance_
=
OpParam
::
InputVarianceFrom
<
GType
>
(
inputs
,
*
scope
);
epsilon_
=
OpParam
::
GetAttr
<
float
>
(
"epsilon"
,
attrs
);
momentum_
=
OpParam
::
GetAttr
<
float
>
(
"momentum"
,
attrs
);
this
->
output_
=
OpParam
::
OutFrom
<
GType
>
(
outputs
,
scope
);
this
->
output_
=
OpParam
::
OutFrom
<
GType
>
(
outputs
,
*
scope
);
}
GType
*
Bias
()
const
{
return
bias_
;
}
...
...
@@ -1996,10 +1996,10 @@ class FusionConvBNAddReluParam : public ConvParam<Dtype> {
:
ConvParam
<
Dtype
>
(
inputs
,
outputs
,
attrs
,
scope
)
{
bias_
=
OpParam
::
InputYFrom
<
GType
>
(
inputs
,
*
scope
);
axis_
=
OpParam
::
GetAttr
<
int
>
(
"axis"
,
attrs
);
input_bias_
=
OpParam
::
InputBiasFrom
<
GType
>
(
inputs
,
scope
);
input_mean_
=
OpParam
::
InputMeanFrom
<
GType
>
(
inputs
,
scope
);
input_scale_
=
OpParam
::
InputScaleFrom
<
GType
>
(
inputs
,
scope
);
input_variance_
=
OpParam
::
InputVarianceFrom
<
GType
>
(
inputs
,
scope
);
input_bias_
=
OpParam
::
InputBiasFrom
<
GType
>
(
inputs
,
*
scope
);
input_mean_
=
OpParam
::
InputMeanFrom
<
GType
>
(
inputs
,
*
scope
);
input_scale_
=
OpParam
::
InputScaleFrom
<
GType
>
(
inputs
,
*
scope
);
input_variance_
=
OpParam
::
InputVarianceFrom
<
GType
>
(
inputs
,
*
scope
);
epsilon_
=
OpParam
::
GetAttr
<
float
>
(
"epsilon"
,
attrs
);
momentum_
=
OpParam
::
GetAttr
<
float
>
(
"momentum"
,
attrs
);
keyBNY_
=
OpParam
::
Getkey
(
"BNY"
,
inputs
,
0
);
...
...
@@ -2010,7 +2010,7 @@ class FusionConvBNAddReluParam : public ConvParam<Dtype> {
}
else
if
(
keyY_
==
keyBNY_
)
{
bias_
=
OpParam
::
InputXFrom
<
GType
>
(
inputs
,
*
scope
);
}
this
->
output_
=
OpParam
::
OutFrom
<
GType
>
(
outputs
,
scope
);
this
->
output_
=
OpParam
::
OutFrom
<
GType
>
(
outputs
,
*
scope
);
}
GType
*
Bias
()
const
{
return
bias_
;
}
...
...
@@ -2064,13 +2064,13 @@ class FusionConvBNParam : public ConvParam<Dtype> {
const
VariableNameMap
&
outputs
,
const
AttributeMap
&
attrs
,
Scope
*
scope
)
:
ConvParam
<
Dtype
>
(
inputs
,
outputs
,
attrs
,
scope
)
{
input_bias_
=
OpParam
::
InputBiasFrom
<
GType
>
(
inputs
,
scope
);
input_mean_
=
OpParam
::
InputMeanFrom
<
GType
>
(
inputs
,
scope
);
input_scale_
=
OpParam
::
InputScaleFrom
<
GType
>
(
inputs
,
scope
);
input_variance_
=
OpParam
::
InputVarianceFrom
<
GType
>
(
inputs
,
scope
);
input_bias_
=
OpParam
::
InputBiasFrom
<
GType
>
(
inputs
,
*
scope
);
input_mean_
=
OpParam
::
InputMeanFrom
<
GType
>
(
inputs
,
*
scope
);
input_scale_
=
OpParam
::
InputScaleFrom
<
GType
>
(
inputs
,
*
scope
);
input_variance_
=
OpParam
::
InputVarianceFrom
<
GType
>
(
inputs
,
*
scope
);
epsilon_
=
OpParam
::
GetAttr
<
float
>
(
"epsilon"
,
attrs
);
momentum_
=
OpParam
::
GetAttr
<
float
>
(
"momentum"
,
attrs
);
this
->
output_
=
OpParam
::
OutputYFrom
<
GType
>
(
outputs
,
scope
);
this
->
output_
=
OpParam
::
OutputYFrom
<
GType
>
(
outputs
,
*
scope
);
}
const
GType
*
InputBias
()
const
{
return
input_bias_
;
}
...
...
@@ -2118,13 +2118,13 @@ class FusionConvAddBNParam : public ConvParam<Dtype> {
:
ConvParam
<
Dtype
>
(
inputs
,
outputs
,
attrs
,
scope
)
{
bias_
=
OpParam
::
InputYFrom
<
GType
>
(
inputs
,
*
scope
);
axis_
=
OpParam
::
GetAttr
<
int
>
(
"axis"
,
attrs
);
input_bias_
=
OpParam
::
InputBiasFrom
<
GType
>
(
inputs
,
scope
);
input_mean_
=
OpParam
::
InputMeanFrom
<
GType
>
(
inputs
,
scope
);
input_scale_
=
OpParam
::
InputScaleFrom
<
GType
>
(
inputs
,
scope
);
input_variance_
=
OpParam
::
InputVarianceFrom
<
GType
>
(
inputs
,
scope
);
input_bias_
=
OpParam
::
InputBiasFrom
<
GType
>
(
inputs
,
*
scope
);
input_mean_
=
OpParam
::
InputMeanFrom
<
GType
>
(
inputs
,
*
scope
);
input_scale_
=
OpParam
::
InputScaleFrom
<
GType
>
(
inputs
,
*
scope
);
input_variance_
=
OpParam
::
InputVarianceFrom
<
GType
>
(
inputs
,
*
scope
);
epsilon_
=
OpParam
::
GetAttr
<
float
>
(
"epsilon"
,
attrs
);
momentum_
=
OpParam
::
GetAttr
<
float
>
(
"momentum"
,
attrs
);
this
->
output_
=
OpParam
::
OutputYFrom
<
GType
>
(
outputs
,
scope
);
this
->
output_
=
OpParam
::
OutputYFrom
<
GType
>
(
outputs
,
*
scope
);
}
GType
*
Bias
()
const
{
return
bias_
;
}
...
...
@@ -2175,13 +2175,13 @@ class FusionDWConvBNReluParam : public ConvParam<Dtype> {
const
VariableNameMap
&
outputs
,
const
AttributeMap
&
attrs
,
Scope
*
scope
)
:
ConvParam
<
Dtype
>
(
inputs
,
outputs
,
attrs
,
scope
)
{
input_bias_
=
OpParam
::
InputBiasFrom
<
GType
>
(
inputs
,
scope
);
input_mean_
=
OpParam
::
InputMeanFrom
<
GType
>
(
inputs
,
scope
);
input_scale_
=
OpParam
::
InputScaleFrom
<
GType
>
(
inputs
,
scope
);
input_variance_
=
OpParam
::
InputVarianceFrom
<
GType
>
(
inputs
,
scope
);
input_bias_
=
OpParam
::
InputBiasFrom
<
GType
>
(
inputs
,
*
scope
);
input_mean_
=
OpParam
::
InputMeanFrom
<
GType
>
(
inputs
,
*
scope
);
input_scale_
=
OpParam
::
InputScaleFrom
<
GType
>
(
inputs
,
*
scope
);
input_variance_
=
OpParam
::
InputVarianceFrom
<
GType
>
(
inputs
,
*
scope
);
epsilon_
=
OpParam
::
GetAttr
<
float
>
(
"epsilon"
,
attrs
);
momentum_
=
OpParam
::
GetAttr
<
float
>
(
"momentum"
,
attrs
);
this
->
output_
=
OpParam
::
OutFrom
<
GType
>
(
outputs
,
scope
);
this
->
output_
=
OpParam
::
OutFrom
<
GType
>
(
outputs
,
*
scope
);
}
const
GType
*
InputBias
()
const
{
return
input_bias_
;
}
...
...
@@ -2228,13 +2228,13 @@ class FusionConvBNReluParam : public ConvParam<Dtype> {
const
VariableNameMap
&
outputs
,
const
AttributeMap
&
attrs
,
Scope
*
scope
)
:
ConvParam
<
Dtype
>
(
inputs
,
outputs
,
attrs
,
scope
)
{
input_bias_
=
OpParam
::
InputBiasFrom
<
GType
>
(
inputs
,
scope
);
input_mean_
=
OpParam
::
InputMeanFrom
<
GType
>
(
inputs
,
scope
);
input_scale_
=
OpParam
::
InputScaleFrom
<
GType
>
(
inputs
,
scope
);
input_variance_
=
OpParam
::
InputVarianceFrom
<
GType
>
(
inputs
,
scope
);
input_bias_
=
OpParam
::
InputBiasFrom
<
GType
>
(
inputs
,
*
scope
);
input_mean_
=
OpParam
::
InputMeanFrom
<
GType
>
(
inputs
,
*
scope
);
input_scale_
=
OpParam
::
InputScaleFrom
<
GType
>
(
inputs
,
*
scope
);
input_variance_
=
OpParam
::
InputVarianceFrom
<
GType
>
(
inputs
,
*
scope
);
epsilon_
=
OpParam
::
GetAttr
<
float
>
(
"epsilon"
,
attrs
);
momentum_
=
OpParam
::
GetAttr
<
float
>
(
"momentum"
,
attrs
);
this
->
output_
=
OpParam
::
OutFrom
<
GType
>
(
outputs
,
scope
);
this
->
output_
=
OpParam
::
OutFrom
<
GType
>
(
outputs
,
*
scope
);
}
const
GType
*
InputBias
()
const
{
return
input_bias_
;
}
...
...
@@ -3285,10 +3285,10 @@ class IncrementParam : public OpParam {
public:
IncrementParam
(
const
VariableNameMap
&
inputs
,
const
VariableNameMap
&
outputs
,
const
AttributeMap
&
attrs
,
const
Scope
&
scope
)
const
AttributeMap
&
attrs
,
Scope
*
scope
)
:
OpParam
(
inputs
,
outputs
,
attrs
,
scope
)
{
input_x_
=
InputXFrom
<
GType
>
(
inputs
,
scope
);
output_
=
OutFrom
<
GType
>
(
outputs
,
scope
);
input_x_
=
InputXFrom
<
GType
>
(
inputs
,
*
scope
);
output_
=
OutFrom
<
GType
>
(
outputs
,
*
scope
);
step_
=
OpParam
::
GetAttr
<
float
>
(
"step"
,
attrs
);
}
...
...
src/operators/pad2d.cpp
已删除
100644 → 0
浏览文件 @
82f57756
/* 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
已删除
100644 → 0
浏览文件 @
82f57756
/* 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
src/operators/pad2d_op.cpp
浏览文件 @
5b229a61
...
...
@@ -19,14 +19,15 @@ namespace paddle_mobile {
namespace
operators
{
template
<
typename
Dtype
,
typename
T
>
void
Pad2dOp
<
Dtype
,
T
>::
InferShape
()
const
{
auto
input_dims
=
this
->
param_
.
InputX
()
->
dims
();
auto
input_n
=
input_dims
[
0
];
auto
input_c
=
input_dims
[
1
];
auto
input_h
=
input_dims
[
2
];
auto
input_w
=
input_dims
[
3
];
this
->
param_
.
Out
()
->
Resize
({
input_n
,
input_c
,
input_h
+
1
,
input_w
+
1
});
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
...
...
@@ -34,10 +35,7 @@ void Pad2dOp<Dtype, T>::InferShape() const {
namespace
ops
=
paddle_mobile
::
operators
;
#ifdef PADDLE_MOBILE_CPU
REGISTER_OPERATOR_CPU
(
pad2d
,
ops
::
Pad2dOp
);
#endif
#ifdef PADDLE_MOBILE_FPGA
REGISTER_OPERATOR_FPGA
(
pad2d
,
ops
::
Pad2dOp
);
REGISTER_OPERATOR_CPU
(
pad2d
,
ops
::
Pad2DOp
);
#endif
#endif
#endif
// PAD2D_OP
src/operators/pad2d_op.h
浏览文件 @
5b229a61
...
...
@@ -17,33 +17,16 @@ limitations under the License. */
#pragma once
#include <string>
#include "framework/operator.h"
#include "operators/kernel/pad2d_kernel.h"
#include "operators/op_param.h"
namespace
paddle_mobile
{
namespace
operators
{
using
framework
::
AttributeMap
;
using
framework
::
OperatorWithKernel
;
using
framework
::
Scope
;
using
std
::
string
;
template
<
typename
DeviceType
,
typename
T
>
class
Pad2dOp
:
public
OperatorWithKernel
<
DeviceType
,
Pad2dParam
<
DeviceType
>
,
operators
::
Pad2dKernel
<
DeviceType
,
T
>>
{
public:
Pad2dOp
(
const
string
&
type
,
const
VariableNameMap
&
inputs
,
const
VariableNameMap
&
outputs
,
const
AttributeMap
&
attrs
,
std
::
shared_ptr
<
Scope
>
scope
)
:
OperatorWithKernel
<
DeviceType
,
Pad2dParam
<
DeviceType
>
,
operators
::
Pad2dKernel
<
DeviceType
,
T
>>
(
type
,
inputs
,
outputs
,
attrs
,
scope
)
{}
void
InferShape
()
const
override
;
private:
};
DECLARE_OPERATOR
(
Pad2D
,
Pad2DParam
,
Pad2DKernel
);
}
// namespace operators
}
// namespace paddle_mobile
#endif
#endif
// PAD2D_OP
test/net/test_ocr.cpp
浏览文件 @
5b229a61
...
...
@@ -20,11 +20,11 @@ limitations under the License. */
void
load_images
(
const
char
*
image_dir
,
const
char
*
images_list
,
std
::
vector
<
std
::
string
>
*
image_names
,
std
::
vector
<
std
::
pair
<
int
,
int
>>
*
image_shapes
)
{
int
height
,
width
;
int
channel
,
height
,
width
;
std
::
string
filename
;
std
::
ifstream
if_list
(
images_list
,
std
::
ios
::
in
);
while
(
!
if_list
.
eof
())
{
if_list
>>
height
>>
width
>>
filename
;
if_list
>>
channel
>>
height
>>
width
>>
filename
;
image_shapes
->
push_back
(
std
::
make_pair
(
height
,
width
));
image_names
->
push_back
(
filename
);
}
...
...
@@ -32,20 +32,25 @@ void load_images(const char *image_dir, const char *images_list,
}
int
main
(
int
argc
,
char
**
argv
)
{
if
(
argc
<
4
)
{
std
::
cerr
<<
"Usage: ./test_ocr model_dir image_dir images_list."
<<
std
::
endl
;
if
(
argc
<
5
)
{
std
::
cerr
<<
"Usage: ./test_ocr model_dir image_dir images_list output_name."
<<
std
::
endl
;
return
1
;
}
char
*
model_dir
=
argv
[
1
];
char
*
image_dir
=
argv
[
2
];
char
*
images_list
=
argv
[
3
];
char
*
output_name
=
argv
[
4
];
paddle_mobile
::
PaddleMobile
<
paddle_mobile
::
CPU
>
paddle_mobile
;
paddle_mobile
.
SetThreadNum
(
8
);
paddle_mobile
.
SetThreadNum
(
1
);
auto
isok
=
paddle_mobile
.
Load
(
std
::
string
(
model_dir
)
+
"/model"
,
std
::
string
(
model_dir
)
+
"/params"
,
true
,
false
,
1
,
true
);
// auto isok = paddle_mobile.Load(std::string(model_dir), false,
// false, 1, true);
DLOG
<<
"pass init model"
;
std
::
vector
<
std
::
string
>
image_names
;
std
::
vector
<
std
::
pair
<
int
,
int
>>
image_shapes
;
...
...
@@ -55,7 +60,7 @@ int main(int argc, char **argv) {
for
(
int
i
=
0
;
i
<
image_names
.
size
();
i
++
)
{
std
::
string
file_name
=
image_names
[
i
];
std
::
vector
<
float
>
input_vec
;
std
::
vector
<
int64_t
>
dims
{
1
,
1
,
48
,
512
};
std
::
vector
<
int64_t
>
dims
{
1
,
3
,
48
,
512
};
dims
[
2
]
=
image_shapes
[
i
].
first
;
dims
[
3
]
=
image_shapes
[
i
].
second
;
// load input image
...
...
@@ -64,23 +69,24 @@ int main(int argc, char **argv) {
std
::
cerr
<<
"shape = ["
<<
dims
[
0
]
<<
", "
<<
dims
[
1
]
<<
", "
<<
dims
[
2
]
<<
", "
<<
dims
[
3
]
<<
"]"
<<
std
::
endl
;
GetInput
<
float
>
(
img_path
,
&
input_vec
,
dims
);
framework
::
Tensor
input
(
input_vec
,
framework
::
make_ddim
(
dims
));
//
framework::Tensor input(input_vec, framework::make_ddim(dims));
// predict
paddle_mobile
.
Predict
(
input
);
auto
output_topk
=
paddle_mobile
.
Fetch
(
"top_k_1.tmp_0"
);
auto
output_indices
=
paddle_mobile
.
Fetch
(
"cast_68.tmp_0"
);
// for (int j = 0; j < 10000; ++j) {
auto
time3
=
paddle_mobile
::
time
();
paddle_mobile
.
Predict
(
input_vec
,
dims
);
auto
output_topk
=
paddle_mobile
.
Fetch
(
output_name
);
auto
time4
=
paddle_mobile
::
time
();
std
::
cerr
<<
"average predict elapsed: "
<<
paddle_mobile
::
time_diff
(
time3
,
time4
)
<<
"ms"
<<
std
::
endl
;
// }
// print result
std
::
cerr
<<
file
_name
<<
std
::
endl
;
std
::
cerr
<<
output
_name
<<
std
::
endl
;
std
::
cerr
<<
output_topk
->
data
<
float
>
()[
0
];
for
(
int
j
=
1
;
j
<
output_topk
->
numel
();
++
j
)
{
std
::
cerr
<<
" "
<<
output_topk
->
data
<
float
>
()[
j
];
}
std
::
cerr
<<
std
::
endl
;
std
::
cerr
<<
output_indices
->
data
<
float
>
()[
0
];
for
(
int
j
=
1
;
j
<
output_indices
->
numel
();
++
j
)
{
std
::
cerr
<<
" "
<<
output_indices
->
data
<
float
>
()[
j
];
}
std
::
cerr
<<
std
::
endl
;
}
return
0
;
}
tools/op.cmake
浏览文件 @
5b229a61
...
...
@@ -624,6 +624,7 @@ if (BEAM_SEARCH_OP)
endif
()
if
(
BEAM_SEARCH_DECODE_OP
)
add_definitions
(
-DBEAM_SEARCH_DECODE_OP
)
endif
()
if
(
FUSION_DECONVADDBNRELU_OP
)
add_definitions
(
-DFUSION_DECONVADDBNRELU_OP
)
endif
()
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录