Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
PaddleDetection
提交
762204e9
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看板
提交
762204e9
编写于
12月 26, 2019
作者:
Y
Yang Zhang
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Switch to "google" C++ style from customized "linux" style
上级
6f79f530
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
26 addition
and
55 deletion
+26
-55
src/binding.cc
src/binding.cc
+15
-30
src/nms.cc
src/nms.cc
+11
-25
未找到文件。
src/binding.cc
浏览文件 @
762204e9
...
...
@@ -4,36 +4,21 @@
#include <pybind11/numpy.h>
#include <pybind11/stl.h>
namespace
nms
{
enum
class
Method
:
uint32_t
{
LINEAR
=
0
,
GAUSSIAN
,
HARD
};
namespace
nms
{
enum
class
Method
:
uint32_t
{
LINEAR
=
0
,
GAUSSIAN
,
HARD
};
size_t
soft_nms
(
float
*
boxes
,
int32_t
*
index
,
size_t
count
,
Method
method
,
float
Nt
,
float
sigma
,
float
threshold
);
size_t
soft_nms
(
float
*
boxes
,
int32_t
*
index
,
size_t
count
,
Method
method
,
float
Nt
,
float
sigma
,
float
threshold
);
}
// namespace nms
namespace
binding
{
namespace
binding
{
namespace
py
=
pybind11
;
using
namespace
pybind11
::
literals
;
py
::
tuple
py_soft_nms
(
py
::
array_t
<
float
,
py
::
array
::
c_style
>
boxes
,
nms
::
Method
method
=
nms
::
Method
::
GAUSSIAN
,
float
Nt
=
0.3
,
float
sigma
=
0.5
,
float
threshold
=
0.001
)
{
float
Nt
=
0.3
,
float
sigma
=
0.5
,
float
threshold
=
0.001
)
{
assert
(
boxes
.
ndim
()
==
2
&&
"Input should be 2-D NumPy array"
);
assert
(
boxes
.
shape
()[
1
]
==
5
&&
"Input should have size [N,5]"
);
...
...
@@ -44,8 +29,8 @@ py::tuple py_soft_nms(py::array_t<float, py::array::c_style> boxes,
auto
N
=
nms
::
soft_nms
(
b
,
i
,
count
,
method
,
Nt
,
sigma
,
threshold
);
std
::
vector
<
size_t
>
shape5
=
{
N
,
5
};
std
::
vector
<
size_t
>
shape1
=
{
N
};
std
::
vector
<
size_t
>
shape5
=
{
N
,
5
};
std
::
vector
<
size_t
>
shape1
=
{
N
};
std
::
vector
<
ssize_t
>
strides5
=
{
sizeof
(
float
)
*
5
,
sizeof
(
float
)};
std
::
vector
<
ssize_t
>
strides1
=
{
sizeof
(
float
)};
...
...
@@ -63,12 +48,12 @@ PYBIND11_MODULE(nms, m) {
m
.
doc
()
=
"SoftNMS for object detection."
;
py
::
enum_
<
nms
::
Method
>
(
m
,
"NMSMethod"
)
.
value
(
"LINEAR"
,
nms
::
Method
::
LINEAR
)
.
value
(
"GAUSSIAN"
,
nms
::
Method
::
GAUSSIAN
)
.
value
(
"HARD"
,
nms
::
Method
::
HARD
)
.
export_values
();
.
value
(
"LINEAR"
,
nms
::
Method
::
LINEAR
)
.
value
(
"GAUSSIAN"
,
nms
::
Method
::
GAUSSIAN
)
.
value
(
"HARD"
,
nms
::
Method
::
HARD
)
.
export_values
();
m
.
def
(
"soft_nms"
,
&
py_soft_nms
,
"boxes"
_a
.
noconvert
(),
"method"
_a
=
nms
::
Method
::
GAUSSIAN
,
"
Nt"
_a
=
0.3
,
"sigma"
_a
=
0.5
,
"
threshold"
_a
=
0.001
);
"method"
_a
=
nms
::
Method
::
GAUSSIAN
,
"Nt"
_a
=
0.3
,
"sigma"
_a
=
0.5
,
"threshold"
_a
=
0.001
);
}
}
/* namespace binding */
src/nms.cc
浏览文件 @
762204e9
#include <cmath>
#include <algorithm>
namespace
nms
{
struct
proposal
{
namespace
nms
{
struct
proposal
{
float
score
,
x1
,
y1
,
x2
,
y2
;
};
inline
static
bool
cmp
(
const
proposal
&
a
,
const
proposal
&
b
)
{
inline
static
bool
cmp
(
const
proposal
&
a
,
const
proposal
&
b
)
{
return
a
.
score
<
b
.
score
;
}
inline
static
float
iou
(
const
proposal
&
,
const
proposal
&
)
__attribute__
((
always_inline
));
inline
static
float
iou
(
const
proposal
&
,
const
proposal
&
)
__attribute__
((
always_inline
));
static
float
iou
(
const
proposal
&
a
,
const
proposal
&
b
)
{
static
float
iou
(
const
proposal
&
a
,
const
proposal
&
b
)
{
auto
overlap
=
0.
f
;
float
iw
=
std
::
min
(
b
.
x2
,
a
.
x2
)
-
std
::
max
(
b
.
x1
,
a
.
x1
)
+
1
;
float
iw
=
std
::
min
(
b
.
x2
,
a
.
x2
)
-
std
::
max
(
b
.
x1
,
a
.
x1
)
+
1
;
if
(
iw
>
0
)
{
float
ih
=
std
::
min
(
b
.
y2
,
a
.
y2
)
-
std
::
max
(
b
.
y1
,
a
.
y1
)
+
1
;
if
(
ih
>
0
)
{
...
...
@@ -31,21 +28,10 @@ static float iou(const proposal& a, const proposal& b)
return
overlap
;
}
enum
class
Method
:
uint32_t
{
LINEAR
=
0
,
GAUSSIAN
,
HARD
};
enum
class
Method
:
uint32_t
{
LINEAR
=
0
,
GAUSSIAN
,
HARD
};
size_t
soft_nms
(
float
*
boxes
,
int32_t
*
index
,
size_t
count
,
Method
method
,
float
Nt
,
float
sigma
,
float
threshold
)
{
size_t
soft_nms
(
float
*
boxes
,
int32_t
*
index
,
size_t
count
,
Method
method
,
float
Nt
,
float
sigma
,
float
threshold
)
{
std
::
iota
(
index
,
index
+
count
,
0
);
// np.arange()
auto
p
=
reinterpret_cast
<
proposal
*>
(
boxes
);
...
...
@@ -55,7 +41,7 @@ size_t soft_nms(float* boxes,
std
::
swap
(
p
[
i
],
*
max
);
std
::
swap
(
index
[
i
],
index
[
max
-
p
]);
auto
j
=
i
+
1
;
auto
j
=
i
+
1
;
auto
weight
=
0.
f
;
while
(
j
<
N
)
{
auto
ov
=
iou
(
p
[
i
],
p
[
j
]);
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录