Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle-Lite
提交
03b128d4
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看板
未验证
提交
03b128d4
编写于
9月 13, 2018
作者:
X
xiebaiyuan
提交者:
GitHub
9月 13, 2018
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #963 from xiebaiyuan/develop
add new attr in pribox to suite fssd close
#924
上级
1c4d5d8e
a590c85a
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
128 addition
and
48 deletion
+128
-48
src/framework/operator.cpp
src/framework/operator.cpp
+13
-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
浏览文件 @
03b128d4
...
...
@@ -62,13 +62,20 @@ void OperatorBase<Dtype>::Run() const {
DLOG
<<
"-------------"
<<
type_
<<
"----------------------------"
;
vector
<
string
>
input_keys
=
GetInputKeys
();
for
(
const
auto
key
:
input_keys
)
{
Tensor
*
input
=
GetVarValue
<
framework
::
LoDTensor
>
(
key
,
inputs_
,
*
scope_
);
if
(
input
)
DLOG
<<
type_
<<
" input- "
<<
key
<<
"="
<<
*
input
;
auto
var_vec_in
=
inputs_
.
at
(
key
);
for
(
int
i
=
0
;
i
<
var_vec_in
.
size
();
++
i
)
{
auto
vari
=
scope_
->
FindVar
(
var_vec_in
[
i
]);
Tensor
*
tensor
=
vari
->
template
GetMutable
<
framework
::
LoDTensor
>();
if
(
tensor
)
DLOG
<<
type_
<<
" input- "
<<
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_
;
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
]);
Tensor
*
tensor
=
vari
->
template
GetMutable
<
framework
::
LoDTensor
>();
if
(
tensor
)
DLOG
<<
type_
<<
" output- "
<<
key
<<
"="
<<
*
tensor
;
}
}
#endif
}
...
...
src/operators/kernel/central-arm-func/prior_box_arm_func.h
浏览文件 @
03b128d4
...
...
@@ -16,6 +16,7 @@ limitations under the License. */
#pragma once
#include <algorithm>
#include <cmath>
#include <vector>
namespace
paddle_mobile
{
...
...
@@ -89,26 +90,8 @@ void PriorBoxCompute(const PriorBoxParam<CPU> ¶m) {
int
idx
=
0
;
for
(
size_t
s
=
0
;
s
<
min_sizes
.
size
();
++
s
)
{
auto
min_size
=
min_sizes
[
s
];
// 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
())
{
auto
max_size
=
max_sizes
[
s
];
// square prior with size sqrt(minSize * maxSize)
box_width
=
box_height
=
sqrt
(
min_size
*
max_size
)
/
2.
;
if
(
param
.
MinMaxAspectRatiosOrder
())
{
box_width
=
box_height
=
min_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
]
=
...
...
@@ -118,6 +101,73 @@ void PriorBoxCompute(const PriorBoxParam<CPU> ¶m) {
output_boxes_dataptr
[
h
*
stride0
+
w
*
stride1
+
idx
*
stride2
+
3
]
=
(
center_y
+
box_height
)
/
img_height
;
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
())
{
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
++
;
}
}
}
}
...
...
src/operators/op_param.h
浏览文件 @
03b128d4
...
...
@@ -676,6 +676,11 @@ class PriorBoxParam : public OpParam {
max_sizes_
=
GetAttr
<
vector
<
float
>>
(
"max_sizes"
,
attrs
);
aspect_ratios_
=
GetAttr
<
vector
<
float
>>
(
"aspect_ratios"
,
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
);
clip_
=
GetAttr
<
bool
>
(
"clip"
,
attrs
);
step_w_
=
GetAttr
<
float
>
(
"step_w"
,
attrs
);
...
...
@@ -708,6 +713,10 @@ class PriorBoxParam : public OpParam {
const
float
&
Offset
()
const
{
return
offset_
;
}
const
bool
&
MinMaxAspectRatiosOrder
()
const
{
return
min_max_aspect_ratios_order_
;
}
private:
RType
*
input_
;
RType
*
input_image_
;
...
...
@@ -722,6 +731,7 @@ class PriorBoxParam : public OpParam {
float
step_w_
;
float
step_h_
;
float
offset_
;
bool
min_max_aspect_ratios_order_
;
};
#endif
...
...
test/net/test_mobilenet_025_fssd.cpp
浏览文件 @
03b128d4
...
...
@@ -16,35 +16,46 @@ limitations under the License. */
#include "../test_helper.h"
#include "../test_include.h"
int
main
()
{
paddle_mobile
::
PaddleMobile
<
paddle_mobile
::
CPU
>
paddle_mobile
;
paddle_mobile
.
SetThreadNum
(
4
);
// ../../../test/models/googlenet
// ../../../test/models/mobilenet
auto
time1
=
time
();
if
(
paddle_mobile
.
Load
(
std
::
string
(
g_fluid_fssd_new
)
+
"/model"
,
std
::
string
(
g_fluid_fssd_new
)
+
"/params"
,
true
))
{
auto
time2
=
time
()
;
std
::
cout
<<
"load cost :"
<<
time_diff
(
time1
,
time1
)
<<
"ms"
<<
std
::
endl
;
int
main
(
int
argc
,
char
**
argv
)
{
int
times
=
10
;
if
(
argc
<=
1
)
{
times
=
10
;
std
::
cout
<<
"没有输入 , 使用默认10次 "
<<
times
<<
std
::
endl
;
}
else
{
std
::
string
arstr
=
argv
[
1
];
times
=
std
::
stoi
(
arstr
);
std
::
cout
<<
"input times: "
<<
times
<<
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
};
Tensor
input_tensor
;
SetupTensor
<
float
>
(
&
input_tensor
,
{
1
,
3
,
160
,
160
},
static_cast
<
float
>
(
0
),
static_cast
<
float
>
(
1
));
GetInput
<
float
>
(
g_imgfssd_ar1
,
&
input
,
dims
);
std
::
cout
<<
"预热10次....."
<<
std
::
endl
;
std
::
vector
<
float
>
input
(
input_tensor
.
data
<
float
>
(),
input_tensor
.
data
<
float
>
()
+
input_tensor
.
numel
());
// 预热十次
for
(
int
i
=
0
;
i
<
10
;
++
i
)
{
paddle_mobile
.
Predict
(
input
,
dims
);
auto
output
=
paddle_mobile
.
Predict
(
input
,
dims
);
}
auto
time3
=
time
();
for
(
int
i
=
0
;
i
<
10
;
++
i
)
{
paddle_mobile
.
Predict
(
input
,
dims
);
std
::
cout
<<
"开始....."
<<
std
::
endl
;
double
time_sum
=
0
;
for
(
int
i
=
0
;
i
<
times
;
++
i
)
{
auto
time3
=
time
();
auto
output
=
paddle_mobile
.
Predict
(
input
,
dims
);
auto
time4
=
time
();
double
timeDiff
=
time_diff
(
time3
,
time4
);
time_sum
+=
timeDiff
;
std
::
cout
<<
"第"
<<
i
<<
"次"
<<
"predict cost :"
<<
timeDiff
<<
"ms"
<<
std
::
endl
;
}
auto
time4
=
time
();
std
::
cout
<<
"predict cost :"
<<
time_diff
(
time3
,
time4
)
/
10
<<
"ms"
<<
std
::
endl
;
std
::
cout
<<
"平均时间:"
<<
time_sum
/
times
<<
"ms"
<<
std
::
endl
;
}
return
0
;
}
test/test_helper.h
浏览文件 @
03b128d4
...
...
@@ -48,6 +48,8 @@ static const char *g_test_image_1x3x224x224 =
static
const
char
*
g_test_image_1x3x224x224_banana
=
"../images/input_3x224x224_banana"
;
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"
;
using
paddle_mobile
::
framework
::
DDim
;
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录