Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
OpenDAS
mmdetection3d
Commits
3337fa69
Commit
3337fa69
authored
May 11, 2020
by
zhangwenwei
Browse files
Refactor SECOND FPN
parent
868c5fab
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
50 additions
and
39 deletions
+50
-39
mmdet3d/models/necks/second_fpn.py
mmdet3d/models/necks/second_fpn.py
+50
-39
No files found.
mmdet3d/models/necks/second_fpn.py
View file @
3337fa69
from
functools
import
partial
import
copy
import
torch
import
torch.nn
as
nn
from
mmcv.cnn
import
build_norm_layer
,
constant_init
,
kaiming_init
from
torch.nn
import
Sequential
from
torch.nn.modules.batchnorm
import
_BatchNorm
from
mmcv.cnn
import
(
build_norm_layer
,
build_upsample_layer
,
constant_init
,
is_norm
,
kaiming_init
)
from
mmdet.models
import
NECKS
from
..
import
builder
...
...
@@ -12,33 +11,41 @@ from .. import builder
@
NECKS
.
register_module
()
class
SECONDFPN
(
nn
.
Module
):
"""Compare with RPN, RPNV2 support arbitrary number of stage.
"""FPN used in SECOND/PointPillars
Args:
in_channels (list[int]): Input channels of multi-scale feature maps
out_channels (list[int]): Output channels of feature maps
upsample_strides (list[int]): Strides used to upsample the feature maps
norm_cfg (dict): Config dict of normalization layers
upsample_cfg (dict): Config dict of upsample layers
"""
def
__init__
(
self
,
use_norm
=
True
,
in_channels
=
[
128
,
128
,
256
],
out_channels
=
[
256
,
256
,
256
],
upsample_strides
=
[
1
,
2
,
4
],
n
um_upsample_filters
=
[
256
,
256
,
256
]
,
norm
_cfg
=
dict
(
type
=
'
BN'
,
eps
=
1e-3
,
momentum
=
0.01
)):
n
orm_cfg
=
dict
(
type
=
'BN'
,
eps
=
1e-3
,
momentum
=
0.01
)
,
upsample
_cfg
=
dict
(
type
=
'
deconv'
,
bias
=
False
)):
# if for GroupNorm,
# cfg is dict(type='GN', num_groups=num_groups, eps=1e-3, affine=True)
super
(
SECONDFPN
,
self
).
__init__
()
assert
len
(
num_upsample_filter
s
)
==
len
(
upsample_strides
)
assert
len
(
out_channel
s
)
==
len
(
upsample_strides
)
==
len
(
in_channels
)
self
.
in_channels
=
in_channels
ConvTranspose2d
=
partial
(
nn
.
ConvTranspose2d
,
bias
=
False
)
self
.
out_channels
=
out_channels
deblocks
=
[]
for
i
,
num_upsample_filter
in
enumerate
(
num_upsample_filters
):
norm_layer
=
build_norm_layer
(
norm_cfg
,
num_upsample_filter
)[
1
]
deblock
=
Sequential
(
ConvTranspose2d
(
in_channels
[
i
],
num_upsample_filter
,
upsample_strides
[
i
],
stride
=
upsample_strides
[
i
]),
for
i
,
out_channel
in
enumerate
(
out_channels
):
norm_layer
=
build_norm_layer
(
norm_cfg
,
out_channel
)[
1
]
upsample_cfg_
=
copy
.
deepcopy
(
upsample_cfg
)
upsample_cfg_
.
update
(
in_channels
=
in_channels
[
i
],
out_channels
=
out_channel
,
padding
=
upsample_strides
[
i
],
stride
=
upsample_strides
[
i
])
upsample_layer
=
build_upsample_layer
(
upsample_cfg_
)
deblock
=
nn
.
Sequential
(
upsample_layer
,
norm_layer
,
nn
.
ReLU
(
inplace
=
True
),
)
...
...
@@ -49,7 +56,7 @@ class SECONDFPN(nn.Module):
for
m
in
self
.
modules
():
if
isinstance
(
m
,
nn
.
Conv2d
):
kaiming_init
(
m
)
elif
is
instance
(
m
,
(
_BatchNorm
,
nn
.
GroupNorm
)
):
elif
is
_norm
(
m
):
constant_init
(
m
,
1
)
def
forward
(
self
,
x
):
...
...
@@ -65,30 +72,34 @@ class SECONDFPN(nn.Module):
@
NECKS
.
register_module
()
class
SECONDFusionFPN
(
SECONDFPN
):
"""Compare with RPN, RPNV2 support arbitrary number of stage.
"""FPN used in multi-modality SECOND/PointPillars
Args:
in_channels (list[int]): Input channels of multi-scale feature maps
out_channels (list[int]): Output channels of feature maps
upsample_strides (list[int]): Strides used to upsample the feature maps
norm_cfg (dict): Config dict of normalization layers
upsample_cfg (dict): Config dict of upsample layers
downsample_rates (list[int]): The downsample rate of feature map in
comparison to the original voxelization input
fusion_layer (dict): Config dict of fusion layers
"""
def
__init__
(
self
,
use_norm
=
True
,
in_channels
=
[
128
,
128
,
256
],
out_channels
=
[
256
,
256
,
256
],
upsample_strides
=
[
1
,
2
,
4
],
num_upsample_filters
=
[
256
,
256
,
256
],
norm_cfg
=
dict
(
type
=
'BN'
,
eps
=
1e-3
,
momentum
=
0.01
),
down_sample_rate
=
[
40
,
8
,
8
],
fusion_layer
=
None
,
cat_points
=
False
):
super
(
SECONDFusionFPN
,
self
).
__init__
(
use_norm
,
in_channels
,
upsample_strides
,
num_upsample_filters
,
norm_cfg
,
)
upsample_cfg
=
dict
(
type
=
'deconv'
,
bias
=
False
),
downsample_rates
=
[
40
,
8
,
8
],
fusion_layer
=
None
):
super
(
SECONDFusionFPN
,
self
).
__init__
(
in_channels
,
out_channels
,
upsample_strides
,
norm_cfg
,
upsample_cfg
)
self
.
fusion_layer
=
None
if
fusion_layer
is
not
None
:
self
.
fusion_layer
=
builder
.
build_fusion_layer
(
fusion_layer
)
self
.
cat_points
=
cat_points
self
.
down_sample_rate
=
down_sample_rate
self
.
downsample_rates
=
downsample_rates
def
forward
(
self
,
x
,
...
...
@@ -107,11 +118,11 @@ class SECONDFusionFPN(SECONDFPN):
downsample_pts_coors
=
torch
.
zeros_like
(
coors
)
downsample_pts_coors
[:,
0
]
=
coors
[:,
0
]
downsample_pts_coors
[:,
1
]
=
(
coors
[:,
1
]
/
self
.
down
_
sample_rate
[
0
])
coors
[:,
1
]
/
self
.
downsample_rate
s
[
0
])
downsample_pts_coors
[:,
2
]
=
(
coors
[:,
2
]
/
self
.
down
_
sample_rate
[
1
])
coors
[:,
2
]
/
self
.
downsample_rate
s
[
1
])
downsample_pts_coors
[:,
3
]
=
(
coors
[:,
3
]
/
self
.
down
_
sample_rate
[
2
])
coors
[:,
3
]
/
self
.
downsample_rate
s
[
2
])
# fusion for each point
out
=
self
.
fusion_layer
(
img_feats
,
points
,
out
,
downsample_pts_coors
,
img_meta
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment