Skip to content

Conversation

@Pranay0302
Copy link
Contributor

Before submitting
  • Self-reviewed the code
  • Updated documentation (if applicable), following Google-style
  • Added docs entry for autogeneration (if new functions/classes)
  • Added/updated tests
  • All tests pass locally

Description

Improve YOLO polygon-to-mask conversion accuracy by rounding scaled polygon coordinates before integer casting. This removes a consistent top-left bias introduced by flooring behavior when coordinates contain decimals greater than 0.5.

Type of Change

  • 🐛 Bug fix (non-breaking change which fixes an issue)
  • 🧪 Test update

Motivation and Context

YOLO polygon annotations are stored as relative (float) coordinates. During mask conversion, coordinates were implicitly floored when cast to int, shifting polygons toward the top-left and producing inaccurate masks. This PR basically switches to rounding before integer conversion to align pixels correctly.

Closes #2023

Changes Made

  • Updated YOLO polygon scaling logic to apply np.round() prior to astype(int) to avoid systematic flooring bias.
  • Ensured scaling uses resolution_wh as float32 to prevent premature integer casting.
  • Added a regression test covering decimal polygon coordinates greater than 0.5 to validate rounding behavior.

Testing

  • I have tested this code locally
  • I have added unit tests that prove my fix is effective or that my feature works
  • All new and existing tests pass

Notes:

  • 22 YOLO format tests pass
  • 112 total dataset tests pass

Additional Notes

This is a non-breaking change that only affects polygon-to-mask conversion accuracy for YOLO polygon annotations with fractional coordinates.

@Pranay0302 Pranay0302 requested a review from SkalskiP as a code owner January 16, 2026 23:21
@CLAassistant
Copy link

CLAassistant commented Jan 16, 2026

CLA assistant check
All committers have signed the CLA.

@Pranay0302
Copy link
Contributor Author

Hey @SkalskiP, would you be able to review this?

@Pranay0302
Copy link
Contributor Author

Hey @Borda , when you have a moment could you please take a look at this PR and let me know if everything looks good on your end? Appreciate the review!

@codecov
Copy link

codecov bot commented Jan 23, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 52%. Comparing base (8419279) to head (777b183).
⚠️ Report is 1 commits behind head on develop.

Additional details and impacted files
@@           Coverage Diff           @@
##           develop   #2080   +/-   ##
=======================================
  Coverage       52%     52%           
=======================================
  Files           61      61           
  Lines         7076    7076           
=======================================
  Hits          3657    3657           
  Misses        3419    3419           
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@SkalskiP SkalskiP merged commit b85b41d into roboflow:develop Jan 23, 2026
23 of 24 checks passed
@SkalskiP
Copy link
Collaborator

Hi @Pranay0302 👋🏻 Thanks a lot for your interest in supervision and drafting this PR. Looks good. Merged!

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.

Conversion from YOLO polygons to masks is inaccurate

4 participants