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

There should be a way to obtain a variable from a saved model #394

Open
ramon-garcia opened this issue Jan 29, 2023 · 3 comments
Open

There should be a way to obtain a variable from a saved model #394

ramon-garcia opened this issue Jan 29, 2023 · 3 comments

Comments

@ramon-garcia
Copy link
Contributor

ramon-garcia commented Jan 29, 2023

If one restores a model with SavedModelBundle::load() and obtains a graph, there is no way to get Variables from it. One can obtain an Operation with Graph::operation_by_name_required, but not a Variable.

Variable objects are needed, for instance, to run an optimizer with optimizer.minimize.

@ramon-garcia
Copy link
Contributor Author

In addition, in models generated with Tensorflow 2, variables are implemented as ops of type VarHandleOp. In Tensorflow/Rust, variables are implemented as ops of type Variable2. This can make it more difficult to work with models generated with Python.

@camdenmcgath
Copy link

@ramon-garcia @adamcrume I'd be happy to look in to this if this is an issue you guys still need fixed. Would I start by implementing some function like Graph::variable_by_name_required similar to operation by name? Also do I need to reconcile the use of both VarHandleOp and Variable2 types?

@adamcrume
Copy link
Contributor

Inside the proto in MetaGraphDef::from_serialized_proto, you can find the collection_def with the key variables, and value.bytes_list.value should contain a serialized VariableDef proto. That (plus metadata from the tensor referred to by VariableDef.variable_name) should be enough info to create a Variable struct.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants