Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
PaddleX
提交
764e8982
P
PaddleX
项目概览
PaddlePaddle
/
PaddleX
通知
138
Star
4
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
43
列表
看板
标记
里程碑
合并请求
5
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
PaddleX
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
43
Issue
43
列表
看板
标记
里程碑
合并请求
5
合并请求
5
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
764e8982
编写于
8月 05, 2020
作者:
F
FlyingQianMM
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
change chinese comments to english comments
上级
ff361bdf
变更
8
隐藏空白更改
内联
并排
Showing
8 changed file
with
51 addition
and
49 deletion
+51
-49
deploy/cpp/demo/classifier.cpp
deploy/cpp/demo/classifier.cpp
+4
-4
deploy/cpp/demo/detector.cpp
deploy/cpp/demo/detector.cpp
+7
-7
deploy/cpp/demo/segmenter.cpp
deploy/cpp/demo/segmenter.cpp
+5
-5
deploy/cpp/demo/video_classifier.cpp
deploy/cpp/demo/video_classifier.cpp
+7
-7
deploy/cpp/demo/video_detector.cpp
deploy/cpp/demo/video_detector.cpp
+8
-7
deploy/cpp/demo/video_segmenter.cpp
deploy/cpp/demo/video_segmenter.cpp
+8
-8
examples/human_segmentation/deploy/cpp/human_segmenter.cpp
examples/human_segmentation/deploy/cpp/human_segmenter.cpp
+9
-9
examples/meter_reader/deploy/cpp/meter_reader/meter_reader.cpp
...les/meter_reader/deploy/cpp/meter_reader/meter_reader.cpp
+3
-2
未找到文件。
deploy/cpp/demo/classifier.cpp
浏览文件 @
764e8982
...
...
@@ -51,7 +51,7 @@ int main(int argc, char** argv) {
return
-
1
;
}
//
加载模型
//
Load model
PaddleX
::
Model
model
;
model
.
Init
(
FLAGS_model_dir
,
FLAGS_use_gpu
,
...
...
@@ -59,7 +59,7 @@ int main(int argc, char** argv) {
FLAGS_gpu_id
,
FLAGS_key
);
//
进行预测
//
Predict
int
imgs
=
1
;
if
(
FLAGS_image_list
!=
""
)
{
std
::
ifstream
inf
(
FLAGS_image_list
);
...
...
@@ -67,7 +67,7 @@ int main(int argc, char** argv) {
std
::
cerr
<<
"Fail to open file "
<<
FLAGS_image_list
<<
std
::
endl
;
return
-
1
;
}
//
多batch预测
//
Mini-batch predict
std
::
string
image_path
;
std
::
vector
<
std
::
string
>
image_paths
;
while
(
getline
(
inf
,
image_path
))
{
...
...
@@ -75,7 +75,7 @@ int main(int argc, char** argv) {
}
imgs
=
image_paths
.
size
();
for
(
int
i
=
0
;
i
<
image_paths
.
size
();
i
+=
FLAGS_batch_size
)
{
//
读图像
//
Read image
int
im_vec_size
=
std
::
min
(
static_cast
<
int
>
(
image_paths
.
size
()),
i
+
FLAGS_batch_size
);
std
::
vector
<
cv
::
Mat
>
im_vec
(
im_vec_size
-
i
);
...
...
deploy/cpp/demo/detector.cpp
浏览文件 @
764e8982
...
...
@@ -45,7 +45,7 @@ DEFINE_int32(thread_num,
"Number of preprocessing threads"
);
int
main
(
int
argc
,
char
**
argv
)
{
//
解析命令行参数
//
Parsing command-line
google
::
ParseCommandLineFlags
(
&
argc
,
&
argv
,
true
);
if
(
FLAGS_model_dir
==
""
)
{
...
...
@@ -56,7 +56,7 @@ int main(int argc, char** argv) {
std
::
cerr
<<
"--image or --image_list need to be defined"
<<
std
::
endl
;
return
-
1
;
}
//
加载模型
//
Load model
PaddleX
::
Model
model
;
model
.
Init
(
FLAGS_model_dir
,
FLAGS_use_gpu
,
...
...
@@ -65,7 +65,7 @@ int main(int argc, char** argv) {
FLAGS_key
);
int
imgs
=
1
;
std
::
string
save_dir
=
"output"
;
//
进行预测
//
Predict
if
(
FLAGS_image_list
!=
""
)
{
std
::
ifstream
inf
(
FLAGS_image_list
);
if
(
!
inf
)
{
...
...
@@ -90,7 +90,7 @@ int main(int argc, char** argv) {
im_vec
[
j
-
i
]
=
std
::
move
(
cv
::
imread
(
image_paths
[
j
],
1
));
}
model
.
predict
(
im_vec
,
&
results
,
thread_num
);
//
输出结果目标框
//
Output predicted bounding boxes
for
(
int
j
=
0
;
j
<
im_vec_size
-
i
;
++
j
)
{
for
(
int
k
=
0
;
k
<
results
[
j
].
boxes
.
size
();
++
k
)
{
std
::
cout
<<
"image file: "
<<
image_paths
[
i
+
j
]
<<
", "
;
...
...
@@ -104,7 +104,7 @@ int main(int argc, char** argv) {
<<
results
[
j
].
boxes
[
k
].
coordinate
[
3
]
<<
")"
<<
std
::
endl
;
}
}
//
可视化
//
Visualize results
for
(
int
j
=
0
;
j
<
im_vec_size
-
i
;
++
j
)
{
cv
::
Mat
vis_img
=
PaddleX
::
Visualize
(
im_vec
[
j
],
results
[
j
],
model
.
labels
,
FLAGS_threshold
);
...
...
@@ -118,7 +118,7 @@ int main(int argc, char** argv) {
PaddleX
::
DetResult
result
;
cv
::
Mat
im
=
cv
::
imread
(
FLAGS_image
,
1
);
model
.
predict
(
im
,
&
result
);
//
输出结果目标框
//
Output predicted bounding boxes
for
(
int
i
=
0
;
i
<
result
.
boxes
.
size
();
++
i
)
{
std
::
cout
<<
"image file: "
<<
FLAGS_image
<<
std
::
endl
;
std
::
cout
<<
", predict label: "
<<
result
.
boxes
[
i
].
category
...
...
@@ -130,7 +130,7 @@ int main(int argc, char** argv) {
<<
result
.
boxes
[
i
].
coordinate
[
3
]
<<
")"
<<
std
::
endl
;
}
//
可视化
//
Visualize results
cv
::
Mat
vis_img
=
PaddleX
::
Visualize
(
im
,
result
,
model
.
labels
,
FLAGS_threshold
);
std
::
string
save_path
=
...
...
deploy/cpp/demo/segmenter.cpp
浏览文件 @
764e8982
...
...
@@ -41,7 +41,7 @@ DEFINE_int32(thread_num,
"Number of preprocessing threads"
);
int
main
(
int
argc
,
char
**
argv
)
{
//
解析命令行参数
//
Parsing command-line
google
::
ParseCommandLineFlags
(
&
argc
,
&
argv
,
true
);
if
(
FLAGS_model_dir
==
""
)
{
...
...
@@ -53,7 +53,7 @@ int main(int argc, char** argv) {
return
-
1
;
}
//
加载模型
//
Load model
PaddleX
::
Model
model
;
model
.
Init
(
FLAGS_model_dir
,
FLAGS_use_gpu
,
...
...
@@ -61,7 +61,7 @@ int main(int argc, char** argv) {
FLAGS_gpu_id
,
FLAGS_key
);
int
imgs
=
1
;
//
进行预测
//
Predict
if
(
FLAGS_image_list
!=
""
)
{
std
::
ifstream
inf
(
FLAGS_image_list
);
if
(
!
inf
)
{
...
...
@@ -86,7 +86,7 @@ int main(int argc, char** argv) {
im_vec
[
j
-
i
]
=
std
::
move
(
cv
::
imread
(
image_paths
[
j
],
1
));
}
model
.
predict
(
im_vec
,
&
results
,
thread_num
);
//
可视化
//
Visualize results
for
(
int
j
=
0
;
j
<
im_vec_size
-
i
;
++
j
)
{
cv
::
Mat
vis_img
=
PaddleX
::
Visualize
(
im_vec
[
j
],
results
[
j
],
model
.
labels
);
...
...
@@ -100,7 +100,7 @@ int main(int argc, char** argv) {
PaddleX
::
SegResult
result
;
cv
::
Mat
im
=
cv
::
imread
(
FLAGS_image
,
1
);
model
.
predict
(
im
,
&
result
);
//
可视化
//
Visualize results
cv
::
Mat
vis_img
=
PaddleX
::
Visualize
(
im
,
result
,
model
.
labels
);
std
::
string
save_path
=
PaddleX
::
generate_save_path
(
FLAGS_save_dir
,
FLAGS_image
);
...
...
deploy/cpp/demo/video_classifier.cpp
浏览文件 @
764e8982
...
...
@@ -57,7 +57,7 @@ int main(int argc, char** argv) {
return
-
1
;
}
//
加载模型
//
Load model
PaddleX
::
Model
model
;
model
.
Init
(
FLAGS_model_dir
,
FLAGS_use_gpu
,
...
...
@@ -65,7 +65,7 @@ int main(int argc, char** argv) {
FLAGS_gpu_id
,
FLAGS_key
);
//
打开视频流
//
Open video
cv
::
VideoCapture
capture
;
if
(
FLAGS_use_camera
)
{
capture
.
open
(
FLAGS_camera_id
);
...
...
@@ -85,11 +85,11 @@ int main(int argc, char** argv) {
}
}
//
创建
VideoWriter
//
Create a
VideoWriter
cv
::
VideoWriter
video_out
;
std
::
string
video_out_path
;
if
(
FLAGS_save_result
)
{
//
获取视频流信息: 分辨率, 帧率
//
Get video information: resolution, fps
int
video_width
=
static_cast
<
int
>
(
capture
.
get
(
CV_CAP_PROP_FRAME_WIDTH
));
int
video_height
=
static_cast
<
int
>
(
capture
.
get
(
CV_CAP_PROP_FRAME_HEIGHT
));
int
video_fps
=
static_cast
<
int
>
(
capture
.
get
(
CV_CAP_PROP_FPS
));
...
...
@@ -126,16 +126,16 @@ int main(int argc, char** argv) {
while
(
capture
.
read
(
frame
))
{
if
(
FLAGS_show_result
||
FLAGS_use_camera
)
{
key
=
cv
::
waitKey
(
1
);
//
按下ESC退出整个程序,保存视频文件到磁盘
//
When pressing `ESC`, then exit program and result video is saved
if
(
key
==
27
)
{
break
;
}
}
else
if
(
frame
.
empty
())
{
break
;
}
//
开始预测
//
Begin to predict
model
.
predict
(
frame
,
&
result
);
//
可视化
//
Visualize results
cv
::
Mat
vis_img
=
frame
.
clone
();
auto
colormap
=
PaddleX
::
GenerateColorMap
(
model
.
labels
.
size
());
int
c1
=
colormap
[
3
*
result
.
category_id
+
0
];
...
...
deploy/cpp/demo/video_detector.cpp
浏览文件 @
764e8982
...
...
@@ -48,7 +48,7 @@ DEFINE_double(threshold,
"The minimum scores of target boxes which are shown"
);
int
main
(
int
argc
,
char
**
argv
)
{
//
解析命令行参数
//
Parsing command-line
google
::
ParseCommandLineFlags
(
&
argc
,
&
argv
,
true
);
if
(
FLAGS_model_dir
==
""
)
{
...
...
@@ -59,14 +59,14 @@ int main(int argc, char** argv) {
std
::
cerr
<<
"--video_path or --use_camera need to be defined"
<<
std
::
endl
;
return
-
1
;
}
//
加载模型
//
Load model
PaddleX
::
Model
model
;
model
.
Init
(
FLAGS_model_dir
,
FLAGS_use_gpu
,
FLAGS_use_trt
,
FLAGS_gpu_id
,
FLAGS_key
);
//
打开视频流
//
Open video
cv
::
VideoCapture
capture
;
if
(
FLAGS_use_camera
)
{
capture
.
open
(
FLAGS_camera_id
);
...
...
@@ -86,11 +86,11 @@ int main(int argc, char** argv) {
}
}
//
创建
VideoWriter
//
Create a
VideoWriter
cv
::
VideoWriter
video_out
;
std
::
string
video_out_path
;
if
(
FLAGS_save_result
)
{
//
获取视频流信息: 分辨率, 帧率
//
Get video information: resolution, fps
int
video_width
=
static_cast
<
int
>
(
capture
.
get
(
CV_CAP_PROP_FRAME_WIDTH
));
int
video_height
=
static_cast
<
int
>
(
capture
.
get
(
CV_CAP_PROP_FRAME_HEIGHT
));
int
video_fps
=
static_cast
<
int
>
(
capture
.
get
(
CV_CAP_PROP_FPS
));
...
...
@@ -127,15 +127,16 @@ int main(int argc, char** argv) {
while
(
capture
.
read
(
frame
))
{
if
(
FLAGS_show_result
||
FLAGS_use_camera
)
{
key
=
cv
::
waitKey
(
1
);
//
按下ESC退出整个程序,保存视频文件到磁盘
//
When pressing `ESC`, then exit program and result video is saved
if
(
key
==
27
)
{
break
;
}
}
else
if
(
frame
.
empty
())
{
break
;
}
// Begin to predict
model
.
predict
(
frame
,
&
result
);
//
可视化
//
Visualize results
cv
::
Mat
vis_img
=
PaddleX
::
Visualize
(
frame
,
result
,
model
.
labels
,
FLAGS_threshold
);
if
(
FLAGS_show_result
||
FLAGS_use_camera
)
{
...
...
deploy/cpp/demo/video_segmenter.cpp
浏览文件 @
764e8982
...
...
@@ -45,7 +45,7 @@ DEFINE_bool(save_result, true, "save the result of each frame to a video");
DEFINE_string
(
save_dir
,
"output"
,
"Path to save visualized image"
);
int
main
(
int
argc
,
char
**
argv
)
{
//
解析命令行参数
//
Parsing command-line
google
::
ParseCommandLineFlags
(
&
argc
,
&
argv
,
true
);
if
(
FLAGS_model_dir
==
""
)
{
...
...
@@ -57,14 +57,14 @@ int main(int argc, char** argv) {
return
-
1
;
}
//
加载模型
//
Load model
PaddleX
::
Model
model
;
model
.
Init
(
FLAGS_model_dir
,
FLAGS_use_gpu
,
FLAGS_use_trt
,
FLAGS_gpu_id
,
FLAGS_key
);
//
打开视频流
//
Open video
cv
::
VideoCapture
capture
;
if
(
FLAGS_use_camera
)
{
capture
.
open
(
FLAGS_camera_id
);
...
...
@@ -85,11 +85,11 @@ int main(int argc, char** argv) {
}
//
创建
VideoWriter
//
Create a
VideoWriter
cv
::
VideoWriter
video_out
;
std
::
string
video_out_path
;
if
(
FLAGS_save_result
)
{
//
获取视频流信息: 分辨率, 帧率
//
Get video information: resolution, fps
int
video_width
=
static_cast
<
int
>
(
capture
.
get
(
CV_CAP_PROP_FRAME_WIDTH
));
int
video_height
=
static_cast
<
int
>
(
capture
.
get
(
CV_CAP_PROP_FRAME_HEIGHT
));
int
video_fps
=
static_cast
<
int
>
(
capture
.
get
(
CV_CAP_PROP_FPS
));
...
...
@@ -126,16 +126,16 @@ int main(int argc, char** argv) {
while
(
capture
.
read
(
frame
))
{
if
(
FLAGS_show_result
||
FLAGS_use_camera
)
{
key
=
cv
::
waitKey
(
1
);
//
按下ESC退出整个程序,保存视频文件到磁盘
//
When pressing `ESC`, then exit program and result video is saved
if
(
key
==
27
)
{
break
;
}
}
else
if
(
frame
.
empty
())
{
break
;
}
//
开始预测
//
Begin to predict
model
.
predict
(
frame
,
&
result
);
//
可视化
//
Visualize results
cv
::
Mat
vis_img
=
PaddleX
::
Visualize
(
frame
,
result
,
model
.
labels
);
if
(
FLAGS_show_result
||
FLAGS_use_camera
)
{
cv
::
imshow
(
"video_segmenter"
,
vis_img
);
...
...
examples/human_segmentation/deploy/cpp/human_segmenter.cpp
浏览文件 @
764e8982
...
...
@@ -46,7 +46,7 @@ DEFINE_bool(save_result, true, "save the result of each frame to a video");
DEFINE_string
(
save_dir
,
"output"
,
"Path to save visualized image"
);
int
main
(
int
argc
,
char
**
argv
)
{
//
解析命令行参数
//
Parsing command-line
google
::
ParseCommandLineFlags
(
&
argc
,
&
argv
,
true
);
if
(
FLAGS_model_dir
==
""
)
{
...
...
@@ -60,7 +60,7 @@ int main(int argc, char** argv) {
return
-
1
;
}
//
加载模型
//
Load model
PaddleX
::
Model
model
;
model
.
Init
(
FLAGS_model_dir
,
FLAGS_use_gpu
,
...
...
@@ -68,7 +68,7 @@ int main(int argc, char** argv) {
FLAGS_gpu_id
,
FLAGS_key
);
if
(
FLAGS_use_camera
||
FLAGS_video_path
!=
""
)
{
//
打开视频流
//
Open video
cv
::
VideoCapture
capture
;
if
(
FLAGS_use_camera
)
{
capture
.
open
(
FLAGS_camera_id
);
...
...
@@ -88,11 +88,11 @@ int main(int argc, char** argv) {
}
}
//
创建
VideoWriter
//
Create a
VideoWriter
cv
::
VideoWriter
video_out
;
std
::
string
video_out_path
;
if
(
FLAGS_save_result
)
{
//
获取视频流信息: 分辨率, 帧率
//
Get video information: resolution, fps
int
video_width
=
static_cast
<
int
>
(
capture
.
get
(
CV_CAP_PROP_FRAME_WIDTH
));
int
video_height
=
static_cast
<
int
>
(
capture
.
get
(
CV_CAP_PROP_FRAME_HEIGHT
));
...
...
@@ -129,16 +129,16 @@ int main(int argc, char** argv) {
while
(
capture
.
read
(
frame
))
{
if
(
FLAGS_show_result
||
FLAGS_use_camera
)
{
key
=
cv
::
waitKey
(
1
);
//
按下ESC退出整个程序,保存视频文件到磁盘
//
When pressing `ESC`, then exit program and result video is saved
if
(
key
==
27
)
{
break
;
}
}
else
if
(
frame
.
empty
())
{
break
;
}
//
开始预测
//
Begin to predict
model
.
predict
(
frame
,
&
result
);
//
可视化
//
Visualize results
std
::
vector
<
uint8_t
>
label_map
(
result
.
label_map
.
data
.
begin
(),
result
.
label_map
.
data
.
end
());
cv
::
Mat
mask
(
result
.
label_map
.
shape
[
0
],
...
...
@@ -178,7 +178,7 @@ int main(int argc, char** argv) {
PaddleX
::
SegResult
result
;
cv
::
Mat
im
=
cv
::
imread
(
FLAGS_image
,
1
);
model
.
predict
(
im
,
&
result
);
//
可视化
//
Visualize results
std
::
vector
<
uint8_t
>
label_map
(
result
.
label_map
.
data
.
begin
(),
result
.
label_map
.
data
.
end
());
cv
::
Mat
mask
(
result
.
label_map
.
shape
[
0
],
...
...
examples/meter_reader/deploy/cpp/meter_reader/meter_reader.cpp
浏览文件 @
764e8982
...
...
@@ -51,7 +51,8 @@ DEFINE_string(seg_key, "", "Segmenter model key of encryption");
DEFINE_string
(
image
,
""
,
"Path of test image file"
);
DEFINE_string
(
image_list
,
""
,
"Path of test image list file"
);
DEFINE_string
(
save_dir
,
"output"
,
"Path to save visualized image"
);
DEFINE_double
(
score_threshold
,
0.5
,
"Detected bbox whose score is lower than this threshlod is filtered"
);
DEFINE_double
(
score_threshold
,
0.5
,
"Detected bbox whose score is lower than this threshlod is filtered"
);
void
predict
(
const
cv
::
Mat
&
input_image
,
PaddleX
::
Model
*
det_model
,
PaddleX
::
Model
*
seg_model
,
const
std
::
string
save_dir
,
...
...
@@ -207,7 +208,7 @@ int main(int argc, char **argv) {
return
-
1
;
}
//
加载模型
//
Load model
PaddleX
::
Model
det_model
;
det_model
.
Init
(
FLAGS_det_model_dir
,
FLAGS_use_gpu
,
FLAGS_use_trt
,
FLAGS_gpu_id
,
FLAGS_det_key
);
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录