Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle-Lite
提交
a6f2a7ce
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看板
提交
a6f2a7ce
编写于
9月 13, 2018
作者:
Z
zhangyang
浏览文件
操作
浏览文件
下载
差异文件
Merge remote-tracking branch 'upstream/develop' into develop
上级
baa59299
55cfc4dd
变更
5
显示空白变更内容
内联
并排
Showing
5 changed file
with
132 addition
and
48 deletion
+132
-48
src/framework/operator.cpp
src/framework/operator.cpp
+17
-6
src/operators/kernel/central-arm-func/prior_box_arm_func.h
src/operators/kernel/central-arm-func/prior_box_arm_func.h
+70
-20
src/operators/op_param.h
src/operators/op_param.h
+10
-0
test/net/test_mobilenet_025_fssd.cpp
test/net/test_mobilenet_025_fssd.cpp
+33
-22
test/test_helper.h
test/test_helper.h
+2
-0
未找到文件。
src/framework/operator.cpp
浏览文件 @
a6f2a7ce
...
@@ -62,13 +62,24 @@ void OperatorBase<Dtype>::Run() const {
...
@@ -62,13 +62,24 @@ void OperatorBase<Dtype>::Run() const {
DLOG
<<
"-------------"
<<
type_
<<
"----------------------------"
;
DLOG
<<
"-------------"
<<
type_
<<
"----------------------------"
;
vector
<
string
>
input_keys
=
GetInputKeys
();
vector
<
string
>
input_keys
=
GetInputKeys
();
for
(
const
auto
key
:
input_keys
)
{
for
(
const
auto
key
:
input_keys
)
{
Tensor
*
input
=
GetVarValue
<
framework
::
LoDTensor
>
(
key
,
inputs_
,
*
scope_
);
auto
var_vec_in
=
inputs_
.
at
(
key
);
if
(
input
)
DLOG
<<
type_
<<
" input- "
<<
key
<<
"="
<<
*
input
;
for
(
int
i
=
0
;
i
<
var_vec_in
.
size
();
++
i
)
{
auto
vari
=
scope_
->
FindVar
(
var_vec_in
[
i
]);
if
(
vari
->
IsInitialized
())
{
Tensor
*
tensor
=
vari
->
template
GetMutable
<
framework
::
LoDTensor
>();
if
(
tensor
)
DLOG
<<
type_
<<
" input- "
<<
key
<<
"="
<<
*
tensor
;
}
}
}
for
(
const
auto
key
:
GetOutKeys
())
{
auto
var_vec_out
=
outputs_
.
at
(
key
);
for
(
int
i
=
0
;
i
<
var_vec_out
.
size
();
++
i
)
{
auto
vari
=
scope_
->
FindVar
(
var_vec_out
[
i
]);
if
(
vari
->
IsInitialized
())
{
Tensor
*
tensor
=
vari
->
template
GetMutable
<
framework
::
LoDTensor
>();
if
(
tensor
)
DLOG
<<
type_
<<
" output- "
<<
key
<<
"="
<<
*
tensor
;
}
}
}
vector
<
string
>
output_keys
=
GetOutKeys
();
for
(
const
auto
key
:
output_keys
)
{
Tensor
*
out_
=
GetVarValue
<
framework
::
LoDTensor
>
(
key
,
outputs_
,
*
scope_
);
DLOG
<<
type_
<<
" output- "
<<
key
<<
"="
<<
*
out_
;
}
}
#endif
#endif
}
}
...
...
src/operators/kernel/central-arm-func/prior_box_arm_func.h
浏览文件 @
a6f2a7ce
...
@@ -16,6 +16,7 @@ limitations under the License. */
...
@@ -16,6 +16,7 @@ limitations under the License. */
#pragma once
#pragma once
#include <algorithm>
#include <algorithm>
#include <cmath>
#include <vector>
#include <vector>
namespace
paddle_mobile
{
namespace
paddle_mobile
{
...
@@ -89,12 +90,8 @@ void PriorBoxCompute(const PriorBoxParam<CPU> ¶m) {
...
@@ -89,12 +90,8 @@ void PriorBoxCompute(const PriorBoxParam<CPU> ¶m) {
int
idx
=
0
;
int
idx
=
0
;
for
(
size_t
s
=
0
;
s
<
min_sizes
.
size
();
++
s
)
{
for
(
size_t
s
=
0
;
s
<
min_sizes
.
size
();
++
s
)
{
auto
min_size
=
min_sizes
[
s
];
auto
min_size
=
min_sizes
[
s
];
// priors with different aspect ratios
if
(
param
.
MinMaxAspectRatiosOrder
())
{
for
(
float
ar
:
aspect_ratios
)
{
box_width
=
box_height
=
min_size
/
2.
;
box_width
=
min_size
*
sqrt
(
ar
)
/
2.
;
box_height
=
min_size
/
sqrt
(
ar
)
/
2.
;
/// box_width/2 , / img_width 为了得到feature map 相对于
/// 原图的归一化位置的比例。
output_boxes_dataptr
[
h
*
stride0
+
w
*
stride1
+
idx
*
stride2
+
0
]
=
output_boxes_dataptr
[
h
*
stride0
+
w
*
stride1
+
idx
*
stride2
+
0
]
=
(
center_x
-
box_width
)
/
img_width
;
(
center_x
-
box_width
)
/
img_width
;
output_boxes_dataptr
[
h
*
stride0
+
w
*
stride1
+
idx
*
stride2
+
1
]
=
output_boxes_dataptr
[
h
*
stride0
+
w
*
stride1
+
idx
*
stride2
+
1
]
=
...
@@ -104,24 +101,77 @@ void PriorBoxCompute(const PriorBoxParam<CPU> ¶m) {
...
@@ -104,24 +101,77 @@ void PriorBoxCompute(const PriorBoxParam<CPU> ¶m) {
output_boxes_dataptr
[
h
*
stride0
+
w
*
stride1
+
idx
*
stride2
+
3
]
=
output_boxes_dataptr
[
h
*
stride0
+
w
*
stride1
+
idx
*
stride2
+
3
]
=
(
center_y
+
box_height
)
/
img_height
;
(
center_y
+
box_height
)
/
img_height
;
idx
++
;
idx
++
;
if
(
max_sizes
.
size
()
>
0
)
{
auto
max_size
=
max_sizes
[
s
];
// square prior with size sqrt(minSize * maxSize)
box_width
=
box_height
=
sqrt
(
min_size
*
max_size
)
/
2.
;
output_boxes_dataptr
[
h
*
stride0
+
w
*
stride1
+
idx
*
stride2
+
0
]
=
(
center_x
-
box_width
)
/
img_width
;
output_boxes_dataptr
[
h
*
stride0
+
w
*
stride1
+
idx
*
stride2
+
1
]
=
(
center_y
-
box_height
)
/
img_height
;
output_boxes_dataptr
[
h
*
stride0
+
w
*
stride1
+
idx
*
stride2
+
2
]
=
(
center_x
+
box_width
)
/
img_width
;
output_boxes_dataptr
[
h
*
stride0
+
w
*
stride1
+
idx
*
stride2
+
3
]
=
(
center_y
+
box_height
)
/
img_height
;
idx
++
;
}
// priors with different aspect ratios
for
(
float
ar
:
aspect_ratios
)
{
if
(
fabs
(
ar
-
1.
)
<
1e-6
)
{
continue
;
}
box_width
=
min_size
*
sqrt
(
ar
)
/
2.
;
box_height
=
min_size
/
sqrt
(
ar
)
/
2.
;
/// box_width/2 , / img_width 为了得到feature map 相对于
/// 原图的归一化位置的比例。
output_boxes_dataptr
[
h
*
stride0
+
w
*
stride1
+
idx
*
stride2
+
0
]
=
(
center_x
-
box_width
)
/
img_width
;
output_boxes_dataptr
[
h
*
stride0
+
w
*
stride1
+
idx
*
stride2
+
1
]
=
(
center_y
-
box_height
)
/
img_height
;
output_boxes_dataptr
[
h
*
stride0
+
w
*
stride1
+
idx
*
stride2
+
2
]
=
(
center_x
+
box_width
)
/
img_width
;
output_boxes_dataptr
[
h
*
stride0
+
w
*
stride1
+
idx
*
stride2
+
3
]
=
(
center_y
+
box_height
)
/
img_height
;
idx
++
;
}
}
else
{
// priors with different aspect ratios
for
(
float
ar
:
aspect_ratios
)
{
box_width
=
min_size
*
sqrt
(
ar
)
/
2.
;
box_height
=
min_size
/
sqrt
(
ar
)
/
2.
;
/// box_width/2 , / img_width 为了得到feature map 相对于
/// 原图的归一化位置的比例。
output_boxes_dataptr
[
h
*
stride0
+
w
*
stride1
+
idx
*
stride2
+
0
]
=
(
center_x
-
box_width
)
/
img_width
;
output_boxes_dataptr
[
h
*
stride0
+
w
*
stride1
+
idx
*
stride2
+
1
]
=
(
center_y
-
box_height
)
/
img_height
;
output_boxes_dataptr
[
h
*
stride0
+
w
*
stride1
+
idx
*
stride2
+
2
]
=
(
center_x
+
box_width
)
/
img_width
;
output_boxes_dataptr
[
h
*
stride0
+
w
*
stride1
+
idx
*
stride2
+
3
]
=
(
center_y
+
box_height
)
/
img_height
;
idx
++
;
}
}
if
(
!
max_sizes
.
empty
())
{
if
(
!
max_sizes
.
empty
())
{
auto
max_size
=
max_sizes
[
s
];
auto
max_size
=
max_sizes
[
s
];
// square prior with size sqrt(minSize * maxSize)
// square prior with size sqrt(minSize * maxSize)
box_width
=
box_height
=
sqrt
(
min_size
*
max_size
)
/
2.
;
box_width
=
box_height
=
sqrt
(
min_size
*
max_size
)
/
2.
;
output_boxes_dataptr
[
h
*
stride0
+
w
*
stride1
+
idx
*
stride2
+
0
]
=
output_boxes_dataptr
[
h
*
stride0
+
w
*
stride1
+
idx
*
stride2
+
(
center_x
-
box_width
)
/
img_width
;
0
]
=
(
center_x
-
box_width
)
/
img_width
;
output_boxes_dataptr
[
h
*
stride0
+
w
*
stride1
+
idx
*
stride2
+
1
]
=
output_boxes_dataptr
[
h
*
stride0
+
w
*
stride1
+
idx
*
stride2
+
(
center_y
-
box_height
)
/
img_height
;
1
]
=
(
center_y
-
box_height
)
/
img_height
;
output_boxes_dataptr
[
h
*
stride0
+
w
*
stride1
+
idx
*
stride2
+
2
]
=
output_boxes_dataptr
[
h
*
stride0
+
w
*
stride1
+
idx
*
stride2
+
(
center_x
+
box_width
)
/
img_width
;
2
]
=
(
center_x
+
box_width
)
/
img_width
;
output_boxes_dataptr
[
h
*
stride0
+
w
*
stride1
+
idx
*
stride2
+
3
]
=
output_boxes_dataptr
[
h
*
stride0
+
w
*
stride1
+
idx
*
stride2
+
(
center_y
+
box_height
)
/
img_height
;
3
]
=
(
center_y
+
box_height
)
/
img_height
;
idx
++
;
idx
++
;
}
}
}
}
}
}
}
}
}
if
(
clip
)
{
if
(
clip
)
{
math
::
Transform
trans
;
math
::
Transform
trans
;
ClipFunctor
<
float
>
clip_func
;
ClipFunctor
<
float
>
clip_func
;
...
...
src/operators/op_param.h
浏览文件 @
a6f2a7ce
...
@@ -676,6 +676,11 @@ class PriorBoxParam : public OpParam {
...
@@ -676,6 +676,11 @@ class PriorBoxParam : public OpParam {
max_sizes_
=
GetAttr
<
vector
<
float
>>
(
"max_sizes"
,
attrs
);
max_sizes_
=
GetAttr
<
vector
<
float
>>
(
"max_sizes"
,
attrs
);
aspect_ratios_
=
GetAttr
<
vector
<
float
>>
(
"aspect_ratios"
,
attrs
);
aspect_ratios_
=
GetAttr
<
vector
<
float
>>
(
"aspect_ratios"
,
attrs
);
variances_
=
GetAttr
<
vector
<
float
>>
(
"variances"
,
attrs
);
variances_
=
GetAttr
<
vector
<
float
>>
(
"variances"
,
attrs
);
if
(
HasAttr
(
"min_max_aspect_ratios_order"
,
attrs
))
{
min_max_aspect_ratios_order_
=
GetAttr
<
bool
>
(
"min_max_aspect_ratios_order"
,
attrs
);
}
flip_
=
GetAttr
<
bool
>
(
"flip"
,
attrs
);
flip_
=
GetAttr
<
bool
>
(
"flip"
,
attrs
);
clip_
=
GetAttr
<
bool
>
(
"clip"
,
attrs
);
clip_
=
GetAttr
<
bool
>
(
"clip"
,
attrs
);
step_w_
=
GetAttr
<
float
>
(
"step_w"
,
attrs
);
step_w_
=
GetAttr
<
float
>
(
"step_w"
,
attrs
);
...
@@ -708,6 +713,10 @@ class PriorBoxParam : public OpParam {
...
@@ -708,6 +713,10 @@ class PriorBoxParam : public OpParam {
const
float
&
Offset
()
const
{
return
offset_
;
}
const
float
&
Offset
()
const
{
return
offset_
;
}
const
bool
&
MinMaxAspectRatiosOrder
()
const
{
return
min_max_aspect_ratios_order_
;
}
private:
private:
RType
*
input_
;
RType
*
input_
;
RType
*
input_image_
;
RType
*
input_image_
;
...
@@ -722,6 +731,7 @@ class PriorBoxParam : public OpParam {
...
@@ -722,6 +731,7 @@ class PriorBoxParam : public OpParam {
float
step_w_
;
float
step_w_
;
float
step_h_
;
float
step_h_
;
float
offset_
;
float
offset_
;
bool
min_max_aspect_ratios_order_
;
};
};
#endif
#endif
...
...
test/net/test_mobilenet_025_fssd.cpp
浏览文件 @
a6f2a7ce
...
@@ -16,35 +16,46 @@ limitations under the License. */
...
@@ -16,35 +16,46 @@ limitations under the License. */
#include "../test_helper.h"
#include "../test_helper.h"
#include "../test_include.h"
#include "../test_include.h"
int
main
()
{
int
main
(
int
argc
,
char
**
argv
)
{
paddle_mobile
::
PaddleMobile
<
paddle_mobile
::
CPU
>
paddle_mobile
;
int
times
=
10
;
paddle_mobile
.
SetThreadNum
(
4
);
if
(
argc
<=
1
)
{
// ../../../test/models/googlenet
times
=
10
;
// ../../../test/models/mobilenet
std
::
cout
<<
"没有输入 , 使用默认10次 "
<<
times
<<
std
::
endl
;
auto
time1
=
time
();
}
else
{
if
(
paddle_mobile
.
Load
(
std
::
string
(
g_fluid_fssd_new
)
+
"/model"
,
std
::
string
arstr
=
argv
[
1
];
std
::
string
(
g_fluid_fssd_new
)
+
"/params"
,
true
))
{
times
=
std
::
stoi
(
arstr
);
auto
time2
=
time
()
;
std
::
cout
<<
"input times: "
<<
times
<<
std
::
endl
;
std
::
cout
<<
"load cost :"
<<
time_diff
(
time1
,
time1
)
<<
"ms"
<<
std
::
endl
;
}
paddle_mobile
::
PaddleMobile
<
paddle_mobile
::
CPU
>
paddle_mobile
;
paddle_mobile
.
SetThreadNum
(
1
);
auto
isok
=
paddle_mobile
.
Load
(
std
::
string
(
g_fluid_fssd_new
)
+
"/model"
,
std
::
string
(
g_fluid_fssd_new
)
+
"/params"
,
true
);
if
(
isok
)
{
std
::
vector
<
float
>
input
;
std
::
vector
<
int64_t
>
dims
{
1
,
3
,
160
,
160
};
std
::
vector
<
int64_t
>
dims
{
1
,
3
,
160
,
160
};
Tensor
input_tensor
;
GetInput
<
float
>
(
g_imgfssd_ar1
,
&
input
,
dims
);
SetupTensor
<
float
>
(
&
input_tensor
,
{
1
,
3
,
160
,
160
},
static_cast
<
float
>
(
0
),
std
::
cout
<<
"预热10次....."
<<
std
::
endl
;
static_cast
<
float
>
(
1
));
std
::
vector
<
float
>
input
(
input_tensor
.
data
<
float
>
(),
input_tensor
.
data
<
float
>
()
+
input_tensor
.
numel
());
// 预热十次
// 预热十次
for
(
int
i
=
0
;
i
<
10
;
++
i
)
{
for
(
int
i
=
0
;
i
<
10
;
++
i
)
{
paddle_mobile
.
Predict
(
input
,
dims
);
auto
output
=
paddle_mobile
.
Predict
(
input
,
dims
);
}
}
std
::
cout
<<
"开始....."
<<
std
::
endl
;
double
time_sum
=
0
;
for
(
int
i
=
0
;
i
<
times
;
++
i
)
{
auto
time3
=
time
();
auto
time3
=
time
();
for
(
int
i
=
0
;
i
<
10
;
++
i
)
{
auto
output
=
paddle_mobile
.
Predict
(
input
,
dims
);
paddle_mobile
.
Predict
(
input
,
dims
);
}
auto
time4
=
time
();
auto
time4
=
time
();
std
::
cout
<<
"predict cost :"
<<
time_diff
(
time3
,
time4
)
/
10
<<
"ms"
double
timeDiff
=
time_diff
(
time3
,
time4
);
<<
std
::
endl
;
time_sum
+=
timeDiff
;
std
::
cout
<<
"第"
<<
i
<<
"次"
<<
"predict cost :"
<<
timeDiff
<<
"ms"
<<
std
::
endl
;
}
std
::
cout
<<
"平均时间:"
<<
time_sum
/
times
<<
"ms"
<<
std
::
endl
;
}
}
return
0
;
return
0
;
}
}
test/test_helper.h
浏览文件 @
a6f2a7ce
...
@@ -48,6 +48,8 @@ static const char *g_test_image_1x3x224x224 =
...
@@ -48,6 +48,8 @@ static const char *g_test_image_1x3x224x224 =
static
const
char
*
g_test_image_1x3x224x224_banana
=
static
const
char
*
g_test_image_1x3x224x224_banana
=
"../images/input_3x224x224_banana"
;
"../images/input_3x224x224_banana"
;
static
const
char
*
g_hand
=
"../images/hand_image"
;
static
const
char
*
g_hand
=
"../images/hand_image"
;
static
const
char
*
g_imgfssd_ar
=
"../images/test_image_ssd_ar"
;
static
const
char
*
g_imgfssd_ar1
=
"../images/003_0001.txt"
;
static
const
char
*
g_img
=
"../images/img.bin"
;
static
const
char
*
g_img
=
"../images/img.bin"
;
using
paddle_mobile
::
framework
::
DDim
;
using
paddle_mobile
::
framework
::
DDim
;
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录