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
9c26a104
Unverified
Commit
9c26a104
authored
Jun 24, 2021
by
Jintao Lin
Committed by
GitHub
Jun 24, 2021
Browse files
empty tensor inference backward compatible (#1131)
* empty tensor inference backward continity * update * add 3d
parent
59ed0ddd
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
19 additions
and
5 deletions
+19
-5
mmcv/cnn/bricks/wrappers.py
mmcv/cnn/bricks/wrappers.py
+4
-4
tests/test_cnn/test_wrappers.py
tests/test_cnn/test_wrappers.py
+15
-1
No files found.
mmcv/cnn/bricks/wrappers.py
View file @
9c26a104
...
...
@@ -128,8 +128,8 @@ class ConvTranspose3d(nn.ConvTranspose3d):
class
MaxPool2d
(
nn
.
MaxPool2d
):
def
forward
(
self
,
x
):
# PyTorch 1.
7
does not support empty tensor inference yet
if
x
.
numel
()
==
0
and
obsolete_torch_version
(
TORCH_VERSION
,
(
1
,
7
)):
# PyTorch 1.
9
does not support empty tensor inference yet
if
x
.
numel
()
==
0
and
obsolete_torch_version
(
TORCH_VERSION
,
(
1
,
9
)):
out_shape
=
list
(
x
.
shape
[:
2
])
for
i
,
k
,
p
,
s
,
d
in
zip
(
x
.
shape
[
-
2
:],
_pair
(
self
.
kernel_size
),
_pair
(
self
.
padding
),
_pair
(
self
.
stride
),
...
...
@@ -146,8 +146,8 @@ class MaxPool2d(nn.MaxPool2d):
class
MaxPool3d
(
nn
.
MaxPool3d
):
def
forward
(
self
,
x
):
# PyTorch 1.
7
does not support empty tensor inference yet
if
x
.
numel
()
==
0
and
obsolete_torch_version
(
TORCH_VERSION
,
(
1
,
7
)):
# PyTorch 1.
9
does not support empty tensor inference yet
if
x
.
numel
()
==
0
and
obsolete_torch_version
(
TORCH_VERSION
,
(
1
,
9
)):
out_shape
=
list
(
x
.
shape
[:
2
])
for
i
,
k
,
p
,
s
,
d
in
zip
(
x
.
shape
[
-
3
:],
_triple
(
self
.
kernel_size
),
_triple
(
self
.
padding
),
...
...
tests/test_cnn/test_wrappers.py
View file @
9c26a104
...
...
@@ -330,7 +330,7 @@ def test_linear(in_w, in_h, in_feature, out_feature):
wrapper
(
x_empty
)
@
patch
(
'mmcv.cnn.bricks.wrappers.TORCH_VERSION'
,
(
1
,
8
))
@
patch
(
'mmcv.cnn.bricks.wrappers.TORCH_VERSION'
,
(
1
,
10
))
def
test_nn_op_forward_called
():
for
m
in
[
'Conv2d'
,
'ConvTranspose2d'
,
'MaxPool2d'
]:
...
...
@@ -347,6 +347,20 @@ def test_nn_op_forward_called():
wrapper
(
x_normal
)
nn_module_forward
.
assert_called_with
(
x_normal
)
for
m
in
[
'Conv3d'
,
'ConvTranspose3d'
,
'MaxPool3d'
]:
with
patch
(
f
'torch.nn.
{
m
}
.forward'
)
as
nn_module_forward
:
# randn input
x_empty
=
torch
.
randn
(
0
,
3
,
10
,
10
,
10
)
wrapper
=
eval
(
m
)(
3
,
2
,
1
)
wrapper
(
x_empty
)
nn_module_forward
.
assert_called_with
(
x_empty
)
# non-randn input
x_normal
=
torch
.
randn
(
1
,
3
,
10
,
10
,
10
)
wrapper
=
eval
(
m
)(
3
,
2
,
1
)
wrapper
(
x_normal
)
nn_module_forward
.
assert_called_with
(
x_normal
)
with
patch
(
'torch.nn.Linear.forward'
)
as
nn_module_forward
:
# randn input
x_empty
=
torch
.
randn
(
0
,
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