-
Notifications
You must be signed in to change notification settings - Fork 19.6k
Add Grain support to image_dataset_from_directory
and text_dataset_from_directory
#21593
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
Add Grain support to image_dataset_from_directory
and text_dataset_from_directory
#21593
Conversation
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 @james77777778, 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 significantly enhances the data loading capabilities within Keras by integrating Grain support into the image_dataset_from_directory
and text_dataset_from_directory
utilities. Users can now specify format="grain"
to leverage Grain's efficient data processing pipeline, offering an alternative to the default TensorFlow dataset format. This change involves refactoring core dataset utilities to be backend-agnostic, introducing new Grain-specific helpers, and updating file system handling to support diverse storage locations, ultimately providing greater flexibility and performance for data ingestion in Keras workflows.
Highlights
- Added
format
argument to dataset utilities: Theimage_dataset_from_directory
andtext_dataset_from_directory
utilities now accept a newformat
argument. This allows users to choose betweentf.data.Dataset
(default) andgrain.IterDataset
for their data loading needs. - New
grain_utils
module for Grain-specific utilities: A new module,grain_utils.py
, has been introduced to house helper functions specifically for handling Grain datasets, includingmake_batch
andmake_string_batch
for efficient data batching. - Improved file system handling for local and remote paths: The internal logic for handling file paths in
dataset_utils.py
has been enhanced to dynamically useos
ortf.io.gfile
based on the path prefix. This enables seamless support for both local and remote file systems (e.g., Google Cloud Storage, HDFS). - Refactored data loading and label processing for multi-backend support: The data loading and label processing functions within
image_dataset_utils.py
andtext_dataset_utils.py
have been refactored to support both TensorFlow and Grain backends, ensuring compatibility and flexibility. - Expanded test coverage for new
format
argument: Test suites for both image and text dataset utilities have been updated to include parameterized tests, thoroughly validating the newformat
argument across different scenarios and ensuring correct behavior for both TensorFlow and Grain outputs. - Grain text data returned as Python strings: When using
format="grain"
withtext_dataset_from_directory
, the text data will be returned as standard Python strings, as Grain does not natively support TensorFlow string tensors.
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 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
-
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 adds support for the grain
data format to image_dataset_from_directory
and text_dataset_from_directory
by introducing a format='grain'
option. The implementation is well-structured, creating parallel functions for grain
and tensorflow
data loading paths. The changes also include a refactoring in dataset_utils.py
to handle different filesystems (local vs. GCS/HDFS) in a more generic way. My feedback includes a couple of suggestions for further refactoring to improve code clarity, performance, and maintainability by reducing code duplication and leveraging existing utilities.
…_from_directory`.
4196615
to
4b791ab
Compare
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## master #21593 +/- ##
=========================================
Coverage ? 82.70%
=========================================
Files ? 568
Lines ? 56881
Branches ? 8889
=========================================
Hits ? 47045
Misses ? 7642
Partials ? 2194
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
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.
Awesome work! The code looks good to me.
This PR adds Grain support to
image_dataset_from_directory
andtext_dataset_from_directory
by includingformat="grain"
as an option.Note that the text will be Python strings when using
format="grain"
, since only TF supports string tensors.Here is a demo colab:
https://colab.research.google.com/drive/13RNE_KTbc13Shp5c1uIKzCbo-Ztfe5Ik?usp=sharing
cc @divyashreepathihalli @mattdangerw