-
Notifications
You must be signed in to change notification settings - Fork 6.6k
fix(genai): Bounding Box Sample - use consistent order of bounding box coordinates #13441
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
…nding box coordinates
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Summary of Changes
Hello @holtskinner, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!
I've addressed an inconsistency in the bounding box coordinate order within the boundingbox_with_txt_img.py
sample. This change standardizes the coordinate format to [y_min, x_min, y_max, x_max]
for clarity and correctness, updating the BoundingBox
model's documentation and the plot_bounding_boxes
function's implementation accordingly. Additionally, I've refactored safety settings to use enums for better code quality.
Highlights
- Coordinate Order Standardization: I've standardized the bounding box coordinate order in the
BoundingBox
model's docstring and theplot_bounding_boxes
function's logic from[x_min, y_min, x_max, y_max]
to the more consistent[y_min, x_min, y_max, x_max]
format. - Code Logic Update: I've modified the
plot_bounding_boxes
function to correctly interpret and scale the new[y_min, x_min, y_max, x_max]
coordinate format when drawing rectangles on the image, ensuring accurate visualization. - Safety Settings Refactoring: I've updated the
SafetySetting
configuration to useHarmCategory
andHarmBlockThreshold
enums instead of string literals, which improves type safety and code readability for the GenAI API calls. - Documentation and Example Updates: I've revised docstrings for
plot_bounding_boxes
and updated the example response comments to reflect the new coordinate order and provide more descriptive labels, enhancing clarity for users.
Using Gemini Code Assist
The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.
Invoking Gemini
You can request assistance from Gemini at any point in your pull request via creating an issue comment (i.e. comment on the pull request page) using either /gemini <command>
or @gemini-code-assist <command>
. Below is a summary of the supported commands.
Feature | Command | Description |
---|---|---|
Code Review | /gemini review |
Performs a code review for the current pull request in its current state. |
Pull Request Summary | /gemini summary |
Provides a summary of the current pull request in its current state. |
Comment | @gemini-code-assist | Responds in comments when explicitly tagged, both in issue comments and review comments. |
Help | /gemini help |
Displays a list of available commands. |
Customization
To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/
folder in the base of the repository. Detailed instructions can be found here.
Limitations & Feedback
Gemini Code Assist is currently in preview and may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments to provide feedback.
You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.
Footnotes
-
Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution. ↩
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code Review
This pull request successfully standardizes the bounding box coordinate order to [y_min, x_min, y_max, x_max]
, improving consistency and correctness in the boundingbox_with_txt_img.py
example. The changes are well-implemented across docstrings, plotting logic, and example responses. The use of enums for safety settings is also a good enhancement. My review includes one medium
severity suggestion to define the normalization scaling factor as a named constant to further improve code clarity and maintainability.
abs_y_min = int(bbox.box_2d[0] / 1000 * height) | ||
abs_x_min = int(bbox.box_2d[1] / 1000 * width) | ||
abs_y_max = int(bbox.box_2d[2] / 1000 * height) | ||
abs_x_max = int(bbox.box_2d[3] / 1000 * width) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The normalization factor 1000
is used multiple times (lines 63-66) for scaling coordinates. To improve readability and maintainability, consider defining this as a named constant, for example, NORMALIZATION_SCALE = 1000
.
This constant could be defined at the beginning of the plot_bounding_boxes
function (e.g., after draw = ImageDraw.Draw(im)
or before the for
loop) or even at the module level if this scale (0-1000) is a standard convention for these normalized coordinates.
Using a named constant makes the code's intent clearer (i.e., that these coordinates are scaled by a factor of 1000) and simplifies future modifications if this scaling factor ever needs to change.
The code suggestion below shows how these lines would look if NORMALIZATION_SCALE
were used. You would need to add the definition of NORMALIZATION_SCALE
(e.g., NORMALIZATION_SCALE = 1000
) elsewhere in an appropriate scope.
abs_y_min = int(bbox.box_2d[0] / 1000 * height) | |
abs_x_min = int(bbox.box_2d[1] / 1000 * width) | |
abs_y_max = int(bbox.box_2d[2] / 1000 * height) | |
abs_x_max = int(bbox.box_2d[3] / 1000 * width) | |
abs_y_min = int(bbox.box_2d[0] / NORMALIZATION_SCALE * height) | |
abs_x_min = int(bbox.box_2d[1] / NORMALIZATION_SCALE * width) | |
abs_y_max = int(bbox.box_2d[2] / NORMALIZATION_SCALE * height) | |
abs_x_max = int(bbox.box_2d[3] / NORMALIZATION_SCALE * width) |
Fixes b/425651706