Skip to content

Conversation

@ILCSFNO
Copy link
Contributor

@ILCSFNO ILCSFNO commented Oct 16, 2025

Fixes #21749

@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @ILCSFNO, 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!

This pull request resolves an issue within the preprocess_input utility function in Keras, specifically targeting a scenario where image data is provided in a 3-dimensional format with channels as the first dimension. The fix ensures that the mean tensor used for normalization is correctly reshaped, preventing incorrect preprocessing and improving the robustness of image input pipelines for models expecting this specific data arrangement.

Highlights

  • Bug Fix: Addressed a bug in the _preprocess_tensor_input function that occurred when the input x was 3-dimensional and the data_format was set to channels_first.
  • Tensor Reshaping Logic: Modified the reshaping logic for mean_tensor to correctly handle 3D inputs with channels_first format, ensuring proper zero-centering.
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 by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

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 pull request 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 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. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

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

  1. 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.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a 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 correctly fixes a bug in _preprocess_tensor_input that occurred when preprocessing a 3D tensor with data_format='channels_first'. The previous implementation produced an incorrect shape for the mean_tensor, leading to a broadcasting error. The fix introduces a special case for 3D tensors which resolves the issue. My review includes a minor suggestion to improve the readability of the new code by simplifying an expression, in line with the Keras API design guidelines on minimizing cognitive load.

@codecov-commenter
Copy link

codecov-commenter commented Oct 16, 2025

Codecov Report

❌ Patch coverage is 33.33333% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 84.84%. Comparing base (a5e6d0a) to head (647d87d).

Files with missing lines Patch % Lines
keras/src/applications/imagenet_utils.py 33.33% 1 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master   #21750      +/-   ##
==========================================
+ Coverage   82.63%   84.84%   +2.21%     
==========================================
  Files         572      572              
  Lines       58551    58553       +2     
  Branches     9151     9152       +1     
==========================================
+ Hits        48381    49682    +1301     
+ Misses       7843     6428    -1415     
- Partials     2327     2443     +116     
Flag Coverage Δ
keras 84.66% <33.33%> (+2.22%) ⬆️
keras-jax 65.43% <33.33%> (+2.24%) ⬆️
keras-numpy 57.67% <0.00%> (+0.10%) ⬆️
keras-openvino 34.50% <0.00%> (+0.12%) ⬆️
keras-tensorflow 66.19% <33.33%> (+2.24%) ⬆️
keras-torch 65.73% <33.33%> (+2.22%) ⬆️
keras.applications 83.52% <33.33%> (?)
keras.applications-jax 83.52% <33.33%> (?)
keras.applications-numpy 22.79% <0.00%> (?)
keras.applications-openvino 22.79% <0.00%> (?)
keras.applications-tensorflow 83.52% <33.33%> (?)
keras.applications-torch 83.25% <33.33%> (?)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
@google-ml-butler google-ml-butler bot added kokoro:force-run ready to pull Ready to be merged into the codebase labels Oct 17, 2025
@hertschuh hertschuh merged commit c22de4b into keras-team:master Oct 17, 2025
11 checks passed
@ILCSFNO ILCSFNO deleted the patch-1 branch October 23, 2025 07:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ready to pull Ready to be merged into the codebase size:XS

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug in func keras.applications.vgg16.preprocess_input() when x in 3D and data_format=='channels_first'

5 participants