Tuesday, March 17, 2020

[tensorflow certification] 2-1. How to use Tensorflow? (Including Test for ensorflow certification)

how_to_use_tensorflow

Let's make hello world using tensorflow function

In [0]:
import tensorflow as tf
tf.__version__
_helloworld = tf.constant("HelloWorld")
sess = tf.Session()
print(sess.run(_helloworld))
b'helloworld'

Let's make (node1+node2=node3 ) computational Graph using tf.constant

In [16]:
import tensorflow as tf
node1 = tf.constant(3.0)
node2 = tf.constant(4.0)
node3 = tf.add(node1,node2)
sess = tf.Session()
print("node3->",sess.run(node3))
node3-> 7.0

Let's make (node1+node2=node3 ) coputational Graph using tf.placeholder

In [19]:
import tensorflow as tf
node1 = tf.placeholder(tf.float32)
node2 = tf.placeholder(tf.float32)
node3 = tf.add(node1,node2)
sess = tf.Session()
print(sess.run(node3,feed_dict ={node1:1.0,node2:2.0}))
print(sess.run(node3,feed_dict={node1:[1.0,1.0],node2:[1.0,2.0]}))
3.0
[2. 3.]

No comments:

Post a Comment