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
chenpangpang
transformers
Commits
a1c4b630
Unverified
Commit
a1c4b630
authored
Jun 22, 2023
by
Matt
Committed by
GitHub
Jun 22, 2023
Browse files
TF CI fix for Segformer (#24426)
Fix segformer so compilation can figure out the channel dim
parent
754f61ca
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
5 additions
and
6 deletions
+5
-6
src/transformers/models/segformer/modeling_tf_segformer.py
src/transformers/models/segformer/modeling_tf_segformer.py
+5
-6
No files found.
src/transformers/models/segformer/modeling_tf_segformer.py
View file @
a1c4b630
...
...
@@ -710,21 +710,20 @@ class TFSegformerDecodeHead(TFSegformerPreTrainedModel):
self
.
config
=
config
def
call
(
self
,
encoder_hidden_states
,
training
:
bool
=
False
):
batch_size
=
shape_list
(
encoder_hidden_states
[
-
1
])[
0
]
all_hidden_states
=
()
for
encoder_hidden_state
,
mlp
in
zip
(
encoder_hidden_states
,
self
.
mlps
):
if
self
.
config
.
reshape_last_stage
is
False
and
len
(
shape_list
(
encoder_hidden_state
))
==
3
:
height
=
tf
.
math
.
sqrt
(
tf
.
cast
(
shape_list
(
encoder_hidden_state
)[
1
],
tf
.
float32
))
height
=
width
=
tf
.
cast
(
height
,
tf
.
int32
)
encoder_hidden_state
=
tf
.
reshape
(
encoder_hidden_state
,
(
batch_size
,
height
,
width
,
-
1
))
channel_dim
=
shape_list
(
encoder_hidden_state
)[
-
1
]
encoder_hidden_state
=
tf
.
reshape
(
encoder_hidden_state
,
(
-
1
,
height
,
width
,
channel_dim
))
# unify channel dimension
encoder_hidden_state
=
tf
.
transpose
(
encoder_hidden_state
,
perm
=
[
0
,
2
,
3
,
1
])
height
=
shape_list
(
encoder_hidden_state
)[
1
]
width
=
shape_list
(
encoder_hidden_state
)[
2
]
height
,
width
=
shape_list
(
encoder_hidden_state
)[
1
:
3
]
encoder_hidden_state
=
mlp
(
encoder_hidden_state
)
encoder_hidden_state
=
tf
.
reshape
(
encoder_hidden_state
,
(
batch_size
,
height
,
width
,
-
1
))
channel_dim
=
shape_list
(
encoder_hidden_state
)[
-
1
]
encoder_hidden_state
=
tf
.
reshape
(
encoder_hidden_state
,
(
-
1
,
height
,
width
,
channel_dim
))
# upsample
temp_state
=
tf
.
transpose
(
encoder_hidden_states
[
0
],
perm
=
[
0
,
2
,
3
,
1
])
...
...
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