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
c35c228c
Unverified
Commit
c35c228c
authored
May 12, 2020
by
Wenwei Zhang
Committed by
GitHub
May 12, 2020
Browse files
Support to pass args to cnn bricks (#277)
parent
d5936d02
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
22 additions
and
2 deletions
+22
-2
mmcv/cnn/bricks/upsample.py
mmcv/cnn/bricks/upsample.py
+6
-2
tests/test_cnn/test_build_layers.py
tests/test_cnn/test_build_layers.py
+16
-0
No files found.
mmcv/cnn/bricks/upsample.py
View file @
c35c228c
...
@@ -47,7 +47,7 @@ class PixelShufflePack(nn.Module):
...
@@ -47,7 +47,7 @@ class PixelShufflePack(nn.Module):
return
x
return
x
def
build_upsample_layer
(
cfg
):
def
build_upsample_layer
(
cfg
,
*
args
,
**
kwargs
):
"""Build upsample layer.
"""Build upsample layer.
Args:
Args:
...
@@ -56,6 +56,10 @@ def build_upsample_layer(cfg):
...
@@ -56,6 +56,10 @@ def build_upsample_layer(cfg):
- scale_factor (int): Upsample ratio, which is not applicable to
- scale_factor (int): Upsample ratio, which is not applicable to
deconv.
deconv.
- layer args: Args needed to instantiate a upsample layer.
- layer args: Args needed to instantiate a upsample layer.
args (argument list): Arguments passed to the `__init__`
method of the corresponding conv layer.
kwargs (keyword arguments): Keyword arguments passed to the `__init__`
method of the corresponding conv layer.
Returns:
Returns:
nn.Module: Created upsample layer.
nn.Module: Created upsample layer.
...
@@ -75,5 +79,5 @@ def build_upsample_layer(cfg):
...
@@ -75,5 +79,5 @@ def build_upsample_layer(cfg):
if
upsample
is
nn
.
Upsample
:
if
upsample
is
nn
.
Upsample
:
cfg_
[
'mode'
]
=
layer_type
cfg_
[
'mode'
]
=
layer_type
layer
=
upsample
(
**
cfg_
)
layer
=
upsample
(
*
args
,
**
kwargs
,
**
cfg_
)
return
layer
return
layer
tests/test_cnn/test_build_layers.py
View file @
c35c228c
...
@@ -226,6 +226,22 @@ def test_upsample_layer():
...
@@ -226,6 +226,22 @@ def test_upsample_layer():
layer
=
build_upsample_layer
(
cfg
)
layer
=
build_upsample_layer
(
cfg
)
assert
isinstance
(
layer
,
nn
.
ConvTranspose2d
)
assert
isinstance
(
layer
,
nn
.
ConvTranspose2d
)
cfg
=
dict
(
type
=
'deconv'
)
kwargs
=
dict
(
in_channels
=
3
,
out_channels
=
3
,
kernel_size
=
3
,
stride
=
2
)
layer
=
build_upsample_layer
(
cfg
,
**
kwargs
)
assert
isinstance
(
layer
,
nn
.
ConvTranspose2d
)
assert
layer
.
in_channels
==
kwargs
[
'in_channels'
]
assert
layer
.
out_channels
==
kwargs
[
'out_channels'
]
assert
layer
.
kernel_size
==
(
kwargs
[
'kernel_size'
],
kwargs
[
'kernel_size'
])
assert
layer
.
stride
==
(
kwargs
[
'stride'
],
kwargs
[
'stride'
])
layer
=
build_upsample_layer
(
cfg
,
3
,
3
,
3
,
2
)
assert
isinstance
(
layer
,
nn
.
ConvTranspose2d
)
assert
layer
.
in_channels
==
kwargs
[
'in_channels'
]
assert
layer
.
out_channels
==
kwargs
[
'out_channels'
]
assert
layer
.
kernel_size
==
(
kwargs
[
'kernel_size'
],
kwargs
[
'kernel_size'
])
assert
layer
.
stride
==
(
kwargs
[
'stride'
],
kwargs
[
'stride'
])
cfg
=
dict
(
cfg
=
dict
(
type
=
'pixel_shuffle'
,
type
=
'pixel_shuffle'
,
in_channels
=
3
,
in_channels
=
3
,
...
...
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