Fix wrong COCO bbox area in vector object-detection export - #885
Open
jaideeppyne wants to merge 1 commit into
Open
Fix wrong COCO bbox area in vector object-detection export#885jaideeppyne wants to merge 1 commit into
jaideeppyne wants to merge 1 commit into
Conversation
`sa_vector_to_coco_object_detection` computed the annotation `area` as
`(x2 - x1) * y2 - y1`. Operator precedence makes that `((x2 - x1) * y2) - y1`
instead of the COCO box area `(x2 - x1) * (y2 - y1)` (width * height). The error
term is `y1 * (width - 1)`, so `area` is wrong for every exported bbox that does
not sit against the top edge (`y1 == 0`). On the repo's own export golden box
`{x1:437.16, y1:341.5, x2:465.23, y2:357.09}` the old code yields 9682 while the
correct area is 437 (~22x off).
Reuse the already-computed `bbox` width/height (`int(bbox[2] * bbox[3])`),
matching the keypoint path and the instance-segmentation path. Intent is
unambiguous: the shipped golden fixture encodes width*height.
Adds a unit test asserting `area == int(width * height)` (and == 437 for that
box). It fails on the current code (9682) and passes with the fix. The existing
export tests never caught this because they only assert output filename equality
(`filecmp.dircmp`), never file contents.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
In
sa_vector_to_coco_object_detection(SA → COCO vector export), the annotationareais computed as:Operator precedence parses this as
((x2 - x1) * y2) - y1, not the COCO bounding-box area(x2 - x1) * (y2 - y1)(width × height). The missing parentheses around(y2 - y1)make the error term exactlyy1 * (width - 1), so the exportedareais wrong for every bbox that isn't flush against the top edge (y1 == 0).On this repo's own export golden box
{x1: 437.16, y1: 341.5, x2: 465.23, y2: 357.09}:area = 9682w * h→437(which is exactly what the shipped goldenTestVectorAnnotationImage.jsonlists)The sibling paths already do it right — instance-segmentation uses
int(_area(mask))and keypoint usesbbox[2] * bbox[3]— so the intent is unambiguous.Fix
bboxis already(x, y, width, height), so this reuses the computed width/height and mirrors the keypoint path.Tests
Adds
tests/unit/test_coco_object_detection_area.py, assertingarea == int(width * height)(and== 437for the golden box). It fails on the current code (assert 9682 == 437) and passes with the fix.The existing export tests never caught this because they only assert output filename equality (
filecmp.dircmpleft_only/right_only) and never compare file contents — so the wrongareavalues were never checked.