The difference between Tensorflow Graph and GraphDef

I am new to tensor flow. I would like to understand the conceptual difference between Graph and GraphDef.

Also, what should I run the graph loaded from the protobuf (.pb) file?

Thank!

+19
source share
3 answers

Graphor Computional Graph- the basic concept of a tensor flow to represent calculations. When you use tenorflow, you first create your own Computation Graphand pass this one Graphto tenorflow. How to do it? As you probably know, flow tensor supports many foreground programming languages ​​such as Python, C ++, Java, and Go, and the main language is C ++; how do other languages ​​convert Graphto C ++? They use a tool called protobufthat can generate specific language stubs from where GraphDef. This is a serialized version Graph.

which one do I need to run the graph loaded from the protobuf file (.pb)

*pb , GraphDef bind GraphDef ( ) Graph, Graph , :

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)
+30

GraphDef - - . . , GraphDef TensorFlow (Python, R, ++, Java,...). , .pb, GraphDef .pb.

- , . Python tf.Graph() Python (code), GraphDef .

python GraphDef, tf.import_graph_def. :

  with tf.gfile.GFile(graph_def_pb_file, "rb") as f:
    graph_def = tf.GraphDef()
    graph_def.ParseFromString(f.read())
  with tf.Graph().as_default() as graph:
    tf.import_graph_def(graph_def, name="")
    ...
+1

Is there a way to convert GraphDef initialized with ReadBinaryProto () to Graph, which can be used with TF_GraphNextOperation ()?

Thanks Fred

+1
source

Source: https://habr.com/ru/post/1688542/


All Articles