I'm quite new to the tensorflow. I would like to understand to conceptual difference between Graph and GraphDef.
furthermore, which one should I have to run a graph loaded from protobuf file (.pb)?
Thanks!
GraphDef is the proto defined here. This is the serialized version of graph. You can print, store, or restore a GraphDef in any TensorFlow frontend (Python, R, C++, Java, ...).
TensorFlow uses graphs as the format for saved models when it exports them from Python. Graphs are also easily optimized, allowing the compiler to do transformations like: Statically infer the value of tensors by folding constant nodes in your computation ("constant folding").
proto. These are the fundamental building blocks of TensorFlow graphs, with each one defining a single operation along with its input connections.
You can use tf. function to make graphs out of your programs. It is a transformation tool that creates Python-independent dataflow graphs out of your Python code. This will help you create performant and portable models, and it is required to use SavedModel .
Graph
or Computional Graph
is the core concept of tensorflow to present computation. When you use tensorflow, you firstly create you own Computation Graph
and pass the Graph
to tensorflow. How to do that? As you may know, tensorflow support many front-end programming languages, like Python, C++, Java and Go and the core language is C++; how do the other languages transform the Graph
to C++? They use a tool called protobuf
which can generate specific language stubs, that's where the GraphDef
come from. It's a serialized version of Graph
.
which one should I have to run a graph loaded from protobuf file (.pb)
You should read your *pb
file using GraphDef
and bind
the GraphDef
to a (default) Graph
, then use a session to run the Graph
for computation, like the following code:
import tensorflow as tf from tensorflow.python.platform import gfile with tf.Session() as sess: model_filename ='PATH_TO_PB.pb' with gfile.FastGFile(model_filename, 'rb') as f: graph_def = tf.GraphDef() graph_def.ParseFromString(f.read()) g_in = tf.import_graph_def(graph_def) LOGDIR='/logs/tests/1/' train_writer = tf.summary.FileWriter(LOGDIR) train_writer.add_graph(sess.graph)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With