Tensorflow timeline trace


根據 

https://github.com/tensorflow/tensorflow/issues/1824

簡單進行了測試

修改運行的腳本增加如下關鍵代碼

例如mnist_softmax.py

from  __future__  import  absolute_import
 
from  __future__  import  division
 
from  __future__  import  print_function
 
# Import data
 
from  tensorflow.examples.tutorials.mnist  import  input_data
 
from  tensorflow.python.client  import  timeline
 
 
import  tensorflow as tf
 
 
flags  =  tf.app.flags
 
FLAGS  =  flags.FLAGS
 
flags.DEFINE_string( 'data_dir' '/tmp/data/' 'Directory for storing data' )
 
mnist  =  input_data.read_data_sets(FLAGS.data_dir, one_hot = True )
 
# Create the model
 
=  tf.placeholder(tf.float32, [ None 784 ])
 
=  tf.Variable(tf.zeros([ 784 10 ]))
 
=  tf.Variable(tf.zeros([ 10 ]))
 
=  tf.nn.softmax(tf.matmul(x, W)  +  b)
 
# Define loss and optimizer
 
y_  =  tf.placeholder(tf.float32, [ None 10 ])
 
cross_entropy  =  tf.reduce_mean( - tf.reduce_sum(y_  *  tf.log(y), reduction_indices = [ 1 ]))
 
train_step  =  tf.train.GradientDescentOptimizer( 0.5 ).minimize(cross_entropy)
 
# Train
 
intiOp  =  tf.initialize_all_variables()
 
# Init run_metadata
 
run_metadata  =  tf.RunMetadata()
 
# Open file to save trace
 
trace_file  =  open ( '/tmp/timeline.ctf.json' 'w' )
 
sess  =  tf.Session()
 
sess.run(intiOp)
 
for  in  range ( 500 ):
 
   batch_xs, batch_ys  =  mnist.train.next_batch( 100 )
 
   sess.run(train_step, feed_dict = {x: batch_xs, y_: batch_ys},
 
            options = tf.RunOptions(trace_level = tf.RunOptions.FULL_TRACE),
 
            run_metadata = run_metadata)
 
# Test trained model
 
correct_prediction  =  tf.equal(tf.argmax(y,  1 ), tf.argmax(y_,  1 ))
 
accuracy  =  tf.reduce_mean(tf.cast(correct_prediction, tf.float32))
 
print (sess.run(accuracy, feed_dict = {x: mnist.test.images, y_: mnist.test.labels}))
 
#timeline
 
trace  =  timeline.Timeline(step_stats = run_metadata.step_stats)
 
trace_file.write(trace.generate_chrome_trace_format())

打開chrome瀏覽器輸入

chrome://tracing/

 

選擇Load按鈕加載輸出的json文件

W,S按鍵可以縮放,A,D按鍵可以移動,具體幫助點擊右上角“?”按鈕


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM