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
vision
Commits
e75a3337
Unverified
Commit
e75a3337
authored
Jul 08, 2022
by
YosuaMichael
Committed by
GitHub
Jul 08, 2022
Browse files
Move out the pad operation from PatchMerging in swin transformer to make it fx compatible (#6252)
parent
f14682a8
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
10 additions
and
2 deletions
+10
-2
torchvision/models/swin_transformer.py
torchvision/models/swin_transformer.py
+10
-2
No files found.
torchvision/models/swin_transformer.py
View file @
e75a3337
...
@@ -25,6 +25,15 @@ __all__ = [
...
@@ -25,6 +25,15 @@ __all__ = [
]
]
def
_patch_merging_pad
(
x
):
H
,
W
,
_
=
x
.
shape
[
-
3
:]
x
=
F
.
pad
(
x
,
(
0
,
0
,
0
,
W
%
2
,
0
,
H
%
2
))
return
x
torch
.
fx
.
wrap
(
"_patch_merging_pad"
)
class
PatchMerging
(
nn
.
Module
):
class
PatchMerging
(
nn
.
Module
):
"""Patch Merging Layer.
"""Patch Merging Layer.
Args:
Args:
...
@@ -46,8 +55,7 @@ class PatchMerging(nn.Module):
...
@@ -46,8 +55,7 @@ class PatchMerging(nn.Module):
Returns:
Returns:
Tensor with layout of [..., H/2, W/2, 2*C]
Tensor with layout of [..., H/2, W/2, 2*C]
"""
"""
H
,
W
,
_
=
x
.
shape
[
-
3
:]
x
=
_patch_merging_pad
(
x
)
x
=
F
.
pad
(
x
,
(
0
,
0
,
0
,
W
%
2
,
0
,
H
%
2
))
x0
=
x
[...,
0
::
2
,
0
::
2
,
:]
# ... H/2 W/2 C
x0
=
x
[...,
0
::
2
,
0
::
2
,
:]
# ... H/2 W/2 C
x1
=
x
[...,
1
::
2
,
0
::
2
,
:]
# ... H/2 W/2 C
x1
=
x
[...,
1
::
2
,
0
::
2
,
:]
# ... H/2 W/2 C
...
...
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