tensorflow / rust

Rust language bindings for TensorFlow
Apache License 2.0
5.19k stars 422 forks source link

Why not having a constructor for Scope based on a Graph #385

Open ramon-garcia opened 2 years ago

ramon-garcia commented 2 years ago

Suppose that one, for instance, restores a graph from a file. Then one needs to add some elements. But one needs a Scope as an argument for building operations.

Tensorflow-java allows one to build a Scope from a Graph: see the example in the documentation. Why not in tensorflow-rust?

Best regards.

Corallus-Caninus commented 2 years ago

Hi Ramon-Garcia,

You can get the mutable graph for a scope with the following getter method: https://tensorflow.github.io/rust/src/tensorflow/scope.rs.html#329-332

You can then load the graph from disk into that graph using SavedModelBundle

as an example, I did something similar in the framework I'm trying to create (originally taken from example code in this repository) https://github.com/Corallus-Caninus/Brains/blob/main/src/lib.rs#L444 notice also that I grab the ops out of the deserialized Graph by using the GraphAPI names.

I hope this helps!

ramon-garcia commented 2 years ago

Thank you for the suggestion. But it looks counterintuitive.