Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Crayon鑫
Paddle
提交
95aec835
P
Paddle
项目概览
Crayon鑫
/
Paddle
与 Fork 源项目一致
Fork自
PaddlePaddle / Paddle
通知
1
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
Paddle
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1
Issue
1
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
95aec835
编写于
12月 28, 2017
作者:
S
sweetsky0901
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
modify fun name
上级
41bbd283
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
49 addition
and
49 deletion
+49
-49
paddle/operators/detection_output_op.h
paddle/operators/detection_output_op.h
+9
-9
paddle/operators/math/detection_util.h
paddle/operators/math/detection_util.h
+40
-40
未找到文件。
paddle/operators/detection_output_op.h
浏览文件 @
95aec835
...
...
@@ -119,22 +119,22 @@ class DetectionOutputKernel : public framework::OpKernel<T> {
size_t
prior_offset
=
i
*
8
;
size_t
loc_pred_offset
=
n
*
num_priors
*
4
+
i
*
4
;
std
::
vector
<
math
::
BBox
<
T
>>
prior_bbox_vec
;
math
::
get_bbox_from_p
riorData
<
T
>
(
priorbox_data
+
prior_offset
,
1
,
prior_bbox_vec
);
math
::
GetBBoxFromP
riorData
<
T
>
(
priorbox_data
+
prior_offset
,
1
,
prior_bbox_vec
);
std
::
vector
<
std
::
vector
<
T
>>
prior_bbox_var
;
math
::
get_bbox_var_from_prior_d
ata
<
T
>
(
priorbox_data
+
prior_offset
,
1
,
prior_bbox_var
);
math
::
GetBBoxVarFromPriorD
ata
<
T
>
(
priorbox_data
+
prior_offset
,
1
,
prior_bbox_var
);
std
::
vector
<
T
>
loc_pred_data
;
for
(
size_t
j
=
0
;
j
<
4
;
++
j
)
loc_pred_data
.
push_back
(
*
(
loc_data
+
loc_pred_offset
+
j
));
math
::
BBox
<
T
>
bbox
=
math
::
decode_bbox_with_v
ar
<
T
>
(
math
::
BBox
<
T
>
bbox
=
math
::
DecodeBBoxWithV
ar
<
T
>
(
prior_bbox_vec
[
0
],
prior_bbox_var
[
0
],
loc_pred_data
);
decoded_bboxes
.
push_back
(
bbox
);
}
all_decoded_bboxes
.
push_back
(
decoded_bboxes
);
}
std
::
vector
<
std
::
map
<
size_t
,
std
::
vector
<
size_t
>>>
all_indices
;
int
num_kept
=
math
::
get_detection_i
ndices
<
T
>
(
int
num_kept
=
math
::
GetDetectionI
ndices
<
T
>
(
conf_data
,
num_priors
,
num_classes
,
background_label_id
,
batch_size
,
confidence_threshold
,
nms_top_k
,
nms_threshold
,
top_k
,
all_decoded_bboxes
,
&
all_indices
);
...
...
@@ -154,9 +154,9 @@ class DetectionOutputKernel : public framework::OpKernel<T> {
out_cpu
.
mutable_data
<
T
>
(
out
->
dims
(),
platform
::
CPUPlace
());
out_data
=
out_cpu
.
data
<
T
>
();
}
math
::
get_detection_o
utput
<
T
>
(
conf_data
,
num_kept
,
num_priors
,
num_classes
,
batch_size
,
all_indices
,
all_decoded_bboxes
,
out_data
);
math
::
GetDetectionO
utput
<
T
>
(
conf_data
,
num_kept
,
num_priors
,
num_classes
,
batch_size
,
all_indices
,
all_decoded_bboxes
,
out_data
);
if
(
platform
::
is_gpu_place
(
context
.
GetPlace
()))
{
framework
::
CopyFrom
(
out_cpu
,
platform
::
CUDAPlace
(),
context
.
device_context
(),
out
);
...
...
paddle/operators/math/detection_util.h
浏览文件 @
95aec835
...
...
@@ -51,31 +51,31 @@ struct BBox {
// KNCHW ==> NHWC
// template <typename T>
template
<
typename
T
>
void
get_bbox_from_p
riorData
(
const
T
*
prior_data
,
const
size_t
num_bboxes
,
std
::
vector
<
BBox
<
T
>>&
bbox_vec
);
void
GetBBoxFromP
riorData
(
const
T
*
prior_data
,
const
size_t
num_bboxes
,
std
::
vector
<
BBox
<
T
>>&
bbox_vec
);
template
<
typename
T
>
void
get_bbox_var_from_prior_d
ata
(
const
T
*
prior_data
,
const
size_t
num
,
std
::
vector
<
std
::
vector
<
T
>>&
var_vec
);
void
GetBBoxVarFromPriorD
ata
(
const
T
*
prior_data
,
const
size_t
num
,
std
::
vector
<
std
::
vector
<
T
>>&
var_vec
);
template
<
typename
T
>
BBox
<
T
>
decode_bbox_with_v
ar
(
BBox
<
T
>&
prior_bbox
,
const
std
::
vector
<
T
>&
prior_bbox_var
,
const
std
::
vector
<
T
>&
loc_pred_data
);
BBox
<
T
>
DecodeBBoxWithV
ar
(
BBox
<
T
>&
prior_bbox
,
const
std
::
vector
<
T
>&
prior_bbox_var
,
const
std
::
vector
<
T
>&
loc_pred_data
);
template
<
typename
T1
,
typename
T2
>
bool
sort_score_pair_d
escend
(
const
std
::
pair
<
T1
,
T2
>&
pair1
,
const
std
::
pair
<
T1
,
T2
>&
pair2
);
bool
SortScorePairD
escend
(
const
std
::
pair
<
T1
,
T2
>&
pair1
,
const
std
::
pair
<
T1
,
T2
>&
pair2
);
template
<
typename
T
>
bool
sort_score_pair_d
escend
(
const
std
::
pair
<
T
,
BBox
<
T
>>&
pair1
,
const
std
::
pair
<
T
,
BBox
<
T
>>&
pair2
);
bool
SortScorePairD
escend
(
const
std
::
pair
<
T
,
BBox
<
T
>>&
pair1
,
const
std
::
pair
<
T
,
BBox
<
T
>>&
pair2
);
template
<
typename
T
>
T
jaccard_overlap
(
const
BBox
<
T
>&
bbox1
,
const
BBox
<
T
>&
bbox2
);
template
<
typename
T
>
void
apply_nms_fast
(
const
std
::
vector
<
BBox
<
T
>>&
bboxes
,
const
T
*
conf_score_data
,
size_t
class_idx
,
size_t
top_k
,
T
conf_threshold
,
T
nms_threshold
,
size_t
num_prior
s
,
size_t
num_classes
,
std
::
vector
<
size_t
>*
indices
);
void
ApplyNmsFast
(
const
std
::
vector
<
BBox
<
T
>>&
bboxes
,
const
T
*
conf_score_data
,
size_t
class_idx
,
size_t
top_k
,
T
conf_threshold
,
T
nms_threshold
,
size_t
num_priors
,
size_t
num_classe
s
,
std
::
vector
<
size_t
>*
indices
);
template
<
typename
T
>
int
get_detection_i
ndices
(
int
GetDetectionI
ndices
(
const
T
*
conf_data
,
const
size_t
num_priors
,
const
size_t
num_classes
,
const
size_t
background_label_id
,
const
size_t
batch_size
,
const
T
conf_threshold
,
const
size_t
nms_top_k
,
const
T
nms_threshold
,
...
...
@@ -83,16 +83,16 @@ int get_detection_indices(
const
std
::
vector
<
std
::
vector
<
BBox
<
T
>>>&
all_decoded_bboxes
,
std
::
vector
<
std
::
map
<
size_t
,
std
::
vector
<
size_t
>>>*
all_detection_indices
);
template
<
typename
T
>
BBox
<
T
>
c
lipBBox
(
const
BBox
<
T
>&
bbox
);
BBox
<
T
>
C
lipBBox
(
const
BBox
<
T
>&
bbox
);
template
<
typename
T
>
void
get_detection_o
utput
(
void
GetDetectionO
utput
(
const
T
*
conf_data
,
const
size_t
num_kept
,
const
size_t
num_priors
,
const
size_t
num_classes
,
const
size_t
batch_size
,
const
std
::
vector
<
std
::
map
<
size_t
,
std
::
vector
<
size_t
>>>&
all_indices
,
const
std
::
vector
<
std
::
vector
<
BBox
<
T
>>>&
all_decoded_bboxes
,
T
*
out_data
);
template
<
typename
T
>
void
get_bbox_from_p
riorData
(
const
T
*
prior_data
,
const
size_t
num_bboxes
,
std
::
vector
<
BBox
<
T
>>&
bbox_vec
)
{
void
GetBBoxFromP
riorData
(
const
T
*
prior_data
,
const
size_t
num_bboxes
,
std
::
vector
<
BBox
<
T
>>&
bbox_vec
)
{
size_t
out_offset
=
bbox_vec
.
size
();
bbox_vec
.
resize
(
bbox_vec
.
size
()
+
num_bboxes
);
for
(
size_t
i
=
0
;
i
<
num_bboxes
;
++
i
)
{
...
...
@@ -105,8 +105,8 @@ void get_bbox_from_priorData(const T* prior_data, const size_t num_bboxes,
}
}
template
<
typename
T
>
void
get_bbox_var_from_prior_d
ata
(
const
T
*
prior_data
,
const
size_t
num
,
std
::
vector
<
std
::
vector
<
T
>>&
var_vec
)
{
void
GetBBoxVarFromPriorD
ata
(
const
T
*
prior_data
,
const
size_t
num
,
std
::
vector
<
std
::
vector
<
T
>>&
var_vec
)
{
size_t
out_offset
=
var_vec
.
size
();
var_vec
.
resize
(
var_vec
.
size
()
+
num
);
for
(
size_t
i
=
0
;
i
<
num
;
++
i
)
{
...
...
@@ -119,9 +119,9 @@ void get_bbox_var_from_prior_data(const T* prior_data, const size_t num,
}
}
template
<
typename
T
>
BBox
<
T
>
decode_bbox_with_v
ar
(
BBox
<
T
>&
prior_bbox
,
const
std
::
vector
<
T
>&
prior_bbox_var
,
const
std
::
vector
<
T
>&
loc_pred_data
)
{
BBox
<
T
>
DecodeBBoxWithV
ar
(
BBox
<
T
>&
prior_bbox
,
const
std
::
vector
<
T
>&
prior_bbox_var
,
const
std
::
vector
<
T
>&
loc_pred_data
)
{
T
prior_bbox_width
=
prior_bbox
.
get_width
();
T
prior_bbox_height
=
prior_bbox
.
get_height
();
T
prior_bbox_center_x
=
prior_bbox
.
get_center_x
();
...
...
@@ -147,8 +147,8 @@ BBox<T> decode_bbox_with_var(BBox<T>& prior_bbox,
return
decoded_bbox
;
}
template
<
typename
T1
,
typename
T2
>
bool
sort_score_pair_d
escend
(
const
std
::
pair
<
T1
,
T2
>&
pair1
,
const
std
::
pair
<
T1
,
T2
>&
pair2
)
{
bool
SortScorePairD
escend
(
const
std
::
pair
<
T1
,
T2
>&
pair1
,
const
std
::
pair
<
T1
,
T2
>&
pair2
)
{
return
pair1
.
first
>
pair2
.
first
;
}
template
<
typename
T
>
...
...
@@ -174,10 +174,10 @@ T jaccard_overlap(const BBox<T>& bbox1, const BBox<T>& bbox2) {
}
template
<
typename
T
>
void
apply_nms_fast
(
const
std
::
vector
<
BBox
<
T
>>&
bboxes
,
const
T
*
conf_score_data
,
size_t
class_idx
,
size_t
top_k
,
T
conf_threshold
,
T
nms_threshold
,
size_t
num_prior
s
,
size_t
num_classes
,
std
::
vector
<
size_t
>*
indices
)
{
void
ApplyNmsFast
(
const
std
::
vector
<
BBox
<
T
>>&
bboxes
,
const
T
*
conf_score_data
,
size_t
class_idx
,
size_t
top_k
,
T
conf_threshold
,
T
nms_threshold
,
size_t
num_priors
,
size_t
num_classe
s
,
std
::
vector
<
size_t
>*
indices
)
{
std
::
vector
<
std
::
pair
<
T
,
size_t
>>
scores
;
for
(
size_t
i
=
0
;
i
<
num_priors
;
++
i
)
{
size_t
conf_offset
=
i
*
num_classes
+
class_idx
;
...
...
@@ -185,7 +185,7 @@ void apply_nms_fast(const std::vector<BBox<T>>& bboxes,
scores
.
push_back
(
std
::
make_pair
(
conf_score_data
[
conf_offset
],
i
));
}
std
::
stable_sort
(
scores
.
begin
(),
scores
.
end
(),
sort_score_pair_d
escend
<
T
,
size_t
>
);
SortScorePairD
escend
<
T
,
size_t
>
);
if
(
top_k
>
0
&&
top_k
<
scores
.
size
())
scores
.
resize
(
top_k
);
while
(
scores
.
size
()
>
0
)
{
const
size_t
idx
=
scores
.
front
().
second
;
...
...
@@ -204,7 +204,7 @@ void apply_nms_fast(const std::vector<BBox<T>>& bboxes,
}
}
template
<
typename
T
>
int
get_detection_i
ndices
(
int
GetDetectionI
ndices
(
const
T
*
conf_data
,
const
size_t
num_priors
,
const
size_t
num_classes
,
const
size_t
background_label_id
,
const
size_t
batch_size
,
const
T
conf_threshold
,
const
size_t
nms_top_k
,
const
T
nms_threshold
,
...
...
@@ -219,9 +219,9 @@ int get_detection_indices(
size_t
conf_offset
=
n
*
num_priors
*
num_classes
;
for
(
size_t
c
=
0
;
c
<
num_classes
;
++
c
)
{
if
(
c
==
background_label_id
)
continue
;
apply_nms_f
ast
<
T
>
(
decoded_bboxes
,
conf_data
+
conf_offset
,
c
,
nms_top_k
,
conf_threshold
,
nms_threshold
,
num_priors
,
num_classes
,
&
(
indices
[
c
]));
ApplyNmsF
ast
<
T
>
(
decoded_bboxes
,
conf_data
+
conf_offset
,
c
,
nms_top_k
,
conf_threshold
,
nms_threshold
,
num_priors
,
num_classes
,
&
(
indices
[
c
]));
num_detected
+=
indices
[
c
].
size
();
}
if
(
top_k
>
0
&&
num_detected
>
top_k
)
{
...
...
@@ -237,7 +237,7 @@ int get_detection_indices(
}
}
std
::
sort
(
score_index_pairs
.
begin
(),
score_index_pairs
.
end
(),
sort_score_pair_d
escend
<
T
,
std
::
pair
<
size_t
,
size_t
>>
);
SortScorePairD
escend
<
T
,
std
::
pair
<
size_t
,
size_t
>>
);
score_index_pairs
.
resize
(
top_k
);
std
::
map
<
size_t
,
std
::
vector
<
size_t
>>
new_indices
;
for
(
size_t
i
=
0
;
i
<
score_index_pairs
.
size
();
++
i
)
{
...
...
@@ -255,7 +255,7 @@ int get_detection_indices(
return
total_keep_num
;
}
template
<
typename
T
>
BBox
<
T
>
c
lipBBox
(
const
BBox
<
T
>&
bbox
)
{
BBox
<
T
>
C
lipBBox
(
const
BBox
<
T
>&
bbox
)
{
T
one
=
static_cast
<
T
>
(
1.0
);
T
zero
=
static_cast
<
T
>
(
0.0
);
BBox
<
T
>
clipped_bbox
;
...
...
@@ -266,7 +266,7 @@ BBox<T> clipBBox(const BBox<T>& bbox) {
return
clipped_bbox
;
}
template
<
typename
T
>
void
get_detection_o
utput
(
void
GetDetectionO
utput
(
const
T
*
conf_data
,
const
size_t
num_kept
,
const
size_t
num_priors
,
const
size_t
num_classes
,
const
size_t
batch_size
,
const
std
::
vector
<
std
::
map
<
size_t
,
std
::
vector
<
size_t
>>>&
all_indices
,
...
...
@@ -285,7 +285,7 @@ void get_detection_output(
out_data
[
count
*
7
]
=
n
;
out_data
[
count
*
7
+
1
]
=
label
;
out_data
[
count
*
7
+
2
]
=
(
conf_data
+
conf_offset
)[
label
];
BBox
<
T
>
clipped_bbox
=
c
lipBBox
<
T
>
(
decoded_bboxes
[
idx
]);
BBox
<
T
>
clipped_bbox
=
C
lipBBox
<
T
>
(
decoded_bboxes
[
idx
]);
out_data
[
count
*
7
+
3
]
=
clipped_bbox
.
x_min
;
out_data
[
count
*
7
+
4
]
=
clipped_bbox
.
y_min
;
out_data
[
count
*
7
+
5
]
=
clipped_bbox
.
x_max
;
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录