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

Add asset zipping functionality to TFJS converter #6915

Merged
merged 8 commits into from Oct 12, 2022
Merged

Conversation

ahmedsabie
Copy link
Contributor

@ahmedsabie ahmedsabie commented Oct 8, 2022

The asset files are used for the TFDF library. Does not change behavior of existing models.

To see the logs from the Cloud Build CI, please join either our discussion or announcement mailing list.


This change is Reviewable

@ahmedsabie ahmedsabie marked this pull request as ready for review October 8, 2022 18:30
Copy link
Collaborator

@pyu10055 pyu10055 left a comment

Choose a reason for hiding this comment

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

Reviewable status: 0 of 1 approvals obtained (waiting on @ahmedsabie and @lina128)


tfjs-converter/python/tensorflowjs/converters/tf_saved_model_conversion_v2.py line 25 at r1 (raw file):

import shutil
import tempfile
from zipfile import ZipFile

does the zipfile library have any python version requirement?


tfjs-converter/python/tensorflowjs/converters/tf_saved_model_conversion_v2.py line 428 at r1 (raw file):

                                            saved_model.signatures.keys()))

def _copy_assets(saved_model_dir, output_dir):

should this function only trigger if the user specify the need to copy assets? (i.e. tfdf model).
This should be controlled by a parameter on the tfjs-converter command line.


tfjs-converter/python/tensorflowjs/converters/tf_saved_model_conversion_v2.py line 437 at r1 (raw file):

    with ZipFile(zip_path, 'w') as archive:
      for (input_dir_path, _, file_names) in tf.io.gfile.walk(input_assets_path):

does this copy nested directories too?

Copy link
Collaborator

@lina128 lina128 left a comment

Choose a reason for hiding this comment

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

LGTM

Reviewable status: :shipit: complete! 1 of 1 approvals obtained (waiting on @ahmedsabie)

Copy link
Contributor Author

@ahmedsabie ahmedsabie left a comment

Choose a reason for hiding this comment

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

Reviewable status: :shipit: complete! 1 of 1 approvals obtained (waiting on @pyu10055)


tfjs-converter/python/tensorflowjs/converters/tf_saved_model_conversion_v2.py line 25 at r1 (raw file):

Previously, pyu10055 (Ping Yu) wrote…

does the zipfile library have any python version requirement?

No its builtin


tfjs-converter/python/tensorflowjs/converters/tf_saved_model_conversion_v2.py line 428 at r1 (raw file):

Previously, pyu10055 (Ping Yu) wrote…

should this function only trigger if the user specify the need to copy assets? (i.e. tfdf model).
This should be controlled by a parameter on the tfjs-converter command line.

Assets are defined as "arbitrary files that are needed for model use". If we don't support the asset then the model wouldn't run anyways so it should never be a useless copy, and I don't think its good user experience for users to have to know that TFDF uses assets under the hood


tfjs-converter/python/tensorflowjs/converters/tf_saved_model_conversion_v2.py line 437 at r1 (raw file):

Previously, pyu10055 (Ping Yu) wrote…

does this copy nested directories too?

walk is recursive

Copy link
Collaborator

@pyu10055 pyu10055 left a comment

Choose a reason for hiding this comment

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

Reviewable status: :shipit: complete! 1 of 1 approvals obtained (waiting on @ahmedsabie)


tfjs-converter/python/tensorflowjs/converters/tf_saved_model_conversion_v2.py line 428 at r1 (raw file):

Previously, ahmedsabie wrote…

Assets are defined as "arbitrary files that are needed for model use". If we don't support the asset then the model wouldn't run anyways so it should never be a useless copy, and I don't think its good user experience for users to have to know that TFDF uses assets under the hood

good point, form the convert_tf_save_model() method perspective, it should be a parameter flag, since for non-tfdf model it should not zip the assets.

Copy link
Contributor Author

@ahmedsabie ahmedsabie left a comment

Choose a reason for hiding this comment

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

Reviewable status: :shipit: complete! 1 of 1 approvals obtained (waiting on @pyu10055)


tfjs-converter/python/tensorflowjs/converters/tf_saved_model_conversion_v2.py line 428 at r1 (raw file):

Previously, pyu10055 (Ping Yu) wrote…

good point, form the convert_tf_save_model() method perspective, it should be a parameter flag, since for non-tfdf model it should not zip the assets.

How about checking if the model is a TFDF model after loading and if so add the assets? That way no one calling needs to know what the model they are passing in

Copy link
Collaborator

@pyu10055 pyu10055 left a comment

Choose a reason for hiding this comment

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

Reviewed 2 of 2 files at r1.
Reviewable status: :shipit: complete! 2 of 1 approvals obtained (waiting on @ahmedsabie)


tfjs-converter/python/tensorflowjs/converters/tf_saved_model_conversion_v2.py line 428 at r1 (raw file):

Previously, ahmedsabie wrote…

How about checking if the model is a TFDF model after loading and if so add the assets? That way no one calling needs to know what the model they are passing in

agree, thanks

@ahmedsabie ahmedsabie merged commit 567754e into master Oct 12, 2022
@ahmedsabie ahmedsabie deleted the converter-assets branch October 12, 2022 17:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants