Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
PaddleX
提交
df9645e4
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看板
未验证
提交
df9645e4
编写于
7月 13, 2020
作者:
J
Jason
提交者:
GitHub
7月 13, 2020
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #218 from joey12300/develop
encapsulate GenerateColormap in Visualize
上级
c1c91a73
398b7e46
变更
5
显示空白变更内容
内联
并排
Showing
5 changed file
with
9 addition
and
92 deletion
+9
-92
deploy/cpp/demo/classifier.cpp
deploy/cpp/demo/classifier.cpp
+0
-26
deploy/cpp/demo/detector.cpp
deploy/cpp/demo/detector.cpp
+2
-29
deploy/cpp/demo/segmenter.cpp
deploy/cpp/demo/segmenter.cpp
+2
-29
deploy/cpp/include/paddlex/visualize.h
deploy/cpp/include/paddlex/visualize.h
+2
-5
deploy/cpp/src/visualize.cpp
deploy/cpp/src/visualize.cpp
+3
-3
未找到文件。
deploy/cpp/demo/classifier.cpp
浏览文件 @
df9645e4
...
...
@@ -62,8 +62,6 @@ int main(int argc, char** argv) {
FLAGS_use_ir_optim
);
// 进行预测
double
total_running_time_s
=
0.0
;
double
total_imread_time_s
=
0.0
;
int
imgs
=
1
;
if
(
FLAGS_image_list
!=
""
)
{
std
::
ifstream
inf
(
FLAGS_image_list
);
...
...
@@ -79,7 +77,6 @@ int main(int argc, char** argv) {
}
imgs
=
image_paths
.
size
();
for
(
int
i
=
0
;
i
<
image_paths
.
size
();
i
+=
FLAGS_batch_size
)
{
auto
start
=
system_clock
::
now
();
// 读图像
int
im_vec_size
=
std
::
min
(
static_cast
<
int
>
(
image_paths
.
size
()),
i
+
FLAGS_batch_size
);
...
...
@@ -91,19 +88,7 @@ int main(int argc, char** argv) {
for
(
int
j
=
i
;
j
<
im_vec_size
;
++
j
)
{
im_vec
[
j
-
i
]
=
std
::
move
(
cv
::
imread
(
image_paths
[
j
],
1
));
}
auto
imread_end
=
system_clock
::
now
();
model
.
predict
(
im_vec
,
&
results
,
thread_num
);
auto
imread_duration
=
duration_cast
<
microseconds
>
(
imread_end
-
start
);
total_imread_time_s
+=
static_cast
<
double
>
(
imread_duration
.
count
())
*
microseconds
::
period
::
num
/
microseconds
::
period
::
den
;
auto
end
=
system_clock
::
now
();
auto
duration
=
duration_cast
<
microseconds
>
(
end
-
start
);
total_running_time_s
+=
static_cast
<
double
>
(
duration
.
count
())
*
microseconds
::
period
::
num
/
microseconds
::
period
::
den
;
for
(
int
j
=
i
;
j
<
im_vec_size
;
++
j
)
{
std
::
cout
<<
"Path:"
<<
image_paths
[
j
]
<<
", predict label: "
<<
results
[
j
-
i
].
category
...
...
@@ -112,23 +97,12 @@ int main(int argc, char** argv) {
}
}
}
else
{
auto
start
=
system_clock
::
now
();
PaddleX
::
ClsResult
result
;
cv
::
Mat
im
=
cv
::
imread
(
FLAGS_image
,
1
);
model
.
predict
(
im
,
&
result
);
auto
end
=
system_clock
::
now
();
auto
duration
=
duration_cast
<
microseconds
>
(
end
-
start
);
total_running_time_s
+=
static_cast
<
double
>
(
duration
.
count
())
*
microseconds
::
period
::
num
/
microseconds
::
period
::
den
;
std
::
cout
<<
"Predict label: "
<<
result
.
category
<<
", label_id:"
<<
result
.
category_id
<<
", score: "
<<
result
.
score
<<
std
::
endl
;
}
std
::
cout
<<
"Total running time: "
<<
total_running_time_s
<<
" s, average running time: "
<<
total_running_time_s
/
imgs
<<
" s/img, total read img time: "
<<
total_imread_time_s
<<
" s, average read time: "
<<
total_imread_time_s
/
imgs
<<
" s/img, batch_size = "
<<
FLAGS_batch_size
<<
std
::
endl
;
return
0
;
}
deploy/cpp/demo/detector.cpp
浏览文件 @
df9645e4
...
...
@@ -65,11 +65,7 @@ int main(int argc, char** argv) {
FLAGS_gpu_id
,
FLAGS_key
,
FLAGS_use_ir_optim
);
double
total_running_time_s
=
0.0
;
double
total_imread_time_s
=
0.0
;
int
imgs
=
1
;
auto
colormap
=
PaddleX
::
GenerateColorMap
(
model
.
labels
.
size
());
std
::
string
save_dir
=
"output"
;
// 进行预测
if
(
FLAGS_image_list
!=
""
)
{
...
...
@@ -85,7 +81,6 @@ int main(int argc, char** argv) {
}
imgs
=
image_paths
.
size
();
for
(
int
i
=
0
;
i
<
image_paths
.
size
();
i
+=
FLAGS_batch_size
)
{
auto
start
=
system_clock
::
now
();
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
);
...
...
@@ -96,17 +91,7 @@ int main(int argc, char** argv) {
for
(
int
j
=
i
;
j
<
im_vec_size
;
++
j
)
{
im_vec
[
j
-
i
]
=
std
::
move
(
cv
::
imread
(
image_paths
[
j
],
1
));
}
auto
imread_end
=
system_clock
::
now
();
model
.
predict
(
im_vec
,
&
results
,
thread_num
);
auto
imread_duration
=
duration_cast
<
microseconds
>
(
imread_end
-
start
);
total_imread_time_s
+=
static_cast
<
double
>
(
imread_duration
.
count
())
*
microseconds
::
period
::
num
/
microseconds
::
period
::
den
;
auto
end
=
system_clock
::
now
();
auto
duration
=
duration_cast
<
microseconds
>
(
end
-
start
);
total_running_time_s
+=
static_cast
<
double
>
(
duration
.
count
())
*
microseconds
::
period
::
num
/
microseconds
::
period
::
den
;
// 输出结果目标框
for
(
int
j
=
0
;
j
<
im_vec_size
-
i
;
++
j
)
{
for
(
int
k
=
0
;
k
<
results
[
j
].
boxes
.
size
();
++
k
)
{
...
...
@@ -124,7 +109,7 @@ int main(int argc, char** argv) {
// 可视化
for
(
int
j
=
0
;
j
<
im_vec_size
-
i
;
++
j
)
{
cv
::
Mat
vis_img
=
PaddleX
::
Visualize
(
im_vec
[
j
],
results
[
j
],
model
.
labels
,
colormap
,
FLAGS_threshold
);
im_vec
[
j
],
results
[
j
],
model
.
labels
,
FLAGS_threshold
);
std
::
string
save_path
=
PaddleX
::
generate_save_path
(
FLAGS_save_dir
,
image_paths
[
i
+
j
]);
cv
::
imwrite
(
save_path
,
vis_img
);
...
...
@@ -132,15 +117,9 @@ int main(int argc, char** argv) {
}
}
}
else
{
auto
start
=
system_clock
::
now
();
PaddleX
::
DetResult
result
;
cv
::
Mat
im
=
cv
::
imread
(
FLAGS_image
,
1
);
model
.
predict
(
im
,
&
result
);
auto
end
=
system_clock
::
now
();
auto
duration
=
duration_cast
<
microseconds
>
(
end
-
start
);
total_running_time_s
+=
static_cast
<
double
>
(
duration
.
count
())
*
microseconds
::
period
::
num
/
microseconds
::
period
::
den
;
// 输出结果目标框
for
(
int
i
=
0
;
i
<
result
.
boxes
.
size
();
++
i
)
{
std
::
cout
<<
"image file: "
<<
FLAGS_image
<<
std
::
endl
;
...
...
@@ -155,7 +134,7 @@ int main(int argc, char** argv) {
// 可视化
cv
::
Mat
vis_img
=
PaddleX
::
Visualize
(
im
,
result
,
model
.
labels
,
colormap
,
FLAGS_threshold
);
PaddleX
::
Visualize
(
im
,
result
,
model
.
labels
,
FLAGS_threshold
);
std
::
string
save_path
=
PaddleX
::
generate_save_path
(
FLAGS_save_dir
,
FLAGS_image
);
cv
::
imwrite
(
save_path
,
vis_img
);
...
...
@@ -163,11 +142,5 @@ int main(int argc, char** argv) {
std
::
cout
<<
"Visualized output saved as "
<<
save_path
<<
std
::
endl
;
}
std
::
cout
<<
"Total running time: "
<<
total_running_time_s
<<
" s, average running time: "
<<
total_running_time_s
/
imgs
<<
" s/img, total read img time: "
<<
total_imread_time_s
<<
" s, average read img time: "
<<
total_imread_time_s
/
imgs
<<
" s, batch_size = "
<<
FLAGS_batch_size
<<
std
::
endl
;
return
0
;
}
deploy/cpp/demo/segmenter.cpp
浏览文件 @
df9645e4
...
...
@@ -62,11 +62,7 @@ int main(int argc, char** argv) {
FLAGS_gpu_id
,
FLAGS_key
,
FLAGS_use_ir_optim
);
double
total_running_time_s
=
0.0
;
double
total_imread_time_s
=
0.0
;
int
imgs
=
1
;
auto
colormap
=
PaddleX
::
GenerateColorMap
(
model
.
labels
.
size
());
// 进行预测
if
(
FLAGS_image_list
!=
""
)
{
std
::
ifstream
inf
(
FLAGS_image_list
);
...
...
@@ -81,7 +77,6 @@ int main(int argc, char** argv) {
}
imgs
=
image_paths
.
size
();
for
(
int
i
=
0
;
i
<
image_paths
.
size
();
i
+=
FLAGS_batch_size
)
{
auto
start
=
system_clock
::
now
();
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
);
...
...
@@ -92,21 +87,11 @@ int main(int argc, char** argv) {
for
(
int
j
=
i
;
j
<
im_vec_size
;
++
j
)
{
im_vec
[
j
-
i
]
=
std
::
move
(
cv
::
imread
(
image_paths
[
j
],
1
));
}
auto
imread_end
=
system_clock
::
now
();
model
.
predict
(
im_vec
,
&
results
,
thread_num
);
auto
imread_duration
=
duration_cast
<
microseconds
>
(
imread_end
-
start
);
total_imread_time_s
+=
static_cast
<
double
>
(
imread_duration
.
count
())
*
microseconds
::
period
::
num
/
microseconds
::
period
::
den
;
auto
end
=
system_clock
::
now
();
auto
duration
=
duration_cast
<
microseconds
>
(
end
-
start
);
total_running_time_s
+=
static_cast
<
double
>
(
duration
.
count
())
*
microseconds
::
period
::
num
/
microseconds
::
period
::
den
;
// 可视化
for
(
int
j
=
0
;
j
<
im_vec_size
-
i
;
++
j
)
{
cv
::
Mat
vis_img
=
PaddleX
::
Visualize
(
im_vec
[
j
],
results
[
j
],
model
.
labels
,
colormap
);
PaddleX
::
Visualize
(
im_vec
[
j
],
results
[
j
],
model
.
labels
);
std
::
string
save_path
=
PaddleX
::
generate_save_path
(
FLAGS_save_dir
,
image_paths
[
i
+
j
]);
cv
::
imwrite
(
save_path
,
vis_img
);
...
...
@@ -114,28 +99,16 @@ int main(int argc, char** argv) {
}
}
}
else
{
auto
start
=
system_clock
::
now
();
PaddleX
::
SegResult
result
;
cv
::
Mat
im
=
cv
::
imread
(
FLAGS_image
,
1
);
model
.
predict
(
im
,
&
result
);
auto
end
=
system_clock
::
now
();
auto
duration
=
duration_cast
<
microseconds
>
(
end
-
start
);
total_running_time_s
+=
static_cast
<
double
>
(
duration
.
count
())
*
microseconds
::
period
::
num
/
microseconds
::
period
::
den
;
// 可视化
cv
::
Mat
vis_img
=
PaddleX
::
Visualize
(
im
,
result
,
model
.
labels
,
colormap
);
cv
::
Mat
vis_img
=
PaddleX
::
Visualize
(
im
,
result
,
model
.
labels
);
std
::
string
save_path
=
PaddleX
::
generate_save_path
(
FLAGS_save_dir
,
FLAGS_image
);
cv
::
imwrite
(
save_path
,
vis_img
);
result
.
clear
();
std
::
cout
<<
"Visualized output saved as "
<<
save_path
<<
std
::
endl
;
}
std
::
cout
<<
"Total running time: "
<<
total_running_time_s
<<
" s, average running time: "
<<
total_running_time_s
/
imgs
<<
" s/img, total read img time: "
<<
total_imread_time_s
<<
" s, average read img time: "
<<
total_imread_time_s
/
imgs
<<
" s, batch_size = "
<<
FLAGS_batch_size
<<
std
::
endl
;
return
0
;
}
deploy/cpp/include/paddlex/visualize.h
浏览文件 @
df9645e4
...
...
@@ -65,13 +65,12 @@ std::vector<int> GenerateColorMap(int num_class);
* @param img: initial image matrix
* @param results: the detection result
* @param labels: label map
* @param
colormap: visualization color map
* @param
threshold: minimum confidence to display
* @return visualized image matrix
* */
cv
::
Mat
Visualize
(
const
cv
::
Mat
&
img
,
const
DetResult
&
results
,
const
std
::
map
<
int
,
std
::
string
>&
labels
,
const
std
::
vector
<
int
>&
colormap
,
float
threshold
=
0.5
);
/*
...
...
@@ -81,13 +80,11 @@ cv::Mat Visualize(const cv::Mat& img,
* @param img: initial image matrix
* @param results: the detection result
* @param labels: label map
* @param colormap: visualization color map
* @return visualized image matrix
* */
cv
::
Mat
Visualize
(
const
cv
::
Mat
&
img
,
const
SegResult
&
result
,
const
std
::
map
<
int
,
std
::
string
>&
labels
,
const
std
::
vector
<
int
>&
colormap
);
const
std
::
map
<
int
,
std
::
string
>&
labels
);
/*
* @brief
...
...
deploy/cpp/src/visualize.cpp
浏览文件 @
df9645e4
...
...
@@ -34,8 +34,8 @@ std::vector<int> GenerateColorMap(int num_class) {
cv
::
Mat
Visualize
(
const
cv
::
Mat
&
img
,
const
DetResult
&
result
,
const
std
::
map
<
int
,
std
::
string
>&
labels
,
const
std
::
vector
<
int
>&
colormap
,
float
threshold
)
{
auto
colormap
=
GenerateColorMap
(
labels
.
size
());
cv
::
Mat
vis_img
=
img
.
clone
();
auto
boxes
=
result
.
boxes
;
for
(
int
i
=
0
;
i
<
boxes
.
size
();
++
i
)
{
...
...
@@ -107,8 +107,8 @@ cv::Mat Visualize(const cv::Mat& img,
cv
::
Mat
Visualize
(
const
cv
::
Mat
&
img
,
const
SegResult
&
result
,
const
std
::
map
<
int
,
std
::
string
>&
labels
,
const
std
::
vector
<
int
>&
colormap
)
{
const
std
::
map
<
int
,
std
::
string
>&
labels
)
{
auto
colormap
=
GenerateColorMap
(
labels
.
size
());
std
::
vector
<
uint8_t
>
label_map
(
result
.
label_map
.
data
.
begin
(),
result
.
label_map
.
data
.
end
());
cv
::
Mat
mask
(
result
.
label_map
.
shape
[
0
],
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录