Unable to visualize Inception v3 model in TensorBo

2019-05-11 23:06发布

问题:

I'm attempting to visualize Google's Inception v3 model using TensorBoard in TensorFlow 0.7.1 and am unable to do so. The TensorBoard Graph tab stalls with the statement

Data : Reading graph.pbtxt

I downloaded an un-Tarred the inception v3 model. The graph protobuffer is in /tmp/imagenet/classify_image_graph_def.pb.

Here's my code to dump the model:

import os
import os.path
import tensorflow as tf
from tensorflow.python.platform import gfile

INCEPTION_LOG_DIR = '/tmp/inception_v3_log'

if not os.path.exists(INCEPTION_LOG_DIR):
    os.makedirs(INCEPTION_LOG_DIR)
with tf.Session() as sess:
    model_filename = '/tmp/imagenet/classify_image_graph_def.pb'
    with gfile.FastGFile(model_filename, 'rb') as f:
        graph_def = tf.GraphDef()
        graph_def.ParseFromString(f.read())
        _ = tf.import_graph_def(graph_def, name='')
    writer = tf.train.SummaryWriter(INCEPTION_LOG_DIR, graph_def)
    writer.close()

This dumps a 91 MB file called events.out.tfevents.1456423256.[hostname] (same size as the graph protobuffer) so it seems that the graph is in there somewhere.

I ran TensorBoard as follows:

tensorboard --logdir /tmp/inception_v3_log

Which results in the aforementioned hung loading bar on the Graph page.

The Chrome JavaScript console yields this error:

Uncaught TypeError: Cannot read property '0' of undefined

which I assume is related to the fact that the graph is missing.

I've tried this with Chrome 48.0.2564.116 (64-bit) on OS X 10.11.3 both with TensorFlow 0.7.1 for Python 3 built using Bazel and TensorFlow 0.7.1 for Python 2 installed via pip with the exact same results.

I also verified that I can visualize the graph generated with the mnist_with_summaries example, so this is an issue specifically with the Inception model.

回答1:

Daniel,

I don't know about the protobuffer stuff you mention, but I think you may want to uninstall the protobuf and reinstall tensorflow.

After my upgrade (on Ubuntu) from tensorflow v0.6 to v0.7.1 I found the following post when I had trouble launching the tensorboard.

I think there was a problem with protobuf. Talked about here: https://github.com/tensorflow/tensorflow/issues/1134#issuecomment-185279000

I ended up uninstalling protobuf and reinstalling tensorboard. Now I can launch the board and view my graph. Good luck! :)

Don



回答2:

Use this code: This works for me:

import tensorflow as tf
from tensorflow.python.platform import gfile
with tf.Session() as sess:
    model_filename ='YouGraphNameWithPath.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='PathWhereSummaryWillBeSaved'
train_writer = tf.summary.FileWriter(LOGDIR)
train_writer.add_graph(sess.graph)