Tensorflow: Basics -I

Let us start with some basics of addition and multiplication program and represent them in a tensorboard.

import tensorflow as tf

x=tf.constant(1,name='x')
m=tf.constant(2,name='y')
z=tf.constant(3,name='z')
prod=tf.multiply(x,m,name='multiply')
add=tf.add(prod,z,name='add')

with tf.Session() as sess:
writer=tf.summary.FileWriter(logdir='./graph',graph=sess.graph)
print(sess.run(add))

Output is :
5

Now, if we want to check the graph, we have to run following command in Linux(Note: I have used Kali linux), read different types of tensor in

Next Step is to create a scope in tensorflow, this helps in maintaining the code complexity.

#Add Variables
a=tf.constant(2,name='a')
b=tf.constant(2,name='b')
c=tf.constant(3,name='c')
d=tf.constant(4,name='d')

with tf.name_scope("Addition"):
with tf.name_scope("Addition1"):
add1=tf.add(a,b,name='Addition')
with tf.name_scope("Addition2"):
add2=tf.add(c,d,name='Addition')
with tf.name_scope("Multiplication"):
mul=tf.multiply(add1,add2,name="multiply")
#Run the graph
with tf.Session() as sess1:
writer= tf.summary.FileWriter(logdir='./graph1',graph=sess1.graph)
print(sess1.run(mul))
tf.reset_default_graph()

If we want to check in detail:

Comments 7

  • I like the valuable info you provide in your articles. I’ll bookmark your weblog and check again here regularly. I am quite certain I will learn lots of new stuff right here! Good luck for the next!

  • I have not checked in here for a while because I thought it was getting boring, but the last several posts are good quality so I guess I will add you back to my daily bloglist. You deserve it my friend 🙂

  • Hi mates, how is the whole thing, and what you want to say concerning
    this article, in my view its truly awesome designed for me.

  • I could not resist commenting. Very well written!

  • I was very delighted to discover this web-site. I wished to many thanks for your time for this fantastic read!! I most definitely delighting in every little bit of it and I have you bookmarked to check out new things you article.

  • Hi there, I discovered your website by means of Google while searching for a comparable topic, your site got here up, it appears to be like great. I’ve bookmarked it in my google bookmarks.

  • Having read this I thought it was extremely informative. I appreciate you spending some time and energy to put this information together. I once again find myself personally spending way too much time both reading and leaving comments. But so what, it was still worth it!

Leave a Reply

Your email address will not be published. Required fields are marked *