Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle-Lite
提交
efd49e13
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看板
提交
efd49e13
编写于
3月 08, 2019
作者:
Z
zhangyang0701
提交者:
GitHub
3月 08, 2019
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #1480 from zhangyang0701/develop
add new interface function for FPGA track close
#1479
上级
a94ebee8
67d1a8a4
变更
9
隐藏空白更改
内联
并排
Showing
9 changed file
with
57 addition
and
40 deletion
+57
-40
src/framework/executor.cpp
src/framework/executor.cpp
+10
-5
src/framework/executor.h
src/framework/executor.h
+1
-0
src/io/api_paddle_mobile.cc
src/io/api_paddle_mobile.cc
+14
-3
src/io/api_paddle_mobile.h
src/io/api_paddle_mobile.h
+2
-0
src/io/paddle_inference_api.h
src/io/paddle_inference_api.h
+2
-2
src/io/paddle_mobile.cpp
src/io/paddle_mobile.cpp
+6
-0
src/io/paddle_mobile.h
src/io/paddle_mobile.h
+1
-0
test/fpga/test_rfcn.cpp
test/fpga/test_rfcn.cpp
+3
-26
test/fpga/test_rfcn_api.cpp
test/fpga/test_rfcn_api.cpp
+18
-4
未找到文件。
src/framework/executor.cpp
浏览文件 @
efd49e13
...
...
@@ -505,18 +505,23 @@ void Executor<Device, T>::GetResults(std::vector<void *> *v) {
template
<
typename
Device
,
typename
T
>
void
Executor
<
Device
,
T
>::
GetTensorResults
(
std
::
vector
<
framework
::
Tensor
*>
*
v
)
{
auto
output_size
=
v
->
size
();
PADDLE_MOBILE_ENFORCE
(
output_size
>
0
,
"Empty output"
);
auto
vars
=
program_
.
scope
->
VarContain
(
"fetch"
);
PADDLE_MOBILE_ENFORCE
(
output_size
==
vars
.
size
(),
"output data number not correct"
);
auto
output_size
=
vars
.
size
();
for
(
int
i
=
0
;
i
<
output_size
;
i
++
)
{
auto
var
=
program_
.
scope
->
Var
(
"fetch"
,
i
);
auto
fetch_tensor
=
var
->
template
GetMutable
<
LoDTensor
>();
(
*
v
)[
i
]
=
fetch_tensor
;
v
->
push_back
(
fetch_tensor
)
;
}
}
template
<
typename
Device
,
typename
T
>
framework
::
Tensor
*
Executor
<
Device
,
T
>::
GetTensorByName
(
const
std
::
string
&
name
)
{
auto
var
=
program_
.
scope
->
Var
(
name
);
return
var
->
template
GetMutable
<
LoDTensor
>();
};
template
<
typename
Device
,
typename
T
>
std
::
shared_ptr
<
Tensor
>
Executor
<
Device
,
T
>::
FetchResult
(
int
id
)
{
auto
&
ops
=
ops_of_block_
[
0
];
...
...
src/framework/executor.h
浏览文件 @
efd49e13
...
...
@@ -57,6 +57,7 @@ class Executor {
void
GetResults
(
std
::
vector
<
void
*>
*
v
);
void
GetTensorResults
(
std
::
vector
<
framework
::
Tensor
*>
*
v
);
framework
::
Tensor
*
GetTensorByName
(
const
std
::
string
&
name
);
std
::
shared_ptr
<
Tensor
>
FetchResult
(
int
id
=
-
1
);
void
Predict_From_To
(
int
start
=
0
,
int
end
=
-
1
);
...
...
src/io/api_paddle_mobile.cc
浏览文件 @
efd49e13
...
...
@@ -151,15 +151,26 @@ void PaddleMobilePredictor<Device, T>::FeedPaddleTensors(
template
<
typename
Device
,
typename
T
>
void
PaddleMobilePredictor
<
Device
,
T
>::
FetchPaddleTensors
(
std
::
vector
<
PaddleTensor
>
*
outputs
)
{
auto
num
=
outputs
->
size
();
PADDLE_MOBILE_ENFORCE
(
num
>
0
,
"0 output pointers is not permitted"
);
std
::
vector
<
framework
::
Tensor
*>
tensors
(
num
,
nullptr
);
// auto num = outputs->size();
// PADDLE_MOBILE_ENFORCE(num > 0, "0 output pointers is not permitted");
// std::vector<framework::Tensor *> tensors(num, nullptr);
outputs
->
clear
();
std
::
vector
<
framework
::
Tensor
*>
tensors
;
paddle_mobile_
->
GetTensorResults
(
&
tensors
);
auto
num
=
tensors
.
size
();
outputs
->
resize
(
num
,
PaddleTensor
());
for
(
int
i
=
0
;
i
<
num
;
i
++
)
{
ConvertTensors
(
*
tensors
[
i
],
&
(
*
outputs
)[
i
]);
}
}
template
<
typename
Device
,
typename
T
>
void
PaddleMobilePredictor
<
Device
,
T
>::
GetPaddleTensor
(
const
std
::
string
&
name
,
PaddleTensor
*
output
)
{
framework
::
Tensor
*
t
=
paddle_mobile_
->
GetTensorByName
(
name
);
ConvertTensors
(
*
t
,
output
);
};
template
<
typename
Device
,
typename
T
>
void
PaddleMobilePredictor
<
Device
,
T
>::
FeedData
(
const
std
::
vector
<
void
*>
&
inputs
)
{
...
...
src/io/api_paddle_mobile.h
浏览文件 @
efd49e13
...
...
@@ -37,6 +37,8 @@ class PaddleMobilePredictor : public PaddlePredictor {
void
Predict_From_To
(
int
start
,
int
end
)
override
;
void
FeedPaddleTensors
(
const
std
::
vector
<
PaddleTensor
>&
inputs
)
override
;
void
FetchPaddleTensors
(
std
::
vector
<
PaddleTensor
>*
outputs
)
override
;
void
GetPaddleTensor
(
const
std
::
string
&
name
,
PaddleTensor
*
output
)
override
;
#endif
~
PaddleMobilePredictor
()
override
;
...
...
src/io/paddle_inference_api.h
浏览文件 @
efd49e13
...
...
@@ -27,8 +27,6 @@ limitations under the License. */
#include <typeindex>
#include <vector>
// #define PADDLE_MOBILE_FPGA
namespace
paddle_mobile
{
#ifdef PADDLE_MOBILE_FPGA
...
...
@@ -133,6 +131,8 @@ class PaddlePredictor {
virtual
void
Predict_From_To
(
int
start
,
int
end
)
=
0
;
virtual
void
FeedPaddleTensors
(
const
std
::
vector
<
PaddleTensor
>&
inputs
)
=
0
;
virtual
void
FetchPaddleTensors
(
std
::
vector
<
PaddleTensor
>*
outputs
)
=
0
;
virtual
void
GetPaddleTensor
(
const
std
::
string
&
name
,
PaddleTensor
*
output
)
=
0
;
#endif
protected:
...
...
src/io/paddle_mobile.cpp
浏览文件 @
efd49e13
...
...
@@ -249,6 +249,12 @@ void PaddleMobile<Device, T>::GetTensorResults(
executor_
->
GetTensorResults
(
v
);
}
template
<
typename
Device
,
typename
T
>
framework
::
Tensor
*
PaddleMobile
<
Device
,
T
>::
GetTensorByName
(
const
std
::
string
&
name
)
{
return
executor_
->
GetTensorByName
(
name
);
};
template
<
typename
Device
,
typename
T
>
std
::
shared_ptr
<
framework
::
Tensor
>
PaddleMobile
<
Device
,
T
>::
FetchResult
(
int
id
)
{
...
...
src/io/paddle_mobile.h
浏览文件 @
efd49e13
...
...
@@ -95,6 +95,7 @@ class PaddleMobile {
void
GetResults
(
std
::
vector
<
void
*>
*
v
);
void
GetTensorResults
(
std
::
vector
<
framework
::
Tensor
*>
*
v
);
framework
::
Tensor
*
GetTensorByName
(
const
std
::
string
&
name
);
std
::
shared_ptr
<
framework
::
Tensor
>
FetchResult
(
int
id
=
-
1
);
void
Predict_From_To
(
int
start
=
0
,
int
end
=
-
1
);
...
...
test/fpga/test_rfcn.cpp
浏览文件 @
efd49e13
...
...
@@ -133,39 +133,16 @@ int main() {
readStream
(
g_image_src_float
,
reinterpret_cast
<
char
*>
(
img
));
std
::
vector
<
void
*>
v
(
3
,
nullptr
);
paddle_mobile
.
FeedData
(
{
img_info
,
img
}
);
paddle_mobile
.
FeedData
(
std
::
vector
<
void
*>
({
img_info
,
img
})
);
paddle_mobile
.
Predict_To
(
-
1
);
for
(
int
i
=
5
5
;
i
<
69
;
i
++
)
{
for
(
int
i
=
6
5
;
i
<
69
;
i
++
)
{
auto
tensor_ptr
=
paddle_mobile
.
FetchResult
(
i
);
std
::
string
saveName
=
"rfcn_"
+
std
::
to_string
(
i
);
// if(i != 58)
paddle_mobile
::
fpga
::
fpga_invalidate
((
*
tensor_ptr
).
get_data
(),
tensor_ptr
->
numel
()
*
sizeof
(
float
));
// tensor_ptr->numel() * sizeof(float));
if
((
i
==
48
)
||
(
i
==
47
))
{
dump_stride
(
saveName
,
(
*
tensor_ptr
),
20
,
false
);
// 20);//tensor_ptr->numel());
}
else
if
(
i
==
55
)
{
dump_stride
(
saveName
,
(
*
tensor_ptr
),
tensor_ptr
->
numel
(),
true
);
// 20);//tensor_ptr->numel());
}
else
{
dump_stride
(
saveName
,
(
*
tensor_ptr
),
tensor_ptr
->
numel
(),
true
);
// 20);//tensor_ptr->numel());
}
/* float result = 0;
std::string str = "softmax_input_data";
float* data =
static_cast<float*>(fpga::fpga_malloc(tensor_ptr->numel() *
sizeof(float))); str = "softmax_output_data"; auto output_ptr =
static_cast<half*>((*tensor_ptr).get_data()); for (int idx = 0; idx <
tensor_ptr->numel(); ++idx)
{
data[idx] = fpga::fp16_2_fp32(output_ptr[idx]);
}
fpga::savefile<float>(str,data, tensor_ptr->numel(), result ); */
dump_stride
(
saveName
,
(
*
tensor_ptr
),
tensor_ptr
->
numel
(),
true
);
}
// paddle_mobile.GetResults(&v);
DLOG
<<
"Computation done"
;
fpga
::
fpga_free
(
img
);
...
...
test/fpga/test_rfcn_api.cpp
浏览文件 @
efd49e13
...
...
@@ -12,6 +12,9 @@ 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. */
#ifndef PADDLE_MOBILE_FPGA
#define PADDLE_MOBILE_FPGA
#endif
#include <fstream>
#include <iostream>
#include "../../src/io/paddle_inference_api.h"
...
...
@@ -59,14 +62,14 @@ int main() {
CreatePaddlePredictor
<
PaddleMobileConfig
,
PaddleEngineKind
::
kPaddleMobile
>
(
config
);
std
::
cout
<<
"
after
loading model"
<<
std
::
endl
;
std
::
cout
<<
"
Finishing
loading model"
<<
std
::
endl
;
float
img_info
[
3
]
=
{
768
,
1536
,
768.0
f
/
960.0
f
};
int
img_length
=
768
*
1536
*
3
;
auto
img
=
reinterpret_cast
<
float
*>
(
fpga_malloc
(
img_length
*
sizeof
(
float
)));
readStream
(
g_image
,
reinterpret_cast
<
char
*>
(
img
));
std
::
cout
<<
"
after
initializing data"
<<
std
::
endl
;
std
::
cout
<<
"
Finishing
initializing data"
<<
std
::
endl
;
/*
predictor->FeedData({img_info, img});
predictor->Predict_From_To(0, -1);
...
...
@@ -110,8 +113,10 @@ int main() {
predictor
->
Predict_From_To
(
0
,
-
1
);
std
::
cout
<<
"Finishing predicting "
<<
std
::
endl
;
std
::
vector
<
PaddleTensor
>
v
(
3
,
PaddleTensor
());
predictor
->
FetchPaddleTensors
(
&
v
);
std
::
vector
<
PaddleTensor
>
v
;
// No need to initialize v
predictor
->
FetchPaddleTensors
(
&
v
);
// Old data in v will be cleared
std
::
cout
<<
"Output number is "
<<
v
.
size
()
<<
std
::
endl
;
auto
post_nms
=
v
[
0
].
data
.
length
()
/
sizeof
(
float
)
/
8
;
for
(
int
num
=
0
;
num
<
post_nms
;
num
++
)
{
for
(
int
i
=
0
;
i
<
8
;
i
++
)
{
...
...
@@ -131,5 +136,14 @@ int main() {
std
::
cout
<<
p
[
num
*
4
+
i
]
<<
std
::
endl
;
}
}
std
::
cout
<<
"Finish getting vector values"
<<
std
::
endl
;
PaddleTensor
tensor
;
predictor
->
GetPaddleTensor
(
"fetch2"
,
&
tensor
);
for
(
int
i
=
0
;
i
<
post_nms
;
i
++
)
{
auto
p
=
reinterpret_cast
<
float
*>
(
tensor
.
data
.
data
());
std
::
cout
<<
p
[
+
i
]
<<
std
::
endl
;
}
return
0
;
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录