簡體   English   中英

張量板無圖

[英]Tensorboard no graph

我正在嘗試張量板以可視化網絡圖。 以下是有關MNIST分類的簡單CNN代碼。 該代碼來自tensorboard教程

碼:

import os
import tensorflow as tf
import urllib

GIST_URL = 'https://gist.githubusercontent.com/dandelionmane/4f02ab8f1451e276fea1f165a20336f1/raw/dfb8ee95b010480d56a73f324aca480b3820c180'
LOGDIR = '/tmp/mnist_tutorial/'

### MNIST EMBEDDINGS ###
mnist = tf.contrib.learn.datasets.mnist.read_data_sets(train_dir=LOGDIR + 'data', one_hot=True)

# Define a simple convolutional layer
def conv_layer(input, channels_in, channels_out):
    w = tf.Variable(tf.zeros([5, 5, channels_in, channels_out]))
    b = tf.Variable(tf.zeros([channels_out]))
    conv = tf.nn.conv2d(input, w, strides=[1, 1, 1, 1], padding="SAME")
    act = tf.nn.relu(conv + b)
    return act

def fc_layer(input, channels_in, channels_out):
    w = tf.Variable(tf.zeros([channels_in, channels_out]))
    b = tf.Variable(tf.zeros([channels_out]))
    act = tf.nn.relu(tf.matmul(input, w) + b)
    return act

def make_hparam_string(learning_rate, use_two_fc, use_two_conv):
  conv_param = "conv=2" if use_two_conv else "conv=1"
  fc_param = "fc=2" if use_two_fc else "fc=1"
  return "lr_%.0E,%s,%s" % (learning_rate, conv_param, fc_param)

 # Setup placeholders, and reshape the data
x = tf.placeholder(tf.float32, shape=[None, 784])
y = tf.placeholder(tf.float32, shape=[None, 10])
x_image = tf.reshape(x, [-1, 28, 28, 1])
# Create the network
conv1 = conv_layer(x_image, 1, 32)
pool1 = tf.nn.max_pool(conv1, ksize=[1, 2, 2, 1], strides=[1, 2, 2, 1], padding="SAME")
conv2 = conv_layer(pool1, 32, 64)
pool2 = tf.nn.max_pool(conv2, ksize=[1, 2, 2, 1], strides=[1, 2, 2, 1], padding="SAME")
flattened = tf.reshape(pool2, [-1, 7 * 7 * 64])
fc1 = fc_layer(flattened, 7 * 7 * 64, 1024)
logits = fc_layer(fc1, 1024, 10)



# Compute cross entropy as our loss function
cross_entropy = tf.reduce_mean(
      tf.nn.softmax_cross_entropy_with_logits(logits=logits, labels=y))
# Use an AdamOptimizer to train the network
train_step = tf.train.AdamOptimizer(1e-4).minimize(cross_entropy)
# compute the accuracy
correct_prediction = tf.equal(tf.argmax(logits, 1), tf.argmax(y, 1))
accuracy = tf.reduce_mean(tf.cast(correct_prediction, tf.float32))

sess = tf.Session()
# Initialize all the variables
sess.run(tf.global_variables_initializer())
hparam = make_hparam_string( .1,True,True)

writer = tf.summary.FileWriter(LOGDIR+hparam)
writer.add_graph(sess.graph)
# Train for 2000 steps
for i in range(20):
    batch = mnist.train.next_batch(100)
    # Occasionally report accuracy
    if i % 5 == 0:
      [train_accuracy] = sess.run([accuracy], feed_dict={x: batch[0], y: batch[1]})
      print("step %d, training accuracy %g" % (i, train_accuracy))
    # Run the training step
    sess.run(train_step, feed_dict={x: batch[0], y: batch[1]})
writer.close()

圖不存在! 為什么? 我也關閉作家。 (正如在這篇文章中提到的, 沒有帶有tensorboard的圖 )。 我不確定我缺少什么。

張量板:

$ tree mnist_tutorial/
mnist_tutorial/
├── data
│   ├── t10k-images-idx3-ubyte.gz
│   ├── t10k-labels-idx1-ubyte.gz
│   ├── train-images-idx3-ubyte.gz
│   └── train-labels-idx1-ubyte.gz
└── lr_1E-01,conv=2,fc=2
    └── events.out.tfevents.1503327291.neon-2.local

2 directories, 5 files

tensorboard logdir應該是什么。 我假設它是lr_1E-01,conv = 2,fc = 2,因為它包含事件文件,並傳遞給FileWriter。

您正在使用tensorflow Windows版本嗎? 請嘗試以下代碼:

tf.train.write_graph(sess.graph_def, LOGDIR+hparam, 'graph.pb', False)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM