Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
PaddleDetection
提交
5afa83e5
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看板
未验证
提交
5afa83e5
编写于
1月 13, 2021
作者:
G
Guanghua Yu
提交者:
GitHub
1月 13, 2021
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix framework warning in solov2 (#2052)
上级
8dfbd86a
变更
5
显示空白变更内容
内联
并排
Showing
5 changed file
with
37 addition
and
21 deletion
+37
-21
ppdet/core/workspace.py
ppdet/core/workspace.py
+6
-1
ppdet/modeling/anchor_heads/solov2_head.py
ppdet/modeling/anchor_heads/solov2_head.py
+9
-7
ppdet/modeling/backbones/fpn.py
ppdet/modeling/backbones/fpn.py
+2
-1
ppdet/modeling/losses/solov2_loss.py
ppdet/modeling/losses/solov2_loss.py
+6
-4
ppdet/modeling/ops.py
ppdet/modeling/ops.py
+14
-8
未找到文件。
ppdet/core/workspace.py
浏览文件 @
5afa83e5
...
@@ -24,6 +24,11 @@ import yaml
...
@@ -24,6 +24,11 @@ import yaml
import
copy
import
copy
import
collections
import
collections
try
:
collectionsAbc
=
collections
.
abc
except
AttributeError
:
collectionsAbc
=
collections
from
.config.schema
import
SchemaDict
,
SharedConfig
,
extract_schema
from
.config.schema
import
SchemaDict
,
SharedConfig
,
extract_schema
from
.config.yaml_helpers
import
serializable
from
.config.yaml_helpers
import
serializable
...
@@ -115,7 +120,7 @@ def dict_merge(dct, merge_dct):
...
@@ -115,7 +120,7 @@ def dict_merge(dct, merge_dct):
"""
"""
for
k
,
v
in
merge_dct
.
items
():
for
k
,
v
in
merge_dct
.
items
():
if
(
k
in
dct
and
isinstance
(
dct
[
k
],
dict
)
and
if
(
k
in
dct
and
isinstance
(
dct
[
k
],
dict
)
and
isinstance
(
merge_dct
[
k
],
collections
.
Mapping
)):
isinstance
(
merge_dct
[
k
],
collections
Abc
.
Mapping
)):
dict_merge
(
dct
[
k
],
merge_dct
[
k
])
dict_merge
(
dct
[
k
],
merge_dct
[
k
])
else
:
else
:
dct
[
k
]
=
merge_dct
[
k
]
dct
[
k
]
=
merge_dct
[
k
]
...
...
ppdet/modeling/anchor_heads/solov2_head.py
浏览文件 @
5afa83e5
...
@@ -132,8 +132,9 @@ class SOLOv2Head(object):
...
@@ -132,8 +132,9 @@ class SOLOv2Head(object):
def
_points_nms
(
self
,
heat
,
kernel
=
2
):
def
_points_nms
(
self
,
heat
,
kernel
=
2
):
hmax
=
fluid
.
layers
.
pool2d
(
hmax
=
fluid
.
layers
.
pool2d
(
input
=
heat
,
pool_size
=
kernel
,
pool_type
=
'max'
,
pool_padding
=
1
)
input
=
heat
,
pool_size
=
kernel
,
pool_type
=
'max'
,
pool_padding
=
1
)
keep
=
fluid
.
layers
.
cast
((
hmax
[:,
:,
:
-
1
,
:
-
1
]
==
heat
),
'float32'
)
keep
=
fluid
.
layers
.
cast
(
return
heat
*
keep
paddle
.
equal
(
hmax
[:,
:,
:
-
1
,
:
-
1
],
heat
),
'float32'
)
return
paddle
.
multiply
(
heat
,
keep
)
def
_split_feats
(
self
,
feats
):
def
_split_feats
(
self
,
feats
):
return
(
paddle
.
nn
.
functional
.
interpolate
(
return
(
paddle
.
nn
.
functional
.
interpolate
(
...
@@ -376,7 +377,7 @@ class SOLOv2Head(object):
...
@@ -376,7 +377,7 @@ class SOLOv2Head(object):
strides
.
append
(
strides
.
append
(
fluid
.
layers
.
fill_constant
(
fluid
.
layers
.
fill_constant
(
shape
=
[
int
(
size_trans
[
_ind
])],
shape
=
[
int
(
size_trans
[
_ind
])],
dtype
=
"
in
t32"
,
dtype
=
"
floa
t32"
,
value
=
self
.
segm_strides
[
_ind
]))
value
=
self
.
segm_strides
[
_ind
]))
strides
=
fluid
.
layers
.
concat
(
strides
)
strides
=
fluid
.
layers
.
concat
(
strides
)
strides
=
fluid
.
layers
.
gather
(
strides
,
index
=
inds
[:,
0
])
strides
=
fluid
.
layers
.
gather
(
strides
,
index
=
inds
[:,
0
])
...
@@ -389,7 +390,7 @@ class SOLOv2Head(object):
...
@@ -389,7 +390,7 @@ class SOLOv2Head(object):
seg_masks
=
fluid
.
layers
.
cast
(
seg_masks
,
'float32'
)
seg_masks
=
fluid
.
layers
.
cast
(
seg_masks
,
'float32'
)
sum_masks
=
fluid
.
layers
.
reduce_sum
(
seg_masks
,
dim
=
[
1
,
2
])
sum_masks
=
fluid
.
layers
.
reduce_sum
(
seg_masks
,
dim
=
[
1
,
2
])
keep
=
fluid
.
layers
.
where
(
sum_masks
>
strides
)
keep
=
fluid
.
layers
.
where
(
paddle
.
greater_than
(
sum_masks
,
strides
)
)
keep
=
fluid
.
layers
.
squeeze
(
keep
,
axes
=
[
1
])
keep
=
fluid
.
layers
.
squeeze
(
keep
,
axes
=
[
1
])
# Prevent empty and increase fake data
# Prevent empty and increase fake data
keep_other
=
fluid
.
layers
.
concat
([
keep_other
=
fluid
.
layers
.
concat
([
...
@@ -409,9 +410,10 @@ class SOLOv2Head(object):
...
@@ -409,9 +410,10 @@ class SOLOv2Head(object):
cate_scores
=
fluid
.
layers
.
gather
(
cate_scores
,
index
=
keep_scores
)
cate_scores
=
fluid
.
layers
.
gather
(
cate_scores
,
index
=
keep_scores
)
# mask scoring.
# mask scoring.
seg_mul
=
fluid
.
layers
.
cast
(
seg_preds
*
seg_masks
,
'float32'
)
seg_mul
=
fluid
.
layers
.
cast
(
seg_scores
=
fluid
.
layers
.
reduce_sum
(
seg_mul
,
dim
=
[
1
,
2
])
/
sum_masks
paddle
.
multiply
(
seg_preds
,
seg_masks
),
'float32'
)
cate_scores
*=
seg_scores
seg_scores
=
paddle
.
divide
(
paddle
.
sum
(
seg_mul
,
axis
=
[
1
,
2
]),
sum_masks
)
cate_scores
=
paddle
.
multiply
(
cate_scores
,
seg_scores
)
# Matrix NMS
# Matrix NMS
seg_preds
,
cate_scores
,
cate_labels
=
self
.
mask_nms
(
seg_preds
,
cate_scores
,
cate_labels
=
self
.
mask_nms
(
...
...
ppdet/modeling/backbones/fpn.py
浏览文件 @
5afa83e5
...
@@ -18,6 +18,7 @@ from __future__ import print_function
...
@@ -18,6 +18,7 @@ from __future__ import print_function
from
collections
import
OrderedDict
from
collections
import
OrderedDict
import
copy
import
copy
import
paddle
from
paddle
import
fluid
from
paddle
import
fluid
from
paddle.fluid.param_attr
import
ParamAttr
from
paddle.fluid.param_attr
import
ParamAttr
from
paddle.fluid.initializer
import
Xavier
from
paddle.fluid.initializer
import
Xavier
...
@@ -105,7 +106,7 @@ class FPN(object):
...
@@ -105,7 +106,7 @@ class FPN(object):
out_shape
=
[
body_input
.
shape
[
2
],
body_input
.
shape
[
3
]],
out_shape
=
[
body_input
.
shape
[
2
],
body_input
.
shape
[
3
]],
name
=
topdown_name
)
name
=
topdown_name
)
return
lateral
+
topdown
return
paddle
.
add
(
lateral
,
topdown
)
def
get_output
(
self
,
body_dict
):
def
get_output
(
self
,
body_dict
):
"""
"""
...
...
ppdet/modeling/losses/solov2_loss.py
浏览文件 @
5afa83e5
...
@@ -48,10 +48,12 @@ class SOLOv2Loss(object):
...
@@ -48,10 +48,12 @@ class SOLOv2Loss(object):
target
=
fluid
.
layers
.
reshape
(
target
=
fluid
.
layers
.
reshape
(
target
,
shape
=
(
fluid
.
layers
.
shape
(
target
)[
0
],
-
1
))
target
,
shape
=
(
fluid
.
layers
.
shape
(
target
)[
0
],
-
1
))
target
=
fluid
.
layers
.
cast
(
target
,
'float32'
)
target
=
fluid
.
layers
.
cast
(
target
,
'float32'
)
a
=
fluid
.
layers
.
reduce_sum
(
input
*
target
,
dim
=
1
)
a
=
fluid
.
layers
.
reduce_sum
(
paddle
.
multiply
(
input
,
target
),
dim
=
1
)
b
=
fluid
.
layers
.
reduce_sum
(
input
*
input
,
dim
=
1
)
+
0.001
b
=
fluid
.
layers
.
reduce_sum
(
c
=
fluid
.
layers
.
reduce_sum
(
target
*
target
,
dim
=
1
)
+
0.001
paddle
.
multiply
(
input
,
input
),
dim
=
1
)
+
0.001
d
=
(
2
*
a
)
/
(
b
+
c
)
c
=
fluid
.
layers
.
reduce_sum
(
paddle
.
multiply
(
target
,
target
),
dim
=
1
)
+
0.001
d
=
paddle
.
divide
((
2
*
a
),
paddle
.
add
(
b
,
c
))
return
1
-
d
return
1
-
d
def
__call__
(
self
,
ins_pred_list
,
ins_label_list
,
cate_preds
,
cate_labels
,
def
__call__
(
self
,
ins_pred_list
,
ins_label_list
,
cate_preds
,
cate_labels
,
...
...
ppdet/modeling/ops.py
浏览文件 @
5afa83e5
...
@@ -1642,8 +1642,12 @@ class MaskMatrixNMS(object):
...
@@ -1642,8 +1642,12 @@ class MaskMatrixNMS(object):
sum_masks
,
expand_times
=
[
n_samples
]),
sum_masks
,
expand_times
=
[
n_samples
]),
shape
=
[
n_samples
,
n_samples
])
shape
=
[
n_samples
,
n_samples
])
# iou.
# iou.
iou_matrix
=
(
inter_matrix
/
(
sum_masks_x
+
fluid
.
layers
.
transpose
(
iou_matrix
=
paddle
.
divide
(
inter_matrix
,
sum_masks_x
,
[
1
,
0
])
-
inter_matrix
))
paddle
.
subtract
(
paddle
.
add
(
sum_masks_x
,
fluid
.
layers
.
transpose
(
sum_masks_x
,
[
1
,
0
])),
inter_matrix
))
iou_matrix
=
paddle
.
triu
(
iou_matrix
,
diagonal
=
1
)
iou_matrix
=
paddle
.
triu
(
iou_matrix
,
diagonal
=
1
)
# label_specific matrix.
# label_specific matrix.
cate_labels_x
=
fluid
.
layers
.
reshape
(
cate_labels_x
=
fluid
.
layers
.
reshape
(
...
@@ -1651,12 +1655,14 @@ class MaskMatrixNMS(object):
...
@@ -1651,12 +1655,14 @@ class MaskMatrixNMS(object):
cate_labels
,
expand_times
=
[
n_samples
]),
cate_labels
,
expand_times
=
[
n_samples
]),
shape
=
[
n_samples
,
n_samples
])
shape
=
[
n_samples
,
n_samples
])
label_matrix
=
fluid
.
layers
.
cast
(
label_matrix
=
fluid
.
layers
.
cast
(
(
cate_labels_x
==
fluid
.
layers
.
transpose
(
cate_labels_x
,
[
1
,
0
])),
paddle
.
equal
(
cate_labels_x
,
fluid
.
layers
.
transpose
(
cate_labels_x
,
[
1
,
0
])),
'float32'
)
'float32'
)
label_matrix
=
paddle
.
triu
(
label_matrix
,
diagonal
=
1
)
label_matrix
=
paddle
.
triu
(
label_matrix
,
diagonal
=
1
)
# IoU compensation
# IoU compensation
compensate_iou
=
paddle
.
max
((
iou_matrix
*
label_matrix
),
axis
=
0
)
compensate_iou
=
paddle
.
max
(
paddle
.
multiply
(
iou_matrix
,
label_matrix
),
axis
=
0
)
compensate_iou
=
fluid
.
layers
.
reshape
(
compensate_iou
=
fluid
.
layers
.
reshape
(
fluid
.
layers
.
expand
(
fluid
.
layers
.
expand
(
compensate_iou
,
expand_times
=
[
n_samples
]),
compensate_iou
,
expand_times
=
[
n_samples
]),
...
@@ -1664,15 +1670,15 @@ class MaskMatrixNMS(object):
...
@@ -1664,15 +1670,15 @@ class MaskMatrixNMS(object):
compensate_iou
=
fluid
.
layers
.
transpose
(
compensate_iou
,
[
1
,
0
])
compensate_iou
=
fluid
.
layers
.
transpose
(
compensate_iou
,
[
1
,
0
])
# IoU decay
# IoU decay
decay_iou
=
iou_matrix
*
label_matrix
decay_iou
=
paddle
.
multiply
(
iou_matrix
,
label_matrix
)
# matrix nms
# matrix nms
if
self
.
kernel
==
'gaussian'
:
if
self
.
kernel
==
'gaussian'
:
decay_matrix
=
fluid
.
layers
.
exp
(
-
1
*
self
.
sigma
*
(
decay_iou
**
2
))
decay_matrix
=
fluid
.
layers
.
exp
(
-
1
*
self
.
sigma
*
(
decay_iou
**
2
))
compensate_matrix
=
fluid
.
layers
.
exp
(
-
1
*
self
.
sigma
*
compensate_matrix
=
fluid
.
layers
.
exp
(
-
1
*
self
.
sigma
*
(
compensate_iou
**
2
))
(
compensate_iou
**
2
))
decay_coefficient
=
paddle
.
min
(
decay_matrix
/
compensate_matrix
,
decay_coefficient
=
paddle
.
min
(
axis
=
0
)
paddle
.
divide
(
decay_matrix
,
compensate_matrix
),
axis
=
0
)
elif
self
.
kernel
==
'linear'
:
elif
self
.
kernel
==
'linear'
:
decay_matrix
=
(
1
-
decay_iou
)
/
(
1
-
compensate_iou
)
decay_matrix
=
(
1
-
decay_iou
)
/
(
1
-
compensate_iou
)
decay_coefficient
=
paddle
.
min
(
decay_matrix
,
axis
=
0
)
decay_coefficient
=
paddle
.
min
(
decay_matrix
,
axis
=
0
)
...
@@ -1680,7 +1686,7 @@ class MaskMatrixNMS(object):
...
@@ -1680,7 +1686,7 @@ class MaskMatrixNMS(object):
raise
NotImplementedError
raise
NotImplementedError
# update the score.
# update the score.
cate_scores
=
cate_scores
*
decay_coefficient
cate_scores
=
paddle
.
multiply
(
cate_scores
,
decay_coefficient
)
keep
=
fluid
.
layers
.
where
(
cate_scores
>=
self
.
update_threshold
)
keep
=
fluid
.
layers
.
where
(
cate_scores
>=
self
.
update_threshold
)
keep
=
fluid
.
layers
.
squeeze
(
keep
,
axes
=
[
1
])
keep
=
fluid
.
layers
.
squeeze
(
keep
,
axes
=
[
1
])
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录