Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
PaddleSeg
提交
f10169ae
P
PaddleSeg
项目概览
PaddlePaddle
/
PaddleSeg
通知
285
Star
8
Fork
1
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
53
列表
看板
标记
里程碑
合并请求
3
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
PaddleSeg
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
53
Issue
53
列表
看板
标记
里程碑
合并请求
3
合并请求
3
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
f10169ae
编写于
9月 30, 2019
作者:
S
sjtubinlong
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
improve c++ normalize and argmax performance
上级
5b80d74e
变更
5
显示空白变更内容
内联
并排
Showing
5 changed file
with
64 addition
and
36 deletion
+64
-36
inference/CMakeLists.txt
inference/CMakeLists.txt
+1
-1
inference/predictor/seg_predictor.cpp
inference/predictor/seg_predictor.cpp
+4
-20
inference/preprocessor/preprocessor_seg.cpp
inference/preprocessor/preprocessor_seg.cpp
+1
-15
inference/preprocessor/preprocessor_seg.h
inference/preprocessor/preprocessor_seg.h
+1
-0
inference/utils/utils.h
inference/utils/utils.h
+57
-0
未找到文件。
inference/CMakeLists.txt
浏览文件 @
f10169ae
...
...
@@ -82,7 +82,7 @@ if (WIN32)
add_definitions
(
-DSTATIC_LIB
)
endif
()
else
()
set
(
CMAKE_CXX_FLAGS
"
${
CMAKE_CXX_FLAGS
}
-o2 -std=c++11"
)
set
(
CMAKE_CXX_FLAGS
"
${
CMAKE_CXX_FLAGS
}
-o2 -
fopenmp -
std=c++11"
)
set
(
CMAKE_STATIC_LIBRARY_PREFIX
""
)
endif
()
...
...
inference/predictor/seg_predictor.cpp
浏览文件 @
f10169ae
#include "seg_predictor.h"
#include <unsupported/Eigen/CXX11/Tensor>
namespace
PaddleSolution
{
...
...
@@ -78,26 +79,8 @@ namespace PaddleSolution {
//post process
_mask
.
clear
();
_scoremap
.
clear
();
int
out_img_len
=
eval_height
*
eval_width
;
for
(
int
i
=
0
;
i
<
out_img_len
;
++
i
)
{
float
max_value
=
-
1
;
int
label
=
0
;
for
(
int
j
=
0
;
j
<
eval_num_class
;
++
j
)
{
int
index
=
i
+
j
*
out_img_len
;
if
(
index
>=
blob_out_len
)
{
break
;
}
float
value
=
p_out
[
index
];
if
(
value
>
max_value
)
{
max_value
=
value
;
label
=
j
;
}
}
if
(
label
==
0
)
max_value
=
0
;
_mask
[
i
]
=
uchar
(
label
);
_scoremap
[
i
]
=
uchar
(
max_value
*
255
);
}
std
::
vector
<
int
>
out_shape
{
eval_num_class
,
eval_height
,
eval_width
};
utils
::
argmax
(
p_out
,
out_shape
,
_mask
,
_scoremap
);
cv
::
Mat
mask_png
=
cv
::
Mat
(
eval_height
,
eval_width
,
CV_8UC1
);
mask_png
.
data
=
_mask
.
data
();
std
::
string
nname
(
fname
);
...
...
@@ -251,6 +234,7 @@ namespace PaddleSolution {
int
idx
=
u
*
default_batch_size
+
i
;
imgs_batch
.
push_back
(
imgs
[
idx
]);
}
if
(
!
_preprocessor
->
batch_process
(
imgs_batch
,
input_buffer
.
data
(),
org_height
.
data
(),
org_width
.
data
()))
{
return
-
1
;
}
...
...
inference/preprocessor/preprocessor_seg.cpp
浏览文件 @
f10169ae
...
...
@@ -32,21 +32,7 @@ namespace PaddleSolution {
if
(
*
ori_h
!=
rh
||
*
ori_w
!=
rw
)
{
cv
::
resize
(
im
,
im
,
resize_size
,
0
,
0
,
cv
::
INTER_LINEAR
);
}
float
*
pmean
=
_config
->
_mean
.
data
();
float
*
pscale
=
_config
->
_std
.
data
();
for
(
int
h
=
0
;
h
<
rh
;
++
h
)
{
const
uchar
*
ptr
=
im
.
ptr
<
uchar
>
(
h
);
int
im_index
=
0
;
for
(
int
w
=
0
;
w
<
rw
;
++
w
)
{
for
(
int
c
=
0
;
c
<
channels
;
++
c
)
{
int
top_index
=
(
c
*
rh
+
h
)
*
rw
+
w
;
float
pixel
=
static_cast
<
float
>
(
ptr
[
im_index
++
]);
pixel
=
(
pixel
/
255
-
pmean
[
c
])
/
pscale
[
c
];
data
[
top_index
]
=
pixel
;
}
}
}
utils
::
normalize
(
im
,
data
,
_config
->
_mean
,
_config
->
_std
);
return
true
;
}
...
...
inference/preprocessor/preprocessor_seg.h
浏览文件 @
f10169ae
#pragma once
#include "preprocessor.h"
#include "utils/utils.h"
namespace
PaddleSolution
{
...
...
inference/utils/utils.h
浏览文件 @
f10169ae
...
...
@@ -4,6 +4,10 @@
#include <vector>
#include <string>
#include <opencv2/core/core.hpp>
#include <opencv2/imgproc/imgproc.hpp>
#include <opencv2/highgui/highgui.hpp>
#ifdef _WIN32
#include <filesystem>
#else
...
...
@@ -59,5 +63,58 @@ namespace PaddleSolution {
return
imgs
;
}
#endif
// normalize and HWC_BGR -> CHW_RGB
inline
void
normalize
(
cv
::
Mat
&
im
,
float
*
data
,
std
::
vector
<
float
>&
fmean
,
std
::
vector
<
float
>&
fstd
)
{
int
rh
=
im
.
rows
;
int
rw
=
im
.
cols
;
int
rc
=
im
.
channels
();
double
normf
=
(
double
)
1.0
/
255.0
;
#pragma omp parallel for
for
(
int
h
=
0
;
h
<
rh
;
++
h
)
{
const
uchar
*
ptr
=
im
.
ptr
<
uchar
>
(
h
);
int
im_index
=
0
;
for
(
int
w
=
0
;
w
<
rw
;
++
w
)
{
for
(
int
c
=
0
;
c
<
rc
;
++
c
)
{
int
top_index
=
(
c
*
rh
+
h
)
*
rw
+
w
;
float
pixel
=
static_cast
<
float
>
(
ptr
[
im_index
++
]);
pixel
=
(
pixel
*
normf
-
fmean
[
c
])
/
fstd
[
c
];
data
[
top_index
]
=
pixel
;
}
}
}
}
// argmax
inline
void
argmax
(
float
*
out
,
std
::
vector
<
int
>&
shape
,
std
::
vector
<
uchar
>&
mask
,
std
::
vector
<
uchar
>&
scoremap
)
{
int
out_img_len
=
shape
[
1
]
*
shape
[
2
];
int
blob_out_len
=
out_img_len
*
shape
[
0
];
/*
Eigen::TensorMap<Eigen::Tensor<float, 3>> out_3d(out, shape[0], shape[1], shape[2]);
Eigen::Tensor<Eigen::DenseIndex, 2> argmax = out_3d.argmax(0);
*/
float
max_value
=
-
1
;
int
label
=
0
;
#pragma omp parallel private(label)
for
(
int
i
=
0
;
i
<
out_img_len
;
++
i
)
{
max_value
=
-
1
;
label
=
0
;
#pragma omp for reduction(max : max_value)
for
(
int
j
=
0
;
j
<
shape
[
0
];
++
j
)
{
int
index
=
i
+
j
*
out_img_len
;
if
(
index
>=
blob_out_len
)
{
continue
;
}
float
value
=
out
[
index
];
if
(
value
>
max_value
)
{
max_value
=
value
;
label
=
j
;
}
}
if
(
label
==
0
)
max_value
=
0
;
mask
[
i
]
=
uchar
(
label
);
scoremap
[
i
]
=
uchar
(
max_value
*
255
);
}
}
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录