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
abf691aa
Unverified
Commit
abf691aa
authored
May 23, 2023
by
Yih-Dar
Committed by
GitHub
May 23, 2023
Browse files
Fix PyTorch SAM tests (#23682)
fix Co-authored-by:
ydshieh
<
ydshieh@users.noreply.github.com
>
parent
b687af0b
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
4 additions
and
4 deletions
+4
-4
tests/models/sam/test_modeling_sam.py
tests/models/sam/test_modeling_sam.py
+4
-4
No files found.
tests/models/sam/test_modeling_sam.py
View file @
abf691aa
...
@@ -476,7 +476,7 @@ class SamModelIntegrationTest(unittest.TestCase):
...
@@ -476,7 +476,7 @@ class SamModelIntegrationTest(unittest.TestCase):
scores
=
outputs
.
iou_scores
.
squeeze
()
scores
=
outputs
.
iou_scores
.
squeeze
()
masks
=
outputs
.
pred_masks
[
0
,
0
,
0
,
0
,
:
3
]
masks
=
outputs
.
pred_masks
[
0
,
0
,
0
,
0
,
:
3
]
self
.
assertTrue
(
torch
.
allclose
(
scores
[
-
1
],
torch
.
tensor
(
0.4515
),
atol
=
2e-4
))
self
.
assertTrue
(
torch
.
allclose
(
scores
[
-
1
],
torch
.
tensor
(
0.4515
),
atol
=
2e-4
))
self
.
assertTrue
(
torch
.
allclose
(
masks
,
torch
.
tensor
([
-
4.180
7
,
-
3.494
9
,
-
3.448
3
]).
to
(
torch_device
),
atol
=
2e-4
))
self
.
assertTrue
(
torch
.
allclose
(
masks
,
torch
.
tensor
([
-
4.180
0
,
-
3.494
8
,
-
3.448
1
]).
to
(
torch_device
),
atol
=
2e-4
))
def
test_inference_mask_generation_one_point_one_bb
(
self
):
def
test_inference_mask_generation_one_point_one_bb
(
self
):
model
=
SamModel
.
from_pretrained
(
"facebook/sam-vit-base"
)
model
=
SamModel
.
from_pretrained
(
"facebook/sam-vit-base"
)
...
@@ -499,7 +499,7 @@ class SamModelIntegrationTest(unittest.TestCase):
...
@@ -499,7 +499,7 @@ class SamModelIntegrationTest(unittest.TestCase):
masks
=
outputs
.
pred_masks
[
0
,
0
,
0
,
0
,
:
3
]
masks
=
outputs
.
pred_masks
[
0
,
0
,
0
,
0
,
:
3
]
self
.
assertTrue
(
torch
.
allclose
(
scores
[
-
1
],
torch
.
tensor
(
0.9566
),
atol
=
2e-4
))
self
.
assertTrue
(
torch
.
allclose
(
scores
[
-
1
],
torch
.
tensor
(
0.9566
),
atol
=
2e-4
))
self
.
assertTrue
(
self
.
assertTrue
(
torch
.
allclose
(
masks
,
torch
.
tensor
([
-
12.7
657
,
-
12.36
83
,
-
12.
5985
]).
to
(
torch_device
),
atol
=
2e-4
)
torch
.
allclose
(
masks
,
torch
.
tensor
([
-
12.7
729
,
-
12.36
65
,
-
12.
6061
]).
to
(
torch_device
),
atol
=
2e-4
)
)
)
def
test_inference_mask_generation_batched_points_batched_images
(
self
):
def
test_inference_mask_generation_batched_points_batched_images
(
self
):
...
@@ -540,7 +540,7 @@ class SamModelIntegrationTest(unittest.TestCase):
...
@@ -540,7 +540,7 @@ class SamModelIntegrationTest(unittest.TestCase):
],
],
]
]
)
)
EXPECTED_MASKS
=
torch
.
tensor
([
-
2.855
2
,
-
2.79
90
,
-
2.96
1
2
])
EXPECTED_MASKS
=
torch
.
tensor
([
-
2.855
0
,
-
2.79
88
,
-
2.962
5
])
self
.
assertTrue
(
torch
.
allclose
(
scores
,
EXPECTED_SCORES
,
atol
=
1e-3
))
self
.
assertTrue
(
torch
.
allclose
(
scores
,
EXPECTED_SCORES
,
atol
=
1e-3
))
self
.
assertTrue
(
torch
.
allclose
(
masks
,
EXPECTED_MASKS
,
atol
=
1e-3
))
self
.
assertTrue
(
torch
.
allclose
(
masks
,
EXPECTED_MASKS
,
atol
=
1e-3
))
...
@@ -568,7 +568,7 @@ class SamModelIntegrationTest(unittest.TestCase):
...
@@ -568,7 +568,7 @@ class SamModelIntegrationTest(unittest.TestCase):
outputs
=
model
(
**
inputs
)
outputs
=
model
(
**
inputs
)
scores
=
outputs
.
iou_scores
.
squeeze
()
scores
=
outputs
.
iou_scores
.
squeeze
()
self
.
assertTrue
(
torch
.
allclose
(
scores
[
-
1
],
torch
.
tensor
(
0.789
2
),
atol
=
1e-4
))
self
.
assertTrue
(
torch
.
allclose
(
scores
[
-
1
],
torch
.
tensor
(
0.789
4
),
atol
=
1e-4
))
def
test_inference_mask_generation_one_point
(
self
):
def
test_inference_mask_generation_one_point
(
self
):
model
=
SamModel
.
from_pretrained
(
"facebook/sam-vit-base"
)
model
=
SamModel
.
from_pretrained
(
"facebook/sam-vit-base"
)
...
...
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