Tensorboard 1.13.1的使用,及遇到的几个问题
TensorBoard介紹
TensorBoard是TensorFlow的可視化工具,它可以通過TensorFlow程序運行過程中輸出的日志文件可視化TensorFlow程序的運行狀態。TensorFlow和TensorBoard程序跑在不同的進程中,TensorBoard會自動讀取最新的TensorFlow日志文件,并呈現當前程序運行的最新狀態。
代碼運行
(1)在Windows或者Linux下TensorFlow框架下,本人所用為win10下的Spyder。
(2)首先創建一個可視化.py文件,它會默認保存到程序的工作空間中,其中
writer = tf.summary.FileWriter("logs/",sess.graph)#加載到文件里,再從文件里加載出來觀看測試代碼如下:
import tensorflow as tfdef add_layer(input,in_size,out_size,activation_function=None):#add one more layer and return the output of this layerwith 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(input,Weights),biases)if activation_function is None:outputs = Wx_plus_belse:outputs = activation_function(Wx_plus_b,)return outputs#define placeholder for inputs to network with tf.name_scope('input'):xs = tf.placeholder(tf.float32,[None,1],name='x_input')ys = tf.placeholder(tf.float32,[None,1],name='y_input')#add hidder 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 with tf.name_scope('loss'):loss = tf.reduce_mean(tf.reduce_sum(tf.square(ys-prediction),reduction_indices=[1])) with tf.name_scope('train'):train_step = tf.train.GradientDescentOptimizer(0.1).minimize(loss)sess = tf.Session() writer = tf.summary.FileWriter("logs/",sess.graph)#加載到文件里,再從文件里加載出來觀看 #important step sess.run(tf.initialize_all_variables())(3)運行完畢后會生成在log下生成文件,打開終端,切換到文件目錄下:
activate tensorflow cd 你的路徑 tensorboard --logdir=logs此處出現了一個小的插曲。運行后出現
OSError:[Errno 22] Invalid argument此處查閱資料后,博主https://blog.csdn.net/u013244846/article/details/88380860,給出了解決方案。但是本人所用工具為Spyder,不過解決方法大致相同。
在tensorflow環境下查找...\Lib\site-packages\tensorboard路徑下的manager.py 打開修改_type_timestamp的定義下的serialize,
serialize=lambda dt: int(dt.strftime("%S"))
最終運行后會出現如下結果:
(tensorflow) I:\TensorflowWS>tensorboard --logdir=logs TensorBoard 1.13.1 at http://DESKTOP-RR115KR:6006 (Press CTRL+C to quit)(4)打開瀏覽器,將網址復制到地址欄。
然而此處遇到了問題
在幾經周折以后,在博主https://blog.csdn.net/dr_theodore/article/details/80748068出找到了解決方法。即在末尾加一句--host=127.0.0.1
(tensorflow) I:\TensorflowWS>tensorboard --logdir=logs --host=127.0.0.1 TensorBoard 1.13.1 at http://127.0.0.1:6006 (Press CTRL+C to quit)完成后,如圖:
另附一條Tensorboard學習總結Tensorboard各顯示塊的作用
總結
以上是生活随笔為你收集整理的Tensorboard 1.13.1的使用,及遇到的几个问题的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 基于javaweb的电子相册管理系统
- 下一篇: Acunetix WVS11安装和扫描