Migration of masked_image_modeling_with_autoencoders to keras 3#2275
Conversation
Summary of ChangesHello @maitry63, 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 focuses on updating the 'Masked image modeling with Autoencoders' tutorial to be fully compatible with Keras 3. The primary goal was to achieve backend-agnosticism, allowing the tutorial to run seamlessly across various Keras 3 backends like JAX, PyTorch, and TensorFlow. This involved a comprehensive refactoring of tensor operations to use Highlights
🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console. Changelog
Activity
Using Gemini Code AssistThe 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
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 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
|
There was a problem hiding this comment.
Code Review
This pull request successfully migrates the Masked Image Modeling example to Keras 3, with a focus on making it backend-agnostic. The changes include updating TensorFlow-specific APIs to their keras.ops equivalents, introducing a PyDataset for data loading, and simplifying parts of the model implementation. However, there are several critical issues that prevent the code from being truly backend-agnostic as claimed, most notably the use of tf.GradientTape in the custom train_step and tf.gather. I've also pointed out some inconsistencies in the model architecture and opportunities for code cleanup and simplification.
|
@gemini-code-assist review |
There was a problem hiding this comment.
Code Review
This pull request does a great job of migrating the Masked Image Modeling example to Keras 3, making it backend-agnostic. The changes correctly replace TensorFlow-specific APIs with keras.ops and adopt Keras 3 conventions like using keras.utils.PyDataset. I've found one critical issue with the handling of the return value from model.evaluate() that will cause the script to fail. Additionally, there's a small oversight in the create_encoder function that was missed during the migration. In create_encoder, the MultiHeadAttention layer is still initialized with a dropout argument. This argument has been removed in Keras 3, and its presence will cause an error. It should be removed, just as it was in create_decoder. My detailed comment provides a suggestion for the other point.
|
@gemini-code-assist review |
There was a problem hiding this comment.
Code Review
This pull request successfully migrates the Masked Image Modeling example to Keras 3, making most of the code backend-agnostic by replacing TensorFlow-specific APIs with keras.ops. The changes are generally well-executed, improving code clarity and adhering to Keras 3 best practices. However, I've identified a few critical issues that need to be addressed. There's a bug in how the model evaluation results are handled, a regression in the data pipeline that removes shuffling for the training set, and a redundant image resizing step that alters the augmentation logic. Additionally, the linear probing part of the example still relies on tf.data.Dataset, which prevents it from being truly backend-agnostic. Addressing these points will ensure the example is correct, efficient, and fully compatible with all Keras backends.
|
@gemini-code-assist review |
There was a problem hiding this comment.
Code Review
This pull request successfully migrates the Masked Image Modeling example to Keras 3, making it backend-agnostic. The changes correctly adopt keras.ops for operations and keras.utils.PyDataset for data handling, and the custom training loop has been effectively refactored. However, I've identified a critical issue with a duplicated class definition that needs to be resolved. Additionally, there are several opportunities for cleanup, such as removing unused imports and commented-out code, which will enhance the overall quality and readability of the example. I've left specific comments with suggestions for these improvements.
sachinprasadhs
left a comment
There was a problem hiding this comment.
Thanks, made few comments, please address it.
sachinprasadhs
left a comment
There was a problem hiding this comment.
Few more comments to address.
|
Thanks, Looks good. Please generate .md and .ipynb files. |
|
This PR is stale because it has been open for 14 days with no activity. It will be closed if no further activity occurs. Thank you. |
This PR migrates the Masked image modeling with Autoencoders tutorial from Keras 2 to Keras 3. The implementation is now fully backend-agnostic, allowing it to run seamlessly on JAX, PyTorch, and TensorFlow (notebook).