fix(detection): scale from_tensorflow boxes by correct axes#2360
Open
RubenHaisma wants to merge 1 commit into
Open
fix(detection): scale from_tensorflow boxes by correct axes#2360RubenHaisma wants to merge 1 commit into
RubenHaisma wants to merge 1 commit into
Conversation
`Detections.from_tensorflow` scaled the normalized box coordinates by the wrong image dimensions: the y coordinates (ymin/ymax, columns 0 and 2) were multiplied by width and the x coordinates (xmin/xmax, columns 1 and 3) by height. Tensorflow Hub object-detection models emit `detection_boxes` as normalized `[ymin, xmin, ymax, xmax]`, so y must scale by height and x by width. The bug is masked on square images (width == height) but corrupts every coordinate on the common non-square case — e.g. a box normalized to `[0.1, 0.2, 0.5, 0.6]` on a 1000x500 image came out as `[100, 100, 300, 500]` instead of the correct `[200, 50, 600, 250]`. Swap the two multipliers so y scales by `resolution_wh[1]` (height) and x by `resolution_wh[0]` (width). Adds a non-square regression test (the connector was previously untested).
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## develop #2360 +/- ##
=======================================
Coverage 82% 82%
=======================================
Files 68 68
Lines 9560 9560
=======================================
+ Hits 7881 7886 +5
+ Misses 1679 1674 -5 🚀 New features to boost your workflow:
|
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.
Description
Detections.from_tensorflowscaled the normalized box coordinates by the wrong image dimensions. Tensorflow Hub object-detection models emitdetection_boxesas normalized[ymin, xmin, ymax, xmax](the connector's own[1, 0, 3, 2]reorder confirms this layout), so the y coordinates must scale by height and x by width. The code did the opposite:The bug is masked on square images (
width == height) but corrupts every coordinate on the common non-square case.Reproduction
A box normalized to
[ymin=0.1, xmin=0.2, ymax=0.5, xmax=0.6]on a1000×500image (resolution_wh=(1000, 500)):Correct values:
xmin = 0.2·1000,ymin = 0.1·500,xmax = 0.6·1000,ymax = 0.5·500.Fix
Swap the two multipliers so y scales by
resolution_wh[1](height) and x byresolution_wh[0](width). No behavior change on square images.Tests
Adds
test_from_tensorflow_scales_axes_on_non_square_image(the connector was previously untested — no references intests/ordocs/). It fails ondevelop([100,100,300,500]) and passes with this fix ([200,50,600,250]).ruff check/formatclean.