1. 程式人生 > >tensorflow tensorboard的入門

tensorflow tensorboard的入門

  • W = tf.Variable(tf.truncated_normal([hidden_size, class_num], stddev=0.1), dtype=tf.float32,name='W')
    tf.summary.histogram('W',W)#把w記錄在histogram上檢視
    with tf.name_scope('loss'):
        cross_entropy = -tf.reduce_mean(y * tf.log(y_pre))
        tf.summary.scalar('loss',cross_entropy)#把loss記錄在scalar上檢視
    merged=tf.summary.merge_all()#合併所有需要在tensorborad上看的,需要sess.run
    writer=tf.summary.FileWriter("logs/",sess.graph)#儲存,路徑tensorboard檢視整個框架
    for i in range(2000):
        _batch_size=32
        batch=mnist.train.next_batch(_batch_size)
        
        if (i+1)%200 ==0:
            result=sess.run(merged,feed_dict={_X:batch[0],y:batch[1],keep_prob:0.8,batch_size:_batch_size})#把merge搞起來
            writer.add_summary(result,i)#i是步數
            train_accuracy=sess.run(accuracy,feed_dict={_X:batch[0],y:batch[1],keep_prob:0.8,batch_size:_batch_size})
            print ("Iter%d, step %d, training accuracy %g" % ( mnist.train.epochs_completed, (i+1), train_accuracy))
        sess.run(train_op, feed_dict={_X: batch[0], y: batch[1], keep_prob: 0.5, batch_size: _batch_size})
    
    
    命令列執行
    
    
    tensorboard --logdir='tensorborad/'
    
    
    
    點網址。點不開手動複製,不顯示可以把名字改成127.0.0.1