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
742273a5
"git@developer.sourcefind.cn:chenpangpang/transformers.git" did not exist on "2f0f9038e29a9d35ca5e2d162d8cdbeee5123b24"
Unverified
Commit
742273a5
authored
Mar 03, 2022
by
Francesco Saverio Zuppichini
Committed by
GitHub
Mar 03, 2022
Browse files
fix for the output from post_process_panoptic_segmentation (#15916)
parent
7c45fe74
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
21 additions
and
2 deletions
+21
-2
src/transformers/models/maskformer/feature_extraction_maskformer.py
...ormers/models/maskformer/feature_extraction_maskformer.py
+1
-2
tests/maskformer/test_modeling_maskformer.py
tests/maskformer/test_modeling_maskformer.py
+20
-0
No files found.
src/transformers/models/maskformer/feature_extraction_maskformer.py
View file @
742273a5
...
@@ -538,7 +538,6 @@ class MaskFormerFeatureExtractor(FeatureExtractionMixin, ImageFeatureExtractionM
...
@@ -538,7 +538,6 @@ class MaskFormerFeatureExtractor(FeatureExtractionMixin, ImageFeatureExtractionM
# create the area, since bool we just need to sum :)
# create the area, since bool we just need to sum :)
mask_k_area
=
mask_k
.
sum
()
mask_k_area
=
mask_k
.
sum
()
# this is the area of all the stuff in query k
# this is the area of all the stuff in query k
# TODO not 100%, why are the taking the k query here????
original_area
=
(
mask_probs
[
k
]
>=
0.5
).
sum
()
original_area
=
(
mask_probs
[
k
]
>=
0.5
).
sum
()
mask_does_exist
=
mask_k_area
>
0
and
original_area
>
0
mask_does_exist
=
mask_k_area
>
0
and
original_area
>
0
...
@@ -565,5 +564,5 @@ class MaskFormerFeatureExtractor(FeatureExtractionMixin, ImageFeatureExtractionM
...
@@ -565,5 +564,5 @@ class MaskFormerFeatureExtractor(FeatureExtractionMixin, ImageFeatureExtractionM
)
)
if
is_stuff
:
if
is_stuff
:
stuff_memory_list
[
pred_class
]
=
current_segment_id
stuff_memory_list
[
pred_class
]
=
current_segment_id
results
.
append
({
"segmentation"
:
segmentation
,
"segments"
:
segments
})
results
.
append
({
"segmentation"
:
segmentation
,
"segments"
:
segments
})
return
results
return
results
tests/maskformer/test_modeling_maskformer.py
View file @
742273a5
...
@@ -404,3 +404,23 @@ class MaskFormerModelIntegrationTest(unittest.TestCase):
...
@@ -404,3 +404,23 @@ class MaskFormerModelIntegrationTest(unittest.TestCase):
outputs
=
model
(
**
inputs
)
outputs
=
model
(
**
inputs
)
self
.
assertTrue
(
outputs
.
loss
is
not
None
)
self
.
assertTrue
(
outputs
.
loss
is
not
None
)
def
test_panoptic_segmentation
(
self
):
model
=
MaskFormerForInstanceSegmentation
.
from_pretrained
(
self
.
model_checkpoints
).
to
(
torch_device
).
eval
()
feature_extractor
=
self
.
default_feature_extractor
inputs
=
feature_extractor
(
[
np
.
zeros
((
3
,
384
,
384
)),
np
.
zeros
((
3
,
384
,
384
))],
annotations
=
[
{
"masks"
:
np
.
random
.
rand
(
10
,
384
,
384
).
astype
(
np
.
float32
),
"labels"
:
np
.
zeros
(
10
).
astype
(
np
.
int64
)},
{
"masks"
:
np
.
random
.
rand
(
10
,
384
,
384
).
astype
(
np
.
float32
),
"labels"
:
np
.
zeros
(
10
).
astype
(
np
.
int64
)},
],
return_tensors
=
"pt"
,
)
with
torch
.
no_grad
():
outputs
=
model
(
**
inputs
)
panoptic_segmentation
=
feature_extractor
.
post_process_panoptic_segmentation
(
outputs
)
self
.
assertTrue
(
len
(
panoptic_segmentation
)
==
2
)
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