Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle-Lite
提交
d019e470
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看板
提交
d019e470
编写于
10月 24, 2018
作者:
L
lijiancheng0614
浏览文件
操作
浏览文件
下载
差异文件
Merge branch 'develop' of
https://github.com/PaddlePaddle/paddle-mobile
into develop
上级
e609227f
39c3f250
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
93 addition
and
20 deletion
+93
-20
src/fpga/api.cpp
src/fpga/api.cpp
+1
-1
test/fpga/test_resnet50.cpp
test/fpga/test_resnet50.cpp
+92
-19
未找到文件。
src/fpga/api.cpp
浏览文件 @
d019e470
...
...
@@ -22,7 +22,7 @@ limitations under the License. */
#include "fpga/filter.h"
#include "fpga/image.h"
#define FPGA_TEST_MODE
//
#define PADDLE_MOBILE_OS_LINUX
#define PADDLE_MOBILE_OS_LINUX
namespace
paddle_mobile
{
namespace
fpga
{
...
...
test/fpga/test_resnet50.cpp
浏览文件 @
d019e470
...
...
@@ -11,34 +11,107 @@ 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. */
#include <fstream>
#include "../test_include.h"
static
const
char
*
g_resnet_combine
=
"../models/resnet50"
;
#include "fpga/api.h"
void
readStream
(
std
::
string
filename
,
float
*
buf
)
{
std
::
ifstream
in
;
in
.
open
(
filename
,
std
::
ios
::
in
);
if
(
!
in
.
is_open
())
{
std
::
cout
<<
"open File Failed."
<<
std
::
endl
;
return
;
}
string
strOne
;
int
i
=
0
;
while
(
!
in
.
eof
())
{
in
>>
buf
[
i
];
i
++
;
}
in
.
close
();
}
void
convert_to_chw
(
int16_t
**
data_in
,
int
channel
,
int
height
,
int
width
,
int16_t
*
data_tmp
)
{
int64_t
amount_per_side
=
width
*
height
;
for
(
int
h
=
0
;
h
<
height
;
h
++
)
{
for
(
int
w
=
0
;
w
<
width
;
w
++
)
{
for
(
int
c
=
0
;
c
<
channel
;
c
++
)
{
*
(
data_tmp
+
c
*
amount_per_side
+
width
*
h
+
w
)
=
*
((
*
data_in
)
++
);
}
}
}
}
void
dump
(
std
::
string
filename
,
const
Tensor
input_tensor
)
{
auto
dataptr
=
input_tensor
.
data
<
float
>
();
std
::
ofstream
out
(
filename
.
c_str
());
float
result
=
0
;
for
(
int
i
=
0
;
i
<
input_tensor
.
numel
();
++
i
)
{
result
=
paddle_mobile
::
fpga
::
fp16_2_fp32
(
dataptr
[
i
]);
out
<<
result
<<
std
::
endl
;
}
out
.
close
();
}
void
dump_stride
(
std
::
string
filename
,
const
Tensor
input_tensor
,
const
int
dumpnum
)
{
int
c
=
(
input_tensor
.
dims
())[
1
];
int
h
=
(
input_tensor
.
dims
())[
2
];
int
w
=
(
input_tensor
.
dims
())[
3
];
auto
data_ptr
=
input_tensor
.
data
<
float
>
();
int16_t
*
data_tmp
=
(
int16_t
*
)
malloc
(
c
*
h
*
w
*
sizeof
(
int16_t
));
int16_t
*
data_ptr_16
=
(
int16_t
*
)
data_ptr
;
convert_to_chw
(
&
data_ptr_16
,
c
,
h
,
w
,
data_tmp
);
// const int16_t *dataptr = input_tensor.data<int16_t>();
std
::
ofstream
out
(
filename
.
c_str
());
float
result
=
0
;
int
stride
=
input_tensor
.
numel
()
/
dumpnum
;
stride
=
stride
>
0
?
stride
:
1
;
for
(
int
i
=
0
;
i
<
input_tensor
.
numel
();
i
+=
stride
)
{
result
=
paddle_mobile
::
fpga
::
fp16_2_fp32
(
data_tmp
[
i
]);
out
<<
result
<<
std
::
endl
;
}
out
.
close
();
free
(
data_tmp
);
}
static
const
char
*
g_resnet50
=
"../models/resnet50"
;
const
std
::
string
g_image_src_float
=
"../images/image_src_float"
;
int
main
()
{
DLOG
<<
paddle_mobile
::
fpga
::
open_device
();
paddle_mobile
::
fpga
::
open_device
();
paddle_mobile
::
PaddleMobile
<
paddle_mobile
::
FPGA
>
paddle_mobile
;
// if (paddle_mobile.Load(std::string(g_resnet_combine) + "/model",
// std::string(g_resnet_combine) + "/params", true)) {
if
(
paddle_mobile
.
Load
(
std
::
string
(
g_resnet_combine
),
true
))
{
std
::
vector
<
int64_t
>
dims
{
1
,
3
,
224
,
224
};
if
(
paddle_mobile
.
Load
(
std
::
string
(
g_resnet50
),
true
))
{
Tensor
input_tensor
;
SetupTensor
<
float
>
(
&
input_tensor
,
{
1
,
3
,
224
,
224
},
static_cast
<
float
>
(
0
),
static_cast
<
float
>
(
1
));
std
::
vector
<
float
>
input
(
input_tensor
.
data
<
float
>
(),
input_tensor
.
data
<
float
>
()
+
input_tensor
.
numel
());
readStream
(
g_image_src_float
,
input_tensor
.
mutable_data
<
float
>
({
1
,
3
,
224
,
224
}));
paddle_mobile
.
FeedData
(
input_tensor
);
for
(
int
i
=
0
;
i
<
1000
;
i
++
)
{
paddle_mobile
.
Predict_To
(
-
1
);
if
(
i
%
100
==
0
)
std
::
cout
<<
i
<<
std
::
endl
;
}
paddle_mobile
.
Predict_To
(
-
1
);
/*for(int i = 0; i < 73; i++)
{
auto tensor_ptr = paddle_mobile.FetchResult(i);
std::string saveName = "resnet50_result_" + std::to_string (i);
paddle_mobile::fpga::fpga_invalidate((*tensor_ptr).data<float>(),
tensor_ptr->numel()); dump_stride(saveName, (*tensor_ptr), 20);
//dump(saveName, (*tensor_ptr));
}*/
// paddle_mobile.Predict_From(73);
// paddle_mobile.Predict_From_To(72, 73);
DLOG
<<
"Computation done"
;
/*std::shared_ptr<Tensor> output_tensor = paddle_mobile.FetchResult(73);
(*output_tensor).dump<float>("resnet50_result_73");
output_tensor = paddle_mobile.FetchResult(74);
(*output_tensor).dump<float>("resnet50_result_74");*/
std
::
shared_ptr
<
Tensor
>
output_tensor
=
paddle_mobile
.
FetchResult
(
74
);
float
max
=
0
;
auto
data_ptr
=
output_tensor
->
data
<
float
>
();
int
maximumIdx
=
0
;
for
(
int
i
=
0
;
i
<
(
*
output_tensor
).
numel
();
i
++
)
{
if
(
data_ptr
[
i
]
>
max
)
{
maximumIdx
=
i
;
max
=
data_ptr
[
i
];
}
}
std
::
cout
<<
"index : "
<<
maximumIdx
<<
", value : "
<<
max
<<
std
::
endl
;
std
::
cout
<<
"Computation done"
<<
std
::
endl
;
return
0
;
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录