Skip to content
Branch: master
Find file History
Type Name Latest commit message Commit time
Failed to load latest commit information.


Welcome to TensorFlow World

The tutorials in this section are just a start for going into the TensorFlow world.

We using Tensorboard for visualizing the outcomes. TensorBoard is the graph visualization tools provided by TensorFlow. Using Google’s words: “The computations you'll use TensorFlow for - like training a massive deep neural network - can be complex and confusing. To make it easier to understand, debug, and optimize TensorFlow programs, we've included a suite of visualization tools called TensorBoard.” A simple Tensorboard implementation is used in this tutorial.


  • The details of summary operations, Tensorboard, and their advantages are beyond the scope of this tutorial and will be presented in more advanced tutorials.

Preparing the environment

At first, we have to import the necessary libraries.

from __future__ import print_function
import tensorflow as tf
import os

Since we are aimed to use Tensorboard, we need a directory to store the information (the operations and their corresponding outputs if desired by the user). This information is exported to event files by TensorFlow. The event files can be transformed to visual data such that the user is able to evaluate the architecture and the operations. The path to store these event files is defined as below:

# The default path for saving event files is the same folder of this python file.
'log_dir', os.path.dirname(os.path.abspath(__file__)) + '/logs',
'Directory where event logs are written to.')

# Store all elements in FLAG structure!

The os.path.dirname(os.path.abspath(__file__)) gets the directory name of the current python file. The points to all defined flags using the FLAGS indicator. From now on the flags can be called using FLAGS.flag_name.

For convenience, it is useful to only work with absolute paths. By using the following script, the user is prompt to use absolute paths for the log_dir directory.

# The user is prompted to input an absolute path.
# os.path.expanduser is leveraged to transform '~' sign to the corresponding path indicator.
#       Example: '~/logs' equals to '/home/username/logs'
if not os.path.isabs(os.path.expanduser(FLAGS.log_dir)):
    raise ValueError('You must assign absolute path for --log_dir')


Some sentence can be defined by TensorFlow:

# Defining some sentence!
welcome = tf.constant('Welcome to TensorFlow world!')

The tf. operator performs the specific operation and the output will be a Tensor. The attribute name="some_name" is defined for better Tensorboard visualization as we see later in this tutorial.

Run the Experiment

The session, which is the environment for running the operations, is executed as below:

# Run the session
with tf.Session() as sess:
    writer = tf.summary.FileWriter(os.path.expanduser(FLAGS.log_dir), sess.graph)
    print("output: ",

# Closing the writer.

The tf.summary.FileWriter is defined to write the summaries into event files.The command of must be used for evaluation of any Tensor otherwise the operation won't be executed. In the end by using the writer.close(), the summary writer will be closed.

You can’t perform that action at this time.