TensorBoard使用
来源:互联网 发布:公共网络摄像头直播 编辑:程序博客网 时间:2024/05/17 02:57
先跑一个小例程
'''Graph and Loss visualization using Tensorboard.This example is using the MNIST database of handwritten digits(http://yann.lecun.com/exdb/mnist/)Author: Aymeric DamienProject: https://github.com/aymericdamien/TensorFlow-Examples/'''from __future__ import print_functionimport tensorflow as tf# Import MNIST datafrom tensorflow.examples.tutorials.mnist import input_datamnist = input_data.read_data_sets("/tmp/data/", one_hot=True)# Parameterslearning_rate = 0.01training_epochs = 25batch_size = 100display_step = 1logs_path = '/tmp/tensorflow_logs/example'# Network Parametersn_hidden_1 = 256 # 1st layer number of featuresn_hidden_2 = 256 # 2nd layer number of featuresn_input = 784 # MNIST data input (img shape: 28*28)n_classes = 10 # MNIST total classes (0-9 digits)# tf Graph Input# mnist data image of shape 28*28=784x = tf.placeholder(tf.float32, [None, 784], name='InputData')# 0-9 digits recognition => 10 classesy = tf.placeholder(tf.float32, [None, 10], name='LabelData')# Create modeldef multilayer_perceptron(x, weights, biases): # Hidden layer with RELU activation layer_1 = tf.add(tf.matmul(x, weights['w1']), biases['b1']) layer_1 = tf.nn.relu(layer_1) # Create a summary to visualize the first layer ReLU activation #tf.summary.histogram("relu1", layer_1) tf.histogram_summary("relu1", layer_1) # Hidden layer with RELU activation layer_2 = tf.add(tf.matmul(layer_1, weights['w2']), biases['b2']) layer_2 = tf.nn.relu(layer_2) # Create another summary to visualize the second layer ReLU activation #tf.summary.histogram("relu2", layer_2) tf.histogram_summary("relu2", layer_2) # Output layer out_layer = tf.add(tf.matmul(layer_2, weights['w3']), biases['b3']) return out_layer# Store layers weight & biasweights = { 'w1': tf.Variable(tf.random_normal([n_input, n_hidden_1]), name='W1'), 'w2': tf.Variable(tf.random_normal([n_hidden_1, n_hidden_2]), name='W2'), 'w3': tf.Variable(tf.random_normal([n_hidden_2, n_classes]), name='W3')}biases = { 'b1': tf.Variable(tf.random_normal([n_hidden_1]), name='b1'), 'b2': tf.Variable(tf.random_normal([n_hidden_2]), name='b2'), 'b3': tf.Variable(tf.random_normal([n_classes]), name='b3')}# Encapsulating all ops into scopes, making Tensorboard's Graph# Visualization more convenientwith tf.name_scope('Model'): # Build model pred = multilayer_perceptron(x, weights, biases)with tf.name_scope('Loss'): # Softmax Cross entropy (cost function) loss = tf.reduce_mean(tf.nn.softmax_cross_entropy_with_logits(pred, y))with tf.name_scope('SGD'): # Gradient Descent optimizer = tf.train.GradientDescentOptimizer(learning_rate) # Op to calculate every variable gradient grads = tf.gradients(loss, tf.trainable_variables()) grads = list(zip(grads, tf.trainable_variables())) # Op to update all variables according to their gradient apply_grads = optimizer.apply_gradients(grads_and_vars=grads)with tf.name_scope('Accuracy'): # Accuracy acc = tf.equal(tf.argmax(pred, 1), tf.argmax(y, 1)) acc = tf.reduce_mean(tf.cast(acc, tf.float32))# Initializing the variablesinit = tf.initialize_all_variables()# Create a summary to monitor cost tensortf.scalar_summary("loss", loss)# Create a summary to monitor accuracy tensortf.scalar_summary("accuracy", acc)# Create summaries to visualize weightsfor var in tf.trainable_variables(): tf.histogram_summary(var.name, var)# Summarize all gradientsfor grad, var in grads: tf.histogram_summary(var.name + '/gradient', grad)# Merge all summaries into a single opmerged_summary_op = tf.merge_all_summaries()# Launch the graphwith tf.Session() as sess: sess.run(init) # op to write logs to Tensorboard summary_writer = tf.train.SummaryWriter(logs_path, graph=tf.get_default_graph()) # Training cycle for epoch in range(training_epochs): avg_cost = 0. total_batch = int(mnist.train.num_examples/batch_size) # Loop over all batches for i in range(total_batch): batch_xs, batch_ys = mnist.train.next_batch(batch_size) # Run optimization op (backprop), cost op (to get loss value) # and summary nodes _, c, summary = sess.run([apply_grads, loss, merged_summary_op], feed_dict={x: batch_xs, y: batch_ys}) # Write logs at every iteration summary_writer.add_summary(summary, epoch * total_batch + i) # Compute average loss avg_cost += c / total_batch # Display logs per epoch step if (epoch+1) % display_step == 0: print("Epoch:", '%04d' % (epoch+1), "cost=", "{:.9f}".format(avg_cost)) print("Optimization Finished!") # Test model # Calculate accuracy print("Accuracy:", acc.eval({x: mnist.test.images, y: mnist.test.labels})) print("Run the command line:\n" \ "--> tensorboard --logdir=/tmp/tensorflow_logs " \"\nThen open http://0.0.0.0:6006/ into your web browser")
运行该程序。
运行完了之后,可以在"/tmp/tensorflow_logs/example"目录下找到事件记录文件"events.out.tfevents.1490276692.inspur.datanode7.com"。
输入"tensorboard --logdir=/tmp/tensorflow_logs"
这个时候就遇到问题啦~看下面呢:
[root@inspur example]# tensorboard --logdir=/tmp/tensorflow_logsERROR:tensorflow:Tried to connect to port 6006, but address is in use.6006端口被占用了,把它干掉好啦。
[root@inspur example]# lsof -i:6006COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAMEtensorboa 28508 root 4u IPv4 18373697 0t0 TCP *:6006 (LISTEN)[root@inspur example]# kill -9 28508[root@inspur example]# tensorboard --logdir=/tmp/tensorflow_logsStarting TensorBoard b'23' on port 6006(You can navigate to http://0.0.0.0:6006)
进程号为28508的进程占用了端口6006,用kill命令干掉。
另外程序是在服务器上跑得,所以在本机上查看的时候,网址要输 ‘’服务器IP:6006"
0 1
- TensorBoard使用
- TensorBoard使用
- TensorBoard使用
- 使用TensorBoard
- TensorBoard使用
- tensorboard的使用
- tensorboard 使用报错
- tensorboard使用1
- Tensorboard简单使用
- Tensorboard的使用
- Tensorflow-2-Tensorboard使用
- tensorboard使用问题
- TensorBoard本地使用
- tensorboard使用记录
- tensorboard的使用
- tensorflow 的tensorboard使用
- 15、Tensorboard 的使用
- tensorboard使用入门
- Android EventBus , RxBus
- python判断完全平方数
- 逐浪软件官网全新改版上线 https://www.z01.com/
- IOS Intro
- JAVA WEB之jsp内置对象
- TensorBoard使用
- ORA-24323: value not allowed ORA-01089
- Unable to initialize any output collector(MapReduce执行到reduce过程失败抛出IO)
- 1024. 科学计数法 (20)
- 207. Course Schedule
- Linux系统 ISO下载
- spring cloud微服务框架 第一天
- VS2015 编译问题记录(更新)
- SpringMVC利用Column 注解约束double类型的精度