Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Fix mask loss to ignore padding areas in object detection#43466

Closed
raimbekovm wants to merge 1 commit into
huggingface:mainfrom
raimbekovm:fix-object-detection-loss-padding-mask
Closed

Fix mask loss to ignore padding areas in object detection#43466
raimbekovm wants to merge 1 commit into
huggingface:mainfrom
raimbekovm:fix-object-detection-loss-padding-mask

Conversation

@raimbekovm

Copy link
Copy Markdown
Contributor

What does this PR do?

Fixes the TODO in loss_for_object_detection.py:196 - mask loss now properly ignores padding areas.

When batching images of different sizes, nested_tensor_from_tensor_list pads smaller images. Previously, padding areas were included in dice_loss and sigmoid_focal_loss computation. Now we use the valid mask to exclude them.

Changes:

  • Add optional valid_mask parameter to dice_loss and sigmoid_focal_loss
  • Use valid mask in loss_masks method (both loss_for_object_detection.py and loss_rt_detr.py)
  • AMP compatible (preserves input dtype)
  • Backward compatible (valid_mask=None by default)

Before submitting

  • This PR fixes a typo or improves the docs (you can dismiss the other checks if that's the case).
  • Did you read the contributor guideline,
    Pull Request section?
  • Was this discussed/approved via a Github issue or the forum? Please add a link
    to it if that's the case.
  • Did you make sure to update the documentation with your changes?
  • Did you write any new necessary tests?

Who can review?

@molbap @ArthurZucker

@github-actions

Copy link
Copy Markdown
Contributor

View the CircleCI Test Summary for this PR:

https://huggingface.co/spaces/transformers-community/circle-ci-viz?pr=43466&sha=a453a5

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant