Skip to content

wip: support MS-COCO bbox field in read_coco#1284

Draft
jveitchmichaelis wants to merge 1 commit into
weecology:mainfrom
jveitchmichaelis:coco_boxes
Draft

wip: support MS-COCO bbox field in read_coco#1284
jveitchmichaelis wants to merge 1 commit into
weecology:mainfrom
jveitchmichaelis:coco_boxes

Conversation

@jveitchmichaelis
Copy link
Copy Markdown
Collaborator

@jveitchmichaelis jveitchmichaelis commented Jan 24, 2026

Description

Add support for bounding box loading in utilities.read_coco. Previously we assumed that MS-COCO files are for polygon labels, but as the linked issue correctly points out, bbox only is perfectly valid.

This PR checks to see if the segmentation key is present, if not, load bbox and convert to a shapely bbox instead. I've added an explicit box/task argument for read_coco. Currently we only really support boxes, but in future I would add the same to read_file to allow for the other tasks we're working on.

Also adds a test case.

Tested with OAM-TCD (which has both formats):

image image

Related Issue(s)

Fixes #1281

AI-Assisted Development

Autocomplete

  • I used AI tools (e.g., GitHub Copilot, ChatGPT, etc.) in developing this PR
  • I understand all the code I'm submitting
  • I have reviewed and validated all AI-generated code

AI tools used (if applicable):
Copilot in VS Code

@jveitchmichaelis jveitchmichaelis changed the title support coco bbox format Support MS-COCO bbox format Jan 24, 2026
@jveitchmichaelis jveitchmichaelis changed the title Support MS-COCO bbox format Support MS-COCO bbox field in read_coco Jan 24, 2026
@jveitchmichaelis jveitchmichaelis changed the title Support MS-COCO bbox field in read_coco wip: support MS-COCO bbox field in read_coco Feb 9, 2026
Copy link
Copy Markdown
Member

@ethanwhite ethanwhite left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks good to me other than one minor note on naming for clarity. That said the logs for the test failures have expired so I'm not sure if there's an issue there. I'd suggest rebasing on main with the name changes and we'll see what they test say.

Comment on lines +445 to +446
# COCO bbox format is [x, y, width, height]
x, y, width, height = annotation["bbox"]
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably indicate that it's xmin and ymin for clarity

@jveitchmichaelis
Copy link
Copy Markdown
Collaborator Author

I'll double check this against the new polygon dataset and recall why this is WIP...

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.

utilities.read_file raises KeyError: 'segmentation' when loading valid COCO bbox annotations with segmentation

2 participants