Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
PaddleClas
提交
e5cc8d46
P
PaddleClas
项目概览
PaddlePaddle
/
PaddleClas
1 年多 前同步成功
通知
116
Star
4999
Fork
1114
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
19
列表
看板
标记
里程碑
合并请求
6
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
PaddleClas
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
19
Issue
19
列表
看板
标记
里程碑
合并请求
6
合并请求
6
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
未验证
提交
e5cc8d46
编写于
12月 18, 2020
作者:
L
littletomatodonkey
提交者:
GitHub
12月 18, 2020
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
add enable benchmark for lite (#503)
* add enable benchmark for lite * fix config
上级
70877e91
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
39 addition
and
26 deletion
+39
-26
deploy/lite/config.txt
deploy/lite/config.txt
+1
-0
deploy/lite/image_classfication.cpp
deploy/lite/image_classfication.cpp
+38
-26
未找到文件。
deploy/lite/config.txt
浏览文件 @
e5cc8d46
...
...
@@ -3,3 +3,4 @@ label_path ./imagenet1k_label_list.txt
resize_short_size 256
crop_size 224
visualize 0
enable_benchmark 1
deploy/lite/image_classfication.cpp
浏览文件 @
e5cc8d46
...
...
@@ -149,7 +149,7 @@ cv::Mat CenterCropImg(const cv::Mat &img, const int &crop_size) {
std
::
vector
<
RESULT
>
RunClasModel
(
std
::
shared_ptr
<
PaddlePredictor
>
predictor
,
const
cv
::
Mat
&
img
,
const
std
::
map
<
std
::
string
,
std
::
string
>
&
config
,
const
std
::
vector
<
std
::
string
>
&
word_labels
)
{
const
std
::
vector
<
std
::
string
>
&
word_labels
,
double
&
cost_time
)
{
// Read img
int
resize_short_size
=
stoi
(
config
.
at
(
"resize_short_size"
));
int
crop_size
=
stoi
(
config
.
at
(
"crop_size"
));
...
...
@@ -173,6 +173,7 @@ RunClasModel(std::shared_ptr<PaddlePredictor> predictor, const cv::Mat &img,
const
float
*
dimg
=
reinterpret_cast
<
const
float
*>
(
img_fp
.
data
);
NeonMeanScale
(
dimg
,
data0
,
img_fp
.
rows
*
img_fp
.
cols
,
mean
,
scale
);
auto
start
=
std
::
chrono
::
system_clock
::
now
();
// Run predictor
predictor
->
Run
();
...
...
@@ -180,6 +181,12 @@ RunClasModel(std::shared_ptr<PaddlePredictor> predictor, const cv::Mat &img,
std
::
unique_ptr
<
const
Tensor
>
output_tensor
(
std
::
move
(
predictor
->
GetOutput
(
0
)));
auto
*
output_data
=
output_tensor
->
data
<
float
>
();
auto
end
=
std
::
chrono
::
system_clock
::
now
();
auto
duration
=
std
::
chrono
::
duration_cast
<
std
::
chrono
::
microseconds
>
(
end
-
start
);
cost_time
=
double
(
duration
.
count
())
*
std
::
chrono
::
microseconds
::
period
::
num
/
std
::
chrono
::
microseconds
::
period
::
den
;
int
output_size
=
1
;
for
(
auto
dim
:
output_tensor
->
shape
())
{
...
...
@@ -294,6 +301,12 @@ int main(int argc, char **argv) {
auto
config
=
LoadConfigTxt
(
config_path
);
PrintConfig
(
config
);
double
elapsed_time
=
0.0
;
int
warmup_iter
=
10
;
bool
enable_benchmark
=
bool
(
stoi
(
config
.
at
(
"enable_benchmark"
)));
int
total_cnt
=
enable_benchmark
?
1000
:
1
;
std
::
string
clas_model_file
=
config
.
at
(
"clas_model_file"
);
std
::
string
label_path
=
config
.
at
(
"label_path"
);
...
...
@@ -301,32 +314,31 @@ int main(int argc, char **argv) {
std
::
vector
<
std
::
string
>
word_labels
=
LoadLabels
(
label_path
);
auto
clas_predictor
=
LoadModel
(
clas_model_file
);
auto
start
=
std
::
chrono
::
system_clock
::
now
();
cv
::
Mat
srcimg
=
cv
::
imread
(
img_path
,
cv
::
IMREAD_COLOR
);
cv
::
cvtColor
(
srcimg
,
srcimg
,
cv
::
COLOR_BGR2RGB
);
std
::
vector
<
RESULT
>
results
=
RunClasModel
(
clas_predictor
,
srcimg
,
config
,
word_labels
);
std
::
cout
<<
"===clas result for image: "
<<
img_path
<<
"==="
<<
std
::
endl
;
for
(
int
i
=
0
;
i
<
results
.
size
();
i
++
)
{
std
::
cout
<<
"
\t
"
<<
"Top-"
<<
i
+
1
<<
", class_id: "
<<
results
[
i
].
class_id
<<
", class_name: "
<<
results
[
i
].
class_name
<<
", score: "
<<
results
[
i
].
score
<<
std
::
endl
;
for
(
int
j
=
0
;
j
<
total_cnt
;
++
j
)
{
cv
::
Mat
srcimg
=
cv
::
imread
(
img_path
,
cv
::
IMREAD_COLOR
);
cv
::
cvtColor
(
srcimg
,
srcimg
,
cv
::
COLOR_BGR2RGB
);
double
run_time
=
0
;
std
::
vector
<
RESULT
>
results
=
RunClasModel
(
clas_predictor
,
srcimg
,
config
,
word_labels
,
run_time
);
std
::
cout
<<
"===clas result for image: "
<<
img_path
<<
"==="
<<
std
::
endl
;
for
(
int
i
=
0
;
i
<
results
.
size
();
i
++
)
{
std
::
cout
<<
"
\t
"
<<
"Top-"
<<
i
+
1
<<
", class_id: "
<<
results
[
i
].
class_id
<<
", class_name: "
<<
results
[
i
].
class_name
<<
", score: "
<<
results
[
i
].
score
<<
std
::
endl
;
}
if
(
j
>=
warmup_iter
)
{
elapsed_time
+=
run_time
;
std
::
cout
<<
"Current image path: "
<<
img_path
<<
std
::
endl
;
std
::
cout
<<
"Current time cost: "
<<
run_time
<<
" s, "
<<
"average time cost in all: "
<<
elapsed_time
/
(
j
+
1
-
warmup_iter
)
<<
" s."
<<
std
::
endl
;
}
else
{
std
::
cout
<<
"Current time cost: "
<<
run_time
<<
" s."
<<
std
::
endl
;
}
}
auto
end
=
std
::
chrono
::
system_clock
::
now
();
auto
duration
=
std
::
chrono
::
duration_cast
<
std
::
chrono
::
microseconds
>
(
end
-
start
);
std
::
cout
<<
"Cost "
<<
double
(
duration
.
count
())
*
std
::
chrono
::
microseconds
::
period
::
num
/
std
::
chrono
::
microseconds
::
period
::
den
<<
" s"
<<
std
::
endl
;
return
0
;
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录