Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
S
Segment-Object-Centric
Manage
Activity
Members
Labels
Plan
Issues
3
Issue boards
Milestones
Wiki
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Alexandre Chapin
Segment-Object-Centric
Commits
d8dcb3df
Commit
d8dcb3df
authored
1 year ago
by
Alexandre Chapin
Browse files
Options
Downloads
Patches
Plain Diff
Set all layers to right device
parent
86ac08b5
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
osrt/sam/transformer.py
+5
-0
5 additions, 0 deletions
osrt/sam/transformer.py
with
5 additions
and
0 deletions
osrt/sam/transformer.py
+
5
−
0
View file @
d8dcb3df
...
@@ -158,6 +158,7 @@ class TwoWayAttentionBlock(nn.Module):
...
@@ -158,6 +158,7 @@ class TwoWayAttentionBlock(nn.Module):
q
=
queries
+
query_pe
q
=
queries
+
query_pe
attn_out
=
self
.
self_attn
(
q
=
q
,
k
=
q
,
v
=
queries
)
attn_out
=
self
.
self_attn
(
q
=
q
,
k
=
q
,
v
=
queries
)
queries
=
queries
+
attn_out
queries
=
queries
+
attn_out
self
.
norm1
=
self
.
norm1
.
to
(
queries
.
device
)
queries
=
self
.
norm1
(
queries
)
queries
=
self
.
norm1
(
queries
)
# Cross attention block, tokens attending to image embedding
# Cross attention block, tokens attending to image embedding
...
@@ -165,18 +166,22 @@ class TwoWayAttentionBlock(nn.Module):
...
@@ -165,18 +166,22 @@ class TwoWayAttentionBlock(nn.Module):
k
=
keys
+
key_pe
k
=
keys
+
key_pe
attn_out
=
self
.
cross_attn_token_to_image
(
q
=
q
,
k
=
k
,
v
=
keys
)
attn_out
=
self
.
cross_attn_token_to_image
(
q
=
q
,
k
=
k
,
v
=
keys
)
queries
=
queries
+
attn_out
queries
=
queries
+
attn_out
self
.
norm2
=
self
.
norm2
.
to
(
queries
.
device
)
queries
=
self
.
norm2
(
queries
)
queries
=
self
.
norm2
(
queries
)
# MLP block
# MLP block
self
.
mlp
=
self
.
mlp
.
to
(
queries
.
device
)
mlp_out
=
self
.
mlp
(
queries
)
mlp_out
=
self
.
mlp
(
queries
)
queries
=
queries
+
mlp_out
queries
=
queries
+
mlp_out
queries
=
self
.
norm3
(
queries
)
queries
=
self
.
norm3
(
queries
)
self
.
norm3
=
self
.
norm3
.
to
(
queries
.
device
)
# Cross attention block, image embedding attending to tokens
# Cross attention block, image embedding attending to tokens
q
=
queries
+
query_pe
q
=
queries
+
query_pe
k
=
keys
+
key_pe
k
=
keys
+
key_pe
attn_out
=
self
.
cross_attn_image_to_token
(
q
=
k
,
k
=
q
,
v
=
queries
)
attn_out
=
self
.
cross_attn_image_to_token
(
q
=
k
,
k
=
q
,
v
=
queries
)
keys
=
keys
+
attn_out
keys
=
keys
+
attn_out
self
.
norm4
=
self
.
norm4
.
to
(
keys
.
device
)
keys
=
self
.
norm4
(
keys
)
keys
=
self
.
norm4
(
keys
)
return
queries
,
keys
return
queries
,
keys
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment