Skip to content

Instantly share code, notes, and snippets.

@jubjamie
Created March 31, 2017 10:01
Show Gist options
  • Save jubjamie/2eec49ca1e4f58c5310d72918d991ef6 to your computer and use it in GitHub Desktop.
Save jubjamie/2eec49ca1e4f58c5310d72918d991ef6 to your computer and use it in GitHub Desktop.
Load .pb into Tensorboard
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)
@AI-ML-Enthusiast
Copy link

@jubjamie @ Santosh7vasa

I run the code and it saved a file like this "events.out.tfevents.1574405033.DESKTOP-TOJGNRH". Now How can I load to tensorboard and view the graph
Thanks

@cristiandapp
Copy link

cristiandapp commented Mar 14, 2021

Hi, I used it in colab:

import tensorflow as tf
from tensorflow.python.platform import gfile
with tf.Session() as sess:
    model_filename ='/content/saved_model.pb'
    with tf.gfile.GFile(model_filename, 'rb') as f:
        graph_def = tf.GraphDef()
        train_writerd.flush()
        train_writerd.close()
        graph_def.ParseFromString(f.read())
        g_in = tf.import_graph_def(graph_def)
LOGDIR='/content'
train_writerd = tf.summary.FileWriter(LOGDIR)
train_writerd.add_graph(sess.graph)

At the end I got this error: NameError: name 'train_writerd' is not defined

@AfifaIshtiaq
Copy link

I couldn't se any graph
import tensorflow as tf
from tensorflow.python.platform import gfile
with tf.compat.v1.Session() as sess:
model_filename ='inception_v1_inference.pb'
with tf.io.gfile.GFile(model_filename, 'rb') as f:
graph_def = tf.compat.v1.GraphDef()
graph_def.ParseFromString(f.read())
g_in = tf.import_graph_def(graph_def)
LOGDIR='logs/tests/1/'
train_writer = tf.compat.v1.summary.FileWriter(LOGDIR)
train_writer.add_graph(sess.graph)

image

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