Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle-Lite
提交
d4d58408
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看板
提交
d4d58408
编写于
3月 18, 2019
作者:
Z
zhangyang0701
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
change format
上级
4da635f8
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
109 addition
and
105 deletion
+109
-105
test/fpga/test_marker_api.cpp
test/fpga/test_marker_api.cpp
+98
-97
test/fpga/test_mobilenet_api.cpp
test/fpga/test_mobilenet_api.cpp
+5
-3
test/fpga/test_yolo_api.cpp
test/fpga/test_yolo_api.cpp
+6
-5
未找到文件。
test/fpga/test_marker_api.cpp
浏览文件 @
d4d58408
...
@@ -45,65 +45,67 @@ void readStream(std::string filename, char *buf) {
...
@@ -45,65 +45,67 @@ void readStream(std::string filename, char *buf) {
in
.
close
();
in
.
close
();
}
}
signed
char
float_to_int8
(
float
fdata
)
{
signed
char
float_to_int8
(
float
fdata
)
{
if
(
fdata
<
0.0
)
{
if
(
fdata
<
0.0
)
{
fdata
-=
0.5
;
fdata
-=
0.5
;
}
else
{
}
else
{
fdata
+=
0.5
;
fdata
+=
0.5
;
}
}
return
(
signed
char
)
fdata
;
return
(
signed
char
)
fdata
;
}
}
void
quantize
(
float
**
data_in
,
int
data_size
)
{
void
quantize
(
float
**
data_in
,
int
data_size
)
{
float
*
tmp
=
*
data_in
;
float
*
tmp
=
*
data_in
;
signed
char
*
tmp_data
=
signed
char
*
tmp_data
=
(
signed
char
*
)
paddle_mobile
::
fpga
::
fpga_malloc
(
data_size
*
sizeof
(
char
));
(
signed
char
*
)
paddle_mobile
::
fpga
::
fpga_malloc
(
data_size
*
sizeof
(
char
));
for
(
int
i
=
0
;
i
<
data_size
;
i
++
)
{
for
(
int
i
=
0
;
i
<
data_size
;
i
++
)
{
tmp_data
[
i
]
=
float_to_int8
((
*
data_in
)[
i
]
+
128
);
tmp_data
[
i
]
=
float_to_int8
((
*
data_in
)[
i
]
+
128
);
}
}
*
data_in
=
(
float
*
)
tmp_data
;
// NOLINT
*
data_in
=
(
float
*
)
tmp_data
;
// NOLINT
paddle_mobile
::
fpga
::
fpga_free
(
tmp
);
paddle_mobile
::
fpga
::
fpga_free
(
tmp
);
}
}
void
convert_to_chw
(
float
**
data_in
,
int
channel
,
int
height
,
int
width
,
void
convert_to_chw
(
float
**
data_in
,
int
channel
,
int
height
,
int
width
,
float
*
data_tmp
)
{
float
*
data_tmp
)
{
int64_t
amount_per_side
=
width
*
height
;
int64_t
amount_per_side
=
width
*
height
;
for
(
int
h
=
0
;
h
<
height
;
h
++
)
{
for
(
int
h
=
0
;
h
<
height
;
h
++
)
{
for
(
int
w
=
0
;
w
<
width
;
w
++
)
{
for
(
int
w
=
0
;
w
<
width
;
w
++
)
{
for
(
int
c
=
0
;
c
<
channel
;
c
++
)
{
for
(
int
c
=
0
;
c
<
channel
;
c
++
)
{
*
(
data_tmp
+
c
*
amount_per_side
+
width
*
h
+
w
)
=
*
((
*
data_in
)
++
);
*
(
data_tmp
+
c
*
amount_per_side
+
width
*
h
+
w
)
=
*
((
*
data_in
)
++
);
}
}
}
}
}
}
}
}
void
dump_stride_float
(
std
::
string
filename
,
paddle_mobile
::
PaddleTensor
input_tensor
)
{
void
dump_stride_float
(
std
::
string
filename
,
auto
data_ptr
=
reinterpret_cast
<
float
*>
(
input_tensor
.
data
.
data
());
paddle_mobile
::
PaddleTensor
input_tensor
)
{
int
c
=
(
input_tensor
.
shape
)[
1
];
auto
data_ptr
=
reinterpret_cast
<
float
*>
(
input_tensor
.
data
.
data
());
int
h
=
(
input_tensor
.
shape
)[
2
];
int
c
=
(
input_tensor
.
shape
)[
1
];
int
w
=
(
input_tensor
.
shape
)[
3
];
int
h
=
(
input_tensor
.
shape
)[
2
];
int
n
=
(
input_tensor
.
shape
)[
0
];
int
w
=
(
input_tensor
.
shape
)[
3
];
float
*
data_tmp
=
int
n
=
(
input_tensor
.
shape
)[
0
];
reinterpret_cast
<
float
*>
(
malloc
(
c
*
h
*
w
*
sizeof
(
float
)));
float
*
data_tmp
=
//convert_to_chw(&data_ptr, c, h, w, data_tmp);
reinterpret_cast
<
float
*>
(
malloc
(
c
*
h
*
w
*
sizeof
(
float
)));
std
::
ofstream
out
(
filename
.
c_str
());
// convert_to_chw(&data_ptr, c, h, w, data_tmp);
float
result
=
0
;
std
::
ofstream
out
(
filename
.
c_str
());
int
datasize
=
abs
(
c
*
h
*
w
*
n
);
float
result
=
0
;
if
(
datasize
==
0
)
{
int
datasize
=
abs
(
c
*
h
*
w
*
n
);
std
::
cout
<<
"wrong dump data size"
<<
std
::
endl
;
if
(
datasize
==
0
)
{
return
;
std
::
cout
<<
"wrong dump data size"
<<
std
::
endl
;
}
return
;
for
(
int
i
=
0
;
i
<
datasize
;
i
++
)
{
}
result
=
data_ptr
[
i
];
for
(
int
i
=
0
;
i
<
datasize
;
i
++
)
{
out
<<
result
<<
std
::
endl
;
result
=
data_ptr
[
i
];
}
out
<<
result
<<
std
::
endl
;
out
.
close
();
}
out
.
close
();
}
}
void
dump_stride
(
std
::
string
filename
,
paddle_mobile
::
PaddleTensor
input_tensor
)
{
void
dump_stride
(
std
::
string
filename
,
if
(
input_tensor
.
dtypeid
==
typeid
(
float
))
{
paddle_mobile
::
PaddleTensor
input_tensor
)
{
dump_stride_float
(
filename
,
input_tensor
);
if
(
input_tensor
.
dtypeid
==
typeid
(
float
))
{
}
else
{
dump_stride_float
(
filename
,
input_tensor
);
std
::
cout
<<
"only support dumping float data"
<<
std
::
endl
;
}
else
{
}
std
::
cout
<<
"only support dumping float data"
<<
std
::
endl
;
}
}
}
PaddleMobileConfig
GetConfig
()
{
PaddleMobileConfig
GetConfig
()
{
PaddleMobileConfig
config
;
PaddleMobileConfig
config
;
...
@@ -119,64 +121,63 @@ PaddleMobileConfig GetConfig() {
...
@@ -119,64 +121,63 @@ PaddleMobileConfig GetConfig() {
return
config
;
return
config
;
}
}
PaddleMobileConfig
GetConfig1
()
{
PaddleMobileConfig
GetConfig1
()
{
PaddleMobileConfig
config
;
PaddleMobileConfig
config
;
config
.
precision
=
PaddleMobileConfig
::
FP32
;
config
.
precision
=
PaddleMobileConfig
::
FP32
;
config
.
device
=
PaddleMobileConfig
::
kFPGA
;
config
.
device
=
PaddleMobileConfig
::
kFPGA
;
config
.
prog_file
=
g_model1
;
config
.
prog_file
=
g_model1
;
config
.
param_file
=
g_param1
;
config
.
param_file
=
g_param1
;
config
.
thread_num
=
1
;
config
.
thread_num
=
1
;
config
.
batch_size
=
1
;
config
.
batch_size
=
1
;
config
.
optimize
=
true
;
config
.
optimize
=
true
;
config
.
lod_mode
=
true
;
config
.
lod_mode
=
true
;
config
.
quantification
=
false
;
config
.
quantification
=
false
;
return
config
;
return
config
;
}
}
int
main
()
{
int
main
()
{
open_device
();
open_device
();
PaddleMobileConfig
config1
=
GetConfig1
();
PaddleMobileConfig
config1
=
GetConfig1
();
auto
predictor1
=
auto
predictor1
=
CreatePaddlePredictor
<
PaddleMobileConfig
,
CreatePaddlePredictor
<
PaddleMobileConfig
,
PaddleEngineKind
::
kPaddleMobile
>
(
config1
);
PaddleEngineKind
::
kPaddleMobile
>
(
config1
);
std
::
cout
<<
"Finishing loading model"
<<
std
::
endl
;
std
::
cout
<<
"Finishing loading model"
<<
std
::
endl
;
for
(
int
i
=
0
;
i
<
1
;
++
i
)
{
for
(
int
i
=
0
;
i
<
1
;
++
i
)
{
int
img_length1
=
144
*
14
*
14
;
int
img_length1
=
144
*
14
*
14
;
auto
img1
=
auto
img1
=
reinterpret_cast
<
float
*>
(
fpga_malloc
(
img_length1
*
sizeof
(
float
)));
reinterpret_cast
<
float
*>
(
fpga_malloc
(
img_length1
*
sizeof
(
float
)));
readStream
(
g_image1
,
reinterpret_cast
<
char
*>
(
img1
));
readStream
(
g_image1
,
reinterpret_cast
<
char
*>
(
img1
));
std
::
cout
<<
"Finishing initializing data"
<<
std
::
endl
;
std
::
cout
<<
"Finishing initializing data"
<<
std
::
endl
;
struct
PaddleTensor
t_img1
;
struct
PaddleTensor
t_img1
;
t_img1
.
dtypeid
=
typeid
(
float
);
t_img1
.
dtypeid
=
typeid
(
float
);
t_img1
.
layout
=
LAYOUT_HWC
;
t_img1
.
layout
=
LAYOUT_HWC
;
t_img1
.
shape
=
std
::
vector
<
int
>
({
1
,
14
,
14
,
144
});
t_img1
.
shape
=
std
::
vector
<
int
>
({
1
,
14
,
14
,
144
});
t_img1
.
name
=
"Image information"
;
t_img1
.
name
=
"Image information"
;
t_img1
.
data
.
Reset
(
img1
,
img_length1
*
sizeof
(
float
));
t_img1
.
data
.
Reset
(
img1
,
img_length1
*
sizeof
(
float
));
predictor1
->
FeedPaddleTensors
({
t_img1
});
predictor1
->
FeedPaddleTensors
({
t_img1
});
std
::
cout
<<
"Finishing feeding data "
<<
std
::
endl
;
std
::
cout
<<
"Finishing feeding data "
<<
std
::
endl
;
predictor1
->
Predict_From_To
(
0
,
-
1
);
predictor1
->
Predict_From_To
(
0
,
-
1
);
std
::
cout
<<
"Finishing predicting "
<<
std
::
endl
;
std
::
cout
<<
"Finishing predicting "
<<
std
::
endl
;
std
::
vector
<
paddle_mobile
::
PaddleTensor
>
v1
;
// No need to initialize v
std
::
vector
<
paddle_mobile
::
PaddleTensor
>
v1
;
// No need to initialize v
predictor1
->
FetchPaddleTensors
(
&
v1
);
// Old data in v will be cleared
predictor1
->
FetchPaddleTensors
(
&
v1
);
// Old data in v will be cleared
std
::
cout
<<
"Output number is "
<<
v1
.
size
()
<<
std
::
endl
;
std
::
cout
<<
"Output number is "
<<
v1
.
size
()
<<
std
::
endl
;
for
(
int
fetchNum
=
0
;
fetchNum
<
v1
.
size
();
fetchNum
++
)
{
for
(
int
fetchNum
=
0
;
fetchNum
<
v1
.
size
();
fetchNum
++
)
{
std
::
string
dumpName
=
"marker2_api_fetch_"
+
std
::
to_string
(
fetchNum
);
std
::
string
dumpName
=
"marker2_api_fetch_"
+
std
::
to_string
(
fetchNum
);
dump_stride
(
dumpName
,
v1
[
fetchNum
]);
dump_stride
(
dumpName
,
v1
[
fetchNum
]);
}
}
}
}
/////////////////////////////////////
/////////////////////////////////////
PaddleMobileConfig
config
=
GetConfig
();
PaddleMobileConfig
config
=
GetConfig
();
auto
predictor
=
auto
predictor
=
CreatePaddlePredictor
<
PaddleMobileConfig
,
CreatePaddlePredictor
<
PaddleMobileConfig
,
PaddleEngineKind
::
kPaddleMobile
>
(
config
);
PaddleEngineKind
::
kPaddleMobile
>
(
config
);
std
::
cout
<<
"Finishing loading model"
<<
std
::
endl
;
std
::
cout
<<
"Finishing loading model"
<<
std
::
endl
;
...
@@ -194,14 +195,14 @@ for(int i = 0; i < 1; ++i){
...
@@ -194,14 +195,14 @@ for(int i = 0; i < 1; ++i){
t_img_info
.
data
.
Reset
(
img_info
,
3
*
sizeof
(
float
));
t_img_info
.
data
.
Reset
(
img_info
,
3
*
sizeof
(
float
));
t_img
.
dtypeid
=
typeid
(
float
);
t_img
.
dtypeid
=
typeid
(
float
);
//quantize(&img, img_length);
//
quantize(&img, img_length);
//t_img.dtypeid = typeid(int8_t);
//
t_img.dtypeid = typeid(int8_t);
t_img
.
layout
=
LAYOUT_HWC
;
t_img
.
layout
=
LAYOUT_HWC
;
t_img
.
shape
=
std
::
vector
<
int
>
({
1
,
432
,
1280
,
3
});
t_img
.
shape
=
std
::
vector
<
int
>
({
1
,
432
,
1280
,
3
});
t_img
.
name
=
"Image information"
;
t_img
.
name
=
"Image information"
;
t_img
.
data
.
Reset
(
img
,
img_length
*
sizeof
(
float
));
t_img
.
data
.
Reset
(
img
,
img_length
*
sizeof
(
float
));
//t_img.data.Reset(img, img_length * sizeof(int8_t));
//
t_img.data.Reset(img, img_length * sizeof(int8_t));
// for(int i = 0; i < 100; ++i){
// for(int i = 0; i < 100; ++i){
predictor
->
FeedPaddleTensors
({
t_img_info
,
t_img
});
predictor
->
FeedPaddleTensors
({
t_img_info
,
t_img
});
std
::
cout
<<
"Finishing feeding data "
<<
std
::
endl
;
std
::
cout
<<
"Finishing feeding data "
<<
std
::
endl
;
...
@@ -209,8 +210,8 @@ for(int i = 0; i < 1; ++i){
...
@@ -209,8 +210,8 @@ for(int i = 0; i < 1; ++i){
predictor
->
Predict_From_To
(
0
,
-
1
);
predictor
->
Predict_From_To
(
0
,
-
1
);
std
::
cout
<<
"Finishing predicting "
<<
std
::
endl
;
std
::
cout
<<
"Finishing predicting "
<<
std
::
endl
;
std
::
vector
<
paddle_mobile
::
PaddleTensor
>
v
;
// No need to initialize v
std
::
vector
<
paddle_mobile
::
PaddleTensor
>
v
;
// No need to initialize v
predictor
->
FetchPaddleTensors
(
&
v
);
// Old data in v will be cleared
predictor
->
FetchPaddleTensors
(
&
v
);
// Old data in v will be cleared
std
::
cout
<<
"Output number is "
<<
v
.
size
()
<<
std
::
endl
;
std
::
cout
<<
"Output number is "
<<
v
.
size
()
<<
std
::
endl
;
for
(
int
fetchNum
=
0
;
fetchNum
<
v
.
size
();
fetchNum
++
)
{
for
(
int
fetchNum
=
0
;
fetchNum
<
v
.
size
();
fetchNum
++
)
{
std
::
string
dumpName
=
"marker_api_fetch_"
+
std
::
to_string
(
fetchNum
);
std
::
string
dumpName
=
"marker_api_fetch_"
+
std
::
to_string
(
fetchNum
);
...
...
test/fpga/test_mobilenet_api.cpp
浏览文件 @
d4d58408
...
@@ -19,8 +19,8 @@ limitations under the License. */
...
@@ -19,8 +19,8 @@ limitations under the License. */
#include <iostream>
#include <iostream>
#include "../../src/io/paddle_inference_api.h"
#include "../../src/io/paddle_inference_api.h"
using
namespace
paddle_mobile
;
//
NOLINT
using
namespace
paddle_mobile
;
//
NOLINT
using
namespace
paddle_mobile
::
fpga
;
//NOLINT
using
namespace
paddle_mobile
::
fpga
;
//
NOLINT
static
const
char
*
g_image
=
"../images/mobilenet_txtdata/1.txt"
;
static
const
char
*
g_image
=
"../images/mobilenet_txtdata/1.txt"
;
static
const
char
*
g_model
=
"../models/keycurve_l2_regular4_model/__model__"
;
static
const
char
*
g_model
=
"../models/keycurve_l2_regular4_model/__model__"
;
...
@@ -119,7 +119,9 @@ PaddleMobileConfig GetConfig() {
...
@@ -119,7 +119,9 @@ PaddleMobileConfig GetConfig() {
int
main
()
{
int
main
()
{
open_device
();
open_device
();
PaddleMobileConfig
config
=
GetConfig
();
PaddleMobileConfig
config
=
GetConfig
();
auto
predictor
=
CreatePaddlePredictor
<
paddle_mobile
::
PaddleMobileConfig
,
PaddleEngineKind
::
kPaddleMobile
>
(
config
);
auto
predictor
=
CreatePaddlePredictor
<
paddle_mobile
::
PaddleMobileConfig
,
PaddleEngineKind
::
kPaddleMobile
>
(
config
);
std
::
cout
<<
"Finishing loading model"
<<
std
::
endl
;
std
::
cout
<<
"Finishing loading model"
<<
std
::
endl
;
int
img_length
=
256
*
416
*
3
;
int
img_length
=
256
*
416
*
3
;
...
...
test/fpga/test_yolo_api.cpp
浏览文件 @
d4d58408
...
@@ -19,8 +19,8 @@ limitations under the License. */
...
@@ -19,8 +19,8 @@ limitations under the License. */
#include <iostream>
#include <iostream>
#include "../../src/io/paddle_inference_api.h"
#include "../../src/io/paddle_inference_api.h"
using
namespace
paddle_mobile
;
//
NOLINT
using
namespace
paddle_mobile
;
//
NOLINT
using
namespace
paddle_mobile
::
fpga
;
//NOLINT
using
namespace
paddle_mobile
::
fpga
;
//
NOLINT
static
const
char
*
g_image
=
"../images/yolo_test_txtimg/1.txt"
;
static
const
char
*
g_image
=
"../images/yolo_test_txtimg/1.txt"
;
static
const
char
*
g_model
=
"../models/yolo_bn_l2_model/__model__"
;
static
const
char
*
g_model
=
"../models/yolo_bn_l2_model/__model__"
;
...
@@ -51,8 +51,7 @@ signed char float_to_int8(float fdata) {
...
@@ -51,8 +51,7 @@ signed char float_to_int8(float fdata) {
}
}
void
quantize
(
float
**
data_in
,
int
data_size
)
{
void
quantize
(
float
**
data_in
,
int
data_size
)
{
float
*
tmp
=
*
data_in
;
float
*
tmp
=
*
data_in
;
signed
char
*
tmp_data
=
signed
char
*
tmp_data
=
(
signed
char
*
)
fpga_malloc
(
data_size
*
sizeof
(
char
));
(
signed
char
*
)
fpga_malloc
(
data_size
*
sizeof
(
char
));
for
(
int
i
=
0
;
i
<
data_size
;
i
++
)
{
for
(
int
i
=
0
;
i
<
data_size
;
i
++
)
{
tmp_data
[
i
]
=
float_to_int8
((
*
data_in
)[
i
]
+
128
);
tmp_data
[
i
]
=
float_to_int8
((
*
data_in
)[
i
]
+
128
);
}
}
...
@@ -120,7 +119,9 @@ PaddleMobileConfig GetConfig() {
...
@@ -120,7 +119,9 @@ PaddleMobileConfig GetConfig() {
int
main
()
{
int
main
()
{
open_device
();
open_device
();
PaddleMobileConfig
config
=
GetConfig
();
PaddleMobileConfig
config
=
GetConfig
();
auto
predictor
=
CreatePaddlePredictor
<
PaddleMobileConfig
,
PaddleEngineKind
::
kPaddleMobile
>
(
config
);
auto
predictor
=
CreatePaddlePredictor
<
PaddleMobileConfig
,
PaddleEngineKind
::
kPaddleMobile
>
(
config
);
std
::
cout
<<
"Finishing loading model"
<<
std
::
endl
;
std
::
cout
<<
"Finishing loading model"
<<
std
::
endl
;
int
img_length
=
256
*
416
*
3
;
int
img_length
=
256
*
416
*
3
;
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录