1. 程式人生 > >tensorboard視覺化操作過程及測試程式碼

tensorboard視覺化操作過程及測試程式碼

在anaconda的spyder下生成logs檔案後在chrome瀏覽器中開啟tensorboard,可以看到自己搭建的框架。
總結一下過程與遇到的問題:
1,程式碼中python3.6原來函式改變為tf.summary.FileWriter、tf.global_variables_initializer()。不然報錯無法生成logs檔案
2.生成後,在logs檔案那層,按住shift+右鍵,開啟cmd(可以省去cd到該層目錄的過程),輸入命令:tensorboard –logdir logs
這裡寫圖片描述
開啟chrome瀏覽器,不要輸入他的http….(試了很多次不行,坑)
輸入localhost:6006

可以了

這裡寫圖片描述
測試程式碼:

# -*- coding: utf-8 -*-
"""
Created on Mon Dec 25 19:53:43 2017

@author: Administrator
"""

import matplotlib.pyplot as plt
import time
import tensorflow as tf
import numpy as np
def add_layer(inputs,in_size,out_size,activation_function=None):
    with tf.name_scope('layer'):
        with
tf.name_scope('weights'): Weights=tf.Variable(tf.random_normal([in_size,out_size]),name='W') with tf.name_scope('biases'): biases=tf.Variable(tf.zeros([1,out_size])+0.1,name='b') with tf.name_scope('Wx_plus_b'): Wx_plus_b=tf.add(tf.matmul(inputs,Weights),biases) if
activation_function is None: outputs=Wx_plus_b else: outputs=activation_function(Wx_plus_b) return outputs #define placeholder for inputs to network with tf.name_scope('inputsdong'): xs=tf.placeholder(tf.float32,[None,1],name='x_inputdong') ys=tf.placeholder(tf.float32,[None,1],name='y_inputdong') #add hidden layer l1=add_layer(xs,1,10,activation_function=tf.nn.relu) #add output layer prediction=add_layer(l1,10,1,activation_function=None) #the error between prediction and real data loss=tf.reduce_mean(tf.reduce_sum(tf.square(ys-prediction),reduction_indices=[1])) with tf.name_scope('traindong'): train_step=tf.train.GradientDescentOptimizer(0.1).minimize(loss) sess=tf.Session() writer=tf.summary.FileWriter("logs/",sess.graph) #important step sess.run(tf.global_variables_initializer())