If you're a liberal arts graduate and you're new to Python, let alone Deep Learning, it's difficult to understand TensorFlow. I also learned TensorBoard ** to speed up my understanding. It can be used for various purposes such as debugging, processing optimization, and redesign, as well as promoting understanding of complex deep learning. There are various visualizations, but ** this article focuses on the Graph output method for beginners ** (I wish I could make it wider and deeper, but my understanding has not caught up to that point. Hmm: sweat :). The Official Guide "TensorBoard: Visualizing Learning" was confusing, so I've simplified it a lot. The site of Visualize processing with TensorBoard was wonderful and I used it as a reference. Environment: Confirmed with both python3.5 tensorflow1.1 and tensorflow1.21
-Installing TensorFlow on Windows was easy even for Python beginners -[Explanation for beginners] TensorFlow basic syntax and concept -[Explanation for beginners] TensorFlow tutorial MNIST (for beginners) -[Visualize TensorFlow Tutorial MNIST (for beginners) with TensorBoard] (http://qiita.com/FukuharaYohei/items/2834cc054a8b8884e150) -[Introduction to TensorBoard: image] TensorFlow Visualize image processing to deepen understanding -[Introduction to TensorBoard: Projector] Make TensorFlow processing look cool -[Explanation for beginners] TensorFlow Tutorial Deep MNIST -TensorFlow API memo -Yuki Kashiwagi's facial features to understand TensorFlow [Part 1]
Calculate the constant 1 + 2 like this and visualize it. To be honest, it's very easy.
import tensorflow as tf
sess = tf.InteractiveSession()
#TensorBoard information output directory
log_dir = '/tmp/tensorflow/mnist/logs/simple01'
#Delete the specified directory if it exists and recreate it
if tf.gfile.Exists(log_dir):
tf.gfile.DeleteRecursively(log_dir)
tf.gfile.MakeDirs(log_dir)
#1 with a constant+ 2
x = tf.constant(1, name='x')
y = tf.constant(2, name='y')
z = x + y
#Output z on the graph with this command
_ = tf.summary.scalar('z', z)
#Draw a graph with SummaryWriter(Commands after this will not be output to the graph)
summary_writer = tf.summary.FileWriter(log_dir , sess.graph)
#Run
print(sess.run(z))
#SummaryWriter closed
summary_writer.close()
Then launch Tensorboard. Since my environment is built with Anaconda, I first start Terminal from Anaconda Navigator.
Then, start Tensorbaord from Terminal by specifying the directory (the directory is stored in the variable log_dir in the Python program).
tensorboard --logdir=/tmp/tensorflow/mnist/logs/simple01
After booting, open http: // localhost: 6006 / in your browser and you will see the TensorBoard screen.
I get angry with "No scalar data was found", but this time there is no problem because scalar is not output and only Graph output is used. By selecting "Graphs" from the menu on the screen, the Graph shown below will be output. I was able to see the formula of 1 + 2 here.
Grouping can be done by adding tf.name_scope to the previous source code.
import tensorflow as tf
sess = tf.InteractiveSession()
#TensorBoard information output directory
log_dir = '/tmp/tensorflow/mnist/logs/simple02'
#Delete the specified directory if it exists and recreate it
if tf.gfile.Exists(log_dir):
tf.gfile.DeleteRecursively(log_dir)
tf.gfile.MakeDirs(log_dir)
# add_Grouping by the name of scope
with tf.name_scope('add_scope'):
#1 with a constant+ 2
x = tf.constant(1, name='x')
y = tf.constant(2, name='y')
z = x + y
#Output z on the graph with this command
_ = tf.summary.scalar('z', z)
#Draw a graph with SummaryWriter(Commands after this will not be output to the graph)
summary_writer = tf.summary.FileWriter(log_dir , sess.graph)
#Run
print(sess.run(z))
#SummaryWriter closed
summary_writer.close()
result Grouping (frame) is created with the name add_scope. When the calculation is complicated, it is too difficult to see if it cannot be grouped.
Add tf.name_scope to the previous source code in a nested manner to create a hierarchy of multiple expressions.
import tensorflow as tf
sess = tf.InteractiveSession()
#TensorBoard information output directory
log_dir = '/tmp/tensorflow/mnist/logs/simple02'
#Delete the specified directory if it exists and recreate it
if tf.gfile.Exists(log_dir):
tf.gfile.DeleteRecursively(log_dir)
tf.gfile.MakeDirs(log_dir)
#add_Grouping by the name of scope
with tf.name_scope('add_scope'):
#1 with a constant+ 2
x = tf.constant(1, name='x')
y = tf.constant(2, name='y')
z = x + y
#Output z on the graph with this command
_ = tf.summary.scalar('z', z)
#Multiply the above result
with tf.name_scope('multiply_scope'):
zz = y * z
#Draw a graph with SummaryWriter(Commands after this will not be output to the graph)
summary_writer = tf.summary.FileWriter(log_dir , sess.graph)
#Run
print(sess.run(z))
#SummaryWriter closed
summary_writer.close()
result It was layered and neat.
reference By the way, if you put them in the same line instead of layering, they will be output in this form.
Recommended Posts