Skip to content
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

fix(applications): Improve validation and error handling for ConvNeXt weights and fix broadcasting in EfficientNetV2 #20785

Merged
merged 2 commits into from
Jan 20, 2025

Conversation

harshaljanjani
Copy link
Contributor

@harshaljanjani harshaljanjani commented Jan 20, 2025

Original Error Message (Unnecessary Model Weights Download):

Downloading data from https://storage.googleapis.com/tensorflow/keras-applications/convnext/convnext_large_notop.h5
785596384/785596384 ...
ValueError: Incomplete or corrupted file detected. The auto file hash does not match the provided value of 6fc8009faa2f00c1c1dfce59feea9b0745eb260a7dd11bee65c8e20843da6eab.

New Error Message (Prevents Unnecessary Download and Prompts Early):

ValueError: Model name "convnext_large" does not match weights variant "convnext_small". When using imagenet weights, the model name must contain the weights variant (e.g., "convnext_small").

Unintended Fix For EfficientNetV2:

Fixed a latent bug in EfficientNetV2's preprocessing for channels_first data format where mean and variance tensors were incorrectly shaped as [1,3] instead of [1,3,1,1]. This caused broadcasting errors when normalizing inputs in channels_first mode.

The issue was previously undetected because most users use channels_last format by default. The fix reshapes the normalization parameters to [1,3,1,1] for proper broadcasting across spatial dimensions when using channels_first, while maintaining the original behavior for channels_last format.

Bug revealed by: test_application_*_channels_first test failures
Impact: Affects all EfficientNetV2 models when used with channels_first data format

… weights

- Validate architecture and weights compatibility before API request.
- Enhance error messages for mismatched model name and weights.
@codecov-commenter
Copy link

codecov-commenter commented Jan 20, 2025

Codecov Report

Attention: Patch coverage is 63.63636% with 4 lines in your changes missing coverage. Please review.

Project coverage is 84.52%. Comparing base (a25881c) to head (74e3934).

Files with missing lines Patch % Lines
keras/src/applications/convnext.py 33.33% 2 Missing and 2 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master   #20785      +/-   ##
==========================================
+ Coverage   82.01%   84.52%   +2.50%     
==========================================
  Files         555      555              
  Lines       51856    51867      +11     
  Branches     8021     8025       +4     
==========================================
+ Hits        42530    43840    +1310     
+ Misses       7377     5927    -1450     
- Partials     1949     2100     +151     
Flag Coverage Δ
keras 84.35% <63.63%> (+2.51%) ⬆️
keras-jax 66.63% <63.63%> (+2.52%) ⬆️
keras-numpy 59.02% <0.00%> (+0.11%) ⬆️
keras-openvino 30.04% <0.00%> (+0.13%) ⬆️
keras-tensorflow 67.27% <63.63%> (+2.52%) ⬆️
keras-torch 66.69% <63.63%> (+2.51%) ⬆️
keras.applications 80.24% <63.63%> (?)
keras.applications-jax 80.24% <63.63%> (?)
keras.applications-numpy 22.82% <0.00%> (?)
keras.applications-openvino 22.82% <0.00%> (?)
keras.applications-tensorflow 80.24% <63.63%> (?)
keras.applications-torch 79.98% <63.63%> (?)

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.

…ls_first preprocessing in EfficientNetV2

- Reshaped mean and variance tensors to [1,3,1,1] for proper broadcasting in channels_first mode.
- Ensured compatibility with channels_last format while addressing broadcasting errors.
@harshaljanjani harshaljanjani changed the title fix(applications): Improve validation and error handling for ConvNeXt weights fix(applications): Improve validation and error handling for ConvNeXt weights and fix broadcasting in EfficientNetV2 Jan 20, 2025
Copy link
Collaborator

@fchollet fchollet left a comment

Choose a reason for hiding this comment

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

LGTM, thank you

@google-ml-butler google-ml-butler bot added kokoro:force-run ready to pull Ready to be merged into the codebase labels Jan 20, 2025
@fchollet fchollet merged commit 35f76b8 into keras-team:master Jan 20, 2025
8 checks passed
@google-ml-butler google-ml-butler bot removed ready to pull Ready to be merged into the codebase kokoro:force-run labels Jan 20, 2025
@harshaljanjani harshaljanjani deleted the verbose-error-convnext branch January 21, 2025 01:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
4 participants