Gu-Youngfeng / LearningTensorflow

Some codes during the study process.
0 stars 1 forks source link

How to Visualize Your Model in Tensorflow? #5

Open Gu-Youngfeng opened 5 years ago

Gu-Youngfeng commented 5 years ago

How to visualize the model we built in Tensorflow, I need the quickest and simplest way.

Gu-Youngfeng commented 5 years ago

The recommended answer is to use the Tensorboard.

Step-1: create the log file

create the log file of your model.

# import package
from tf.summary import FileWriter

# create the log file
writer = FileWriter("vis_log/", sess.graph)
writer.close()

Step-2: run the command in the terminate

use the following command to open the Tensorboard service on your computer.

> tensorboard --logdir=path/to/your/log-file

Step-3:

open the website localhost:6006 on your browser to see this framework.

Gu-Youngfeng commented 5 years ago

I give a brief example of 2 layers network,

def try_graph_2():
    x = tf.constant([[3.0, 4.0]])
    weight_0 = tf.Variable(tf.random_normal(shape=(2,5), mean=0, stddev=1), name="weight_0")
    weight_1 = tf.Variable(tf.random_uniform(shape=(5,1), minval=0, maxval=1), name="weight_1")
    biase_0 = tf.Variable(tf.random_normal(shape=(1,5), mean=0, stddev=1), "biase_0")
    biase_1 = tf.Variable(tf.random_uniform(shape=(1,1), minval=0, maxval=1), name="biase_1")

    layer_1 = tf.matmul(x, weight_0) + biase_0
    output = tf.matmul(layer_1, weight_1) + biase_1

    # variables initialization
    init = tf.global_variables_initializer()
    # open a session
    with tf.Session() as sess:
        sess.run(init)
        writer = tf.summary.FileWriter("vis_log/", sess.graph)
        writer.close()

the corresponding graph is like this,

graph_1