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
MMCV
Commits
c9d477bb
Unverified
Commit
c9d477bb
authored
Jan 12, 2023
by
mengpenghui
Committed by
GitHub
Jan 12, 2023
Browse files
[Fix] Fix a dilation bug of MLU-DCNv2 and add limitation of torchvision (#2519)
parent
2810718a
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
13 additions
and
35 deletions
+13
-35
mmcv/ops/modulated_deform_conv.py
mmcv/ops/modulated_deform_conv.py
+13
-35
No files found.
mmcv/ops/modulated_deform_conv.py
View file @
c9d477bb
...
...
@@ -355,10 +355,15 @@ class ModulatedDeformConv2dPack(ModulatedDeformConv2d):
if
IS_MLU_AVAILABLE
:
import
torchvision
from
mmcv.utils
import
digit_version
assert
digit_version
(
torchvision
.
__version__
)
>=
digit_version
(
'0.10.0a0'
),
'the version of torchvision should be >= 0.10.0'
from
torchvision.ops
import
deform_conv2d
as
tv_deform_conv2d
@
CONV_LAYERS
.
register_module
(
'DCNv2'
,
force
=
True
)
class
ModulatedDeformConv2dPack_MLU
(
nn
.
modules
.
Module
):
class
ModulatedDeformConv2dPack_MLU
(
ModulatedDeformConv2d
):
"""This class is the DCNv2 implementation of the MLU device. The MLU
backend support of the operator has been implemented in torchvision.
The mmcv registration mechanism is used for multiplexing here. The
...
...
@@ -377,31 +382,8 @@ if IS_MLU_AVAILABLE:
otherwise False.
"""
def
__init__
(
self
,
in_channels
:
int
,
out_channels
:
int
,
kernel_size
:
Union
[
int
,
Tuple
[
int
]],
stride
:
int
=
1
,
padding
:
int
=
0
,
dilation
:
int
=
1
,
groups
:
int
=
1
,
deform_groups
:
int
=
1
,
bias
:
Union
[
bool
,
str
]
=
True
):
super
().
__init__
()
self
.
in_channels
=
in_channels
self
.
out_channels
=
out_channels
self
.
kernel_size
=
_pair
(
kernel_size
)
self
.
stride
=
_pair
(
stride
)
self
.
padding
=
_pair
(
padding
)
self
.
dilation
=
_pair
(
dilation
)
self
.
groups
=
groups
self
.
deform_groups
=
deform_groups
self
.
weight
=
nn
.
Parameter
(
torch
.
Tensor
(
out_channels
,
in_channels
,
*
self
.
kernel_size
))
if
bias
:
self
.
bias
=
nn
.
Parameter
(
torch
.
Tensor
(
out_channels
))
else
:
self
.
register_parameter
(
'bias'
,
None
)
def
__init__
(
self
,
*
args
,
**
kwargs
):
super
().
__init__
(
*
args
,
**
kwargs
)
self
.
conv_offset
=
nn
.
Conv2d
(
self
.
in_channels
,
self
.
deform_groups
*
3
*
self
.
kernel_size
[
0
]
*
...
...
@@ -409,19 +391,15 @@ if IS_MLU_AVAILABLE:
kernel_size
=
self
.
kernel_size
,
stride
=
self
.
stride
,
padding
=
self
.
padding
,
dilation
=
self
.
dilation
,
bias
=
True
)
self
.
init_weights
()
def
init_weights
(
self
):
n
=
self
.
in_channels
for
k
in
self
.
kernel_size
:
n
*=
k
stdv
=
1.
/
math
.
sqrt
(
n
)
self
.
weight
.
data
.
uniform_
(
-
stdv
,
stdv
)
if
self
.
bias
is
not
None
:
self
.
bias
.
data
.
zero_
()
self
.
conv_offset
.
weight
.
data
.
zero_
()
self
.
conv_offset
.
bias
.
data
.
zero_
()
super
().
init_weights
()
if
hasattr
(
self
,
'conv_offset'
):
self
.
conv_offset
.
weight
.
data
.
zero_
()
self
.
conv_offset
.
bias
.
data
.
zero_
()
def
forward
(
self
,
x
):
out
=
self
.
conv_offset
(
x
)
...
...
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