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
c0a354d8
Unverified
Commit
c0a354d8
authored
Dec 12, 2023
by
Chenhao Xu
Committed by
GitHub
Dec 11, 2023
Browse files
fix bug in mask2former: cost matrix is infeasible (#27897)
fix bug: cost matrix is infeasible
parent
7e35f370
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
3 additions
and
0 deletions
+3
-0
src/transformers/models/mask2former/modeling_mask2former.py
src/transformers/models/mask2former/modeling_mask2former.py
+3
-0
No files found.
src/transformers/models/mask2former/modeling_mask2former.py
View file @
c0a354d8
...
@@ -471,6 +471,9 @@ class Mask2FormerHungarianMatcher(nn.Module):
...
@@ -471,6 +471,9 @@ class Mask2FormerHungarianMatcher(nn.Module):
cost_dice
=
pair_wise_dice_loss
(
pred_mask
,
target_mask
)
cost_dice
=
pair_wise_dice_loss
(
pred_mask
,
target_mask
)
# final cost matrix
# final cost matrix
cost_matrix
=
self
.
cost_mask
*
cost_mask
+
self
.
cost_class
*
cost_class
+
self
.
cost_dice
*
cost_dice
cost_matrix
=
self
.
cost_mask
*
cost_mask
+
self
.
cost_class
*
cost_class
+
self
.
cost_dice
*
cost_dice
# eliminate infinite values in cost_matrix to avoid the error ``ValueError: cost matrix is infeasible``
cost_matrix
=
torch
.
minimum
(
cost_matrix
,
torch
.
tensor
(
1e10
))
cost_matrix
=
torch
.
maximum
(
cost_matrix
,
torch
.
tensor
(
-
1e10
))
# do the assigmented using the hungarian algorithm in scipy
# do the assigmented using the hungarian algorithm in scipy
assigned_indices
:
Tuple
[
np
.
array
]
=
linear_sum_assignment
(
cost_matrix
.
cpu
())
assigned_indices
:
Tuple
[
np
.
array
]
=
linear_sum_assignment
(
cost_matrix
.
cpu
())
indices
.
append
(
assigned_indices
)
indices
.
append
(
assigned_indices
)
...
...
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