Skip to content
This repository was archived by the owner on Jan 1, 2025. It is now read-only.

matcher.py: empty annotation compatibility #135

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions mask2former/modeling/matcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,11 +134,16 @@ def memory_efficient_forward(self, outputs, targets):
with autocast(enabled=False):
out_mask = out_mask.float()
tgt_mask = tgt_mask.float()
# Compute the focal loss between masks
cost_mask = batch_sigmoid_ce_loss_jit(out_mask, tgt_mask)

# Compute the dice loss betwen masks
cost_dice = batch_dice_loss_jit(out_mask, tgt_mask)
is_annotation_empty = out_mask.shape[0] == 0 or tgt_mask.shape[0] == 0
if is_annotation_empty:
# Compute the focal loss between masks
cost_mask = batch_sigmoid_ce_loss(out_mask, tgt_mask)
# Compute the dice loss between masks
cost_dice = batch_dice_loss(out_mask, tgt_mask)
else:
cost_mask = batch_sigmoid_ce_loss_jit(out_mask, tgt_mask)
cost_dice = batch_dice_loss_jit(out_mask, tgt_mask)

# Final cost matrix
C = (
Expand Down