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

Implement SavedModel I/O #5

Closed
frreiss opened this issue Jan 10, 2019 · 2 comments
Closed

Implement SavedModel I/O #5

frreiss opened this issue Jan 10, 2019 · 2 comments
Assignees

Comments

@frreiss
Copy link
Member

frreiss commented Jan 10, 2019

Add support for reading and writing TensorFlow SavedModel files to and from the GraphDef Editor's Graph class. See https://www.tensorflow.org/guide/extend/model_files for a description of the file format.

This support will involve giving the Graph additional fields to support the portions of SavedModel that are not already modeled in Graph -- notably the "signatures" for invoking the model in TensorFlow Serving.

Add regression tests that use the tf.Saver APIs to create temporary SavedModel files (see the Save and Restore guide for more information).

Add an example script in the examples folder that generates a SavedModel file, rewrites it into a second SavedModel file, then loads the second file into a TensorFlow graph and performs some inference.

@frreiss frreiss self-assigned this Jan 15, 2019
@frreiss
Copy link
Member Author

frreiss commented Jan 15, 2019

TensorFlow's APIs for reading and writing variable checkpoints are surprisingly Byzantine. Basically, the only supported way to touch those checkpoint files is through special ops that are only accessible via the tf.Saver class.

For the initial implementation of SavedModel support I'll put heavy restrictions on checkpointed variables. Specifically:

  • If the user creates a graph_def_editor.Graph directly from a tf.Graph, then:
    • Disallow the existence of save/restore ops in the graph. That is, we will raise an exception if any ops of the "Save", "SaveV2", "Restore", or "RestoreV2" variety are found in the graph.
    • When writing a SavedModel file, create an empty dummy TensorFlow graph and point a Saver at that graph, i.e.
      dummy_graph = tf.Graph()
      with dummy_graph.as_default():
          saver = tf.train.Saver(allow_empty=True)
          with tf.Session() as sess:
              saver.save(sess, save_path=_EXPORT_DIR, write_meta_graph=False, 
                         write_state=False)
      
  • If the user creates a graph_def_editor.Graph from a SavedModel "file", then:
    • Disallow modifications to variables in the graph (i.e. adding, removing, changing type, etc.)
    • Keep a pointer to the checkpoint file/directory in the original SavedModel
    • When writing the new SavedModel, copy the checkpoint info from the old one

@frreiss
Copy link
Member Author

frreiss commented Jan 21, 2019

Opened #14 to cover follow-on work. Closing this issue.

@frreiss frreiss closed this as completed Jan 21, 2019
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

No branches or pull requests

1 participant