Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
PaddleDetection
提交
e1e02efe
P
PaddleDetection
项目概览
PaddlePaddle
/
PaddleDetection
大约 1 年 前同步成功
通知
695
Star
11112
Fork
2696
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
184
列表
看板
标记
里程碑
合并请求
40
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
PaddleDetection
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
184
Issue
184
列表
看板
标记
里程碑
合并请求
40
合并请求
40
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
未验证
提交
e1e02efe
编写于
6月 22, 2021
作者:
C
cnn
提交者:
GitHub
6月 22, 2021
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[dev] fix bug of cpp deploy when benchmark=True (#3392) (#3458)
* fix bug when benchmark=True * split warmup and repeat
上级
b8581b74
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
63 addition
and
50 deletion
+63
-50
deploy/cpp/src/main.cc
deploy/cpp/src/main.cc
+4
-1
deploy/cpp/src/object_detector.cc
deploy/cpp/src/object_detector.cc
+59
-49
未找到文件。
deploy/cpp/src/main.cc
浏览文件 @
e1e02efe
...
@@ -279,12 +279,15 @@ void PredictImage(const std::vector<std::string> all_img_paths,
...
@@ -279,12 +279,15 @@ void PredictImage(const std::vector<std::string> all_img_paths,
int
item_start_idx
=
0
;
int
item_start_idx
=
0
;
for
(
int
i
=
0
;
i
<
left_image_cnt
;
i
++
)
{
for
(
int
i
=
0
;
i
<
left_image_cnt
;
i
++
)
{
std
::
cout
<<
all_img_paths
.
at
(
idx
*
batch_size
+
i
)
<<
"
result"
<<
std
::
endl
;
std
::
cout
<<
all_img_paths
.
at
(
idx
*
batch_size
+
i
)
<<
"
bbox_num "
<<
bbox_num
[
i
]
<<
std
::
endl
;
if
(
bbox_num
[
i
]
<=
1
)
{
if
(
bbox_num
[
i
]
<=
1
)
{
continue
;
continue
;
}
}
for
(
int
j
=
0
;
j
<
bbox_num
[
i
];
j
++
)
{
for
(
int
j
=
0
;
j
<
bbox_num
[
i
];
j
++
)
{
PaddleDetection
::
ObjectResult
item
=
result
[
item_start_idx
+
j
];
PaddleDetection
::
ObjectResult
item
=
result
[
item_start_idx
+
j
];
if
(
item
.
confidence
<
threshold
)
{
continue
;
}
if
(
item
.
rect
.
size
()
>
6
){
if
(
item
.
rect
.
size
()
>
6
){
is_rbox
=
true
;
is_rbox
=
true
;
printf
(
"class=%d confidence=%.4f rect=[%d %d %d %d %d %d %d %d]
\n
"
,
printf
(
"class=%d confidence=%.4f rect=[%d %d %d %d %d %d %d %d]
\n
"
,
...
...
deploy/cpp/src/object_detector.cc
浏览文件 @
e1e02efe
...
@@ -174,59 +174,52 @@ void ObjectDetector::Postprocess(
...
@@ -174,59 +174,52 @@ void ObjectDetector::Postprocess(
bool
is_rbox
=
false
)
{
bool
is_rbox
=
false
)
{
result
->
clear
();
result
->
clear
();
int
start_idx
=
0
;
int
start_idx
=
0
;
for
(
int
im_id
=
0
;
im_id
<
bbox_num
.
size
();
im_id
++
)
{
for
(
int
im_id
=
0
;
im_id
<
mats
.
size
();
im_id
++
)
{
cv
::
Mat
raw_mat
=
mats
[
im_id
];
cv
::
Mat
raw_mat
=
mats
[
im_id
];
int
rh
=
1
;
int
rw
=
1
;
if
(
config_
.
arch_
==
"Face"
)
{
rh
=
raw_mat
.
rows
;
rw
=
raw_mat
.
cols
;
}
for
(
int
j
=
start_idx
;
j
<
start_idx
+
bbox_num
[
im_id
];
j
++
)
{
for
(
int
j
=
start_idx
;
j
<
start_idx
+
bbox_num
[
im_id
];
j
++
)
{
int
rh
=
1
;
int
rw
=
1
;
if
(
config_
.
arch_
==
"Face"
)
{
rh
=
raw_mat
.
rows
;
rw
=
raw_mat
.
cols
;
}
if
(
is_rbox
)
{
if
(
is_rbox
)
{
for
(
int
j
=
0
;
j
<
bbox_num
[
im_id
];
++
j
)
{
// Class id
// Class id
int
class_id
=
static_cast
<
int
>
(
round
(
output_data_
[
0
+
j
*
10
]));
int
class_id
=
static_cast
<
int
>
(
round
(
output_data_
[
0
+
j
*
10
]));
// Confidence score
// Confidence score
float
score
=
output_data_
[
1
+
j
*
10
];
float
score
=
output_data_
[
1
+
j
*
10
];
int
x1
=
(
output_data_
[
2
+
j
*
10
]
*
rw
);
int
x1
=
(
output_data_
[
2
+
j
*
10
]
*
rw
);
int
y1
=
(
output_data_
[
3
+
j
*
10
]
*
rh
);
int
y1
=
(
output_data_
[
3
+
j
*
10
]
*
rh
);
int
x2
=
(
output_data_
[
4
+
j
*
10
]
*
rw
);
int
x2
=
(
output_data_
[
4
+
j
*
10
]
*
rw
);
int
y2
=
(
output_data_
[
5
+
j
*
10
]
*
rh
);
int
y2
=
(
output_data_
[
5
+
j
*
10
]
*
rh
);
int
x3
=
(
output_data_
[
6
+
j
*
10
]
*
rw
);
int
x3
=
(
output_data_
[
6
+
j
*
10
]
*
rw
);
int
y3
=
(
output_data_
[
7
+
j
*
10
]
*
rh
);
int
y3
=
(
output_data_
[
7
+
j
*
10
]
*
rh
);
int
x4
=
(
output_data_
[
8
+
j
*
10
]
*
rw
);
int
x4
=
(
output_data_
[
8
+
j
*
10
]
*
rw
);
int
y4
=
(
output_data_
[
9
+
j
*
10
]
*
rh
);
int
y4
=
(
output_data_
[
9
+
j
*
10
]
*
rh
);
if
(
score
>
threshold_
&&
class_id
>
-
1
)
{
ObjectResult
result_item
;
ObjectResult
result_item
;
result_item
.
rect
=
{
x1
,
y1
,
x2
,
y2
,
x3
,
y3
,
x4
,
y4
};
result_item
.
rect
=
{
x1
,
y1
,
x2
,
y2
,
x3
,
y3
,
x4
,
y4
};
result_item
.
class_id
=
class_id
;
result_item
.
class_id
=
class_id
;
result_item
.
confidence
=
score
;
result_item
.
confidence
=
score
;
result
->
push_back
(
result_item
);
result
->
push_back
(
result_item
);
}
}
}
}
else
{
else
{
for
(
int
j
=
0
;
j
<
bbox_num
[
im_id
];
++
j
)
{
// Class id
// Class id
int
class_id
=
static_cast
<
int
>
(
round
(
output_data_
[
0
+
j
*
6
]));
int
class_id
=
static_cast
<
int
>
(
round
(
output_data_
[
0
+
j
*
6
]));
// Confidence score
// Confidence score
float
score
=
output_data_
[
1
+
j
*
6
];
float
score
=
output_data_
[
1
+
j
*
6
];
int
xmin
=
(
output_data_
[
2
+
j
*
6
]
*
rw
);
int
xmin
=
(
output_data_
[
2
+
j
*
6
]
*
rw
);
int
ymin
=
(
output_data_
[
3
+
j
*
6
]
*
rh
);
int
ymin
=
(
output_data_
[
3
+
j
*
6
]
*
rh
);
int
xmax
=
(
output_data_
[
4
+
j
*
6
]
*
rw
);
int
xmax
=
(
output_data_
[
4
+
j
*
6
]
*
rw
);
int
ymax
=
(
output_data_
[
5
+
j
*
6
]
*
rh
);
int
ymax
=
(
output_data_
[
5
+
j
*
6
]
*
rh
);
int
wd
=
xmax
-
xmin
;
int
wd
=
xmax
-
xmin
;
int
hd
=
ymax
-
ymin
;
int
hd
=
ymax
-
ymin
;
if
(
score
>
threshold_
&&
class_id
>
-
1
)
{
ObjectResult
result_item
;
ObjectResult
result_item
;
result_item
.
rect
=
{
xmin
,
ymin
,
xmax
,
ymax
};
result_item
.
rect
=
{
xmin
,
ymin
,
xmax
,
ymax
};
result_item
.
class_id
=
class_id
;
result_item
.
class_id
=
class_id
;
result_item
.
confidence
=
score
;
result_item
.
confidence
=
score
;
result
->
push_back
(
result_item
);
result
->
push_back
(
result_item
);
}
}
}
}
}
}
start_idx
+=
bbox_num
[
im_id
];
start_idx
+=
bbox_num
[
im_id
];
...
@@ -263,6 +256,7 @@ void ObjectDetector::Predict(const std::vector<cv::Mat> imgs,
...
@@ -263,6 +256,7 @@ void ObjectDetector::Predict(const std::vector<cv::Mat> imgs,
}
}
// Prepare input tensor
// Prepare input tensor
auto
input_names
=
predictor_
->
GetInputNames
();
auto
input_names
=
predictor_
->
GetInputNames
();
for
(
const
auto
&
tensor_name
:
input_names
)
{
for
(
const
auto
&
tensor_name
:
input_names
)
{
auto
in_tensor
=
predictor_
->
GetInputHandle
(
tensor_name
);
auto
in_tensor
=
predictor_
->
GetInputHandle
(
tensor_name
);
...
@@ -279,8 +273,10 @@ void ObjectDetector::Predict(const std::vector<cv::Mat> imgs,
...
@@ -279,8 +273,10 @@ void ObjectDetector::Predict(const std::vector<cv::Mat> imgs,
in_tensor
->
CopyFromCpu
(
scale_factor_all
.
data
());
in_tensor
->
CopyFromCpu
(
scale_factor_all
.
data
());
}
}
}
}
auto
preprocess_end
=
std
::
chrono
::
steady_clock
::
now
();
auto
preprocess_end
=
std
::
chrono
::
steady_clock
::
now
();
// Run predictor
// Run predictor
// warmup
for
(
int
i
=
0
;
i
<
warmup
;
i
++
)
for
(
int
i
=
0
;
i
<
warmup
;
i
++
)
{
{
predictor_
->
Run
();
predictor_
->
Run
();
...
@@ -288,15 +284,28 @@ void ObjectDetector::Predict(const std::vector<cv::Mat> imgs,
...
@@ -288,15 +284,28 @@ void ObjectDetector::Predict(const std::vector<cv::Mat> imgs,
auto
output_names
=
predictor_
->
GetOutputNames
();
auto
output_names
=
predictor_
->
GetOutputNames
();
auto
out_tensor
=
predictor_
->
GetOutputHandle
(
output_names
[
0
]);
auto
out_tensor
=
predictor_
->
GetOutputHandle
(
output_names
[
0
]);
std
::
vector
<
int
>
output_shape
=
out_tensor
->
shape
();
std
::
vector
<
int
>
output_shape
=
out_tensor
->
shape
();
auto
out_bbox_num
=
predictor_
->
GetOutputHandle
(
output_names
[
1
]);
std
::
vector
<
int
>
out_bbox_num_shape
=
out_bbox_num
->
shape
();
// Calculate output length
// Calculate output length
int
output_size
=
1
;
int
output_size
=
1
;
for
(
int
j
=
0
;
j
<
output_shape
.
size
();
++
j
)
{
output_size
*=
output_shape
[
j
];
}
if
(
output_size
<
6
)
{
if
(
output_size
<
6
)
{
std
::
cerr
<<
"[WARNING] No object detected."
<<
std
::
endl
;
std
::
cerr
<<
"[WARNING] No object detected."
<<
std
::
endl
;
}
}
output_data_
.
resize
(
output_size
);
output_data_
.
resize
(
output_size
);
out_tensor
->
CopyToCpu
(
output_data_
.
data
());
out_tensor
->
CopyToCpu
(
output_data_
.
data
());
}
int
out_bbox_num_size
=
1
;
for
(
int
j
=
0
;
j
<
out_bbox_num_shape
.
size
();
++
j
)
{
out_bbox_num_size
*=
out_bbox_num_shape
[
j
];
}
out_bbox_num_data_
.
resize
(
out_bbox_num_size
);
out_bbox_num
->
CopyToCpu
(
out_bbox_num_data_
.
data
());
}
bool
is_rbox
=
false
;
bool
is_rbox
=
false
;
auto
inference_start
=
std
::
chrono
::
steady_clock
::
now
();
auto
inference_start
=
std
::
chrono
::
steady_clock
::
now
();
for
(
int
i
=
0
;
i
<
repeats
;
i
++
)
for
(
int
i
=
0
;
i
<
repeats
;
i
++
)
...
@@ -331,6 +340,7 @@ void ObjectDetector::Predict(const std::vector<cv::Mat> imgs,
...
@@ -331,6 +340,7 @@ void ObjectDetector::Predict(const std::vector<cv::Mat> imgs,
auto
inference_end
=
std
::
chrono
::
steady_clock
::
now
();
auto
inference_end
=
std
::
chrono
::
steady_clock
::
now
();
auto
postprocess_start
=
std
::
chrono
::
steady_clock
::
now
();
auto
postprocess_start
=
std
::
chrono
::
steady_clock
::
now
();
// Postprocessing result
// Postprocessing result
result
->
clear
();
Postprocess
(
imgs
,
result
,
out_bbox_num_data_
,
is_rbox
);
Postprocess
(
imgs
,
result
,
out_bbox_num_data_
,
is_rbox
);
bbox_num
->
clear
();
bbox_num
->
clear
();
for
(
int
k
=
0
;
k
<
out_bbox_num_data_
.
size
();
k
++
)
{
for
(
int
k
=
0
;
k
<
out_bbox_num_data_
.
size
();
k
++
)
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录