Skip to content

Instantly share code, notes, and snippets.

@leechanwoo
Created August 22, 2017 12:54
Show Gist options
  • Save leechanwoo/fba24aefd642b6ceb2cc526e23e6ea19 to your computer and use it in GitHub Desktop.
Save leechanwoo/fba24aefd642b6ceb2cc526e23e6ea19 to your computer and use it in GitHub Desktop.
tensorflow basic, session
import tensorflow as tf
const = tf.constant("hello world")
print(const)
import tensorflow as tf
const = tf.constant("hello world")
sess = tf.Session()
hello = sess.run(const)
print(hello)
sess.close()
import tensorflow as tf
const = tf.constant("hello world")
with tf.Session() as sess:
hello = sess.run(const)
print(hello)
import tensorflow as tf
const = tf.constant(10)
with tf.Session() as sess:
ten = sess.run(const)
print(ten)
import tensorflow as tf
one = tf.constant(1)
two = tf.constant(2)
three = tf.contant(3)
four = tf.constant(4)
five = tf.constant(5)
add12 = one + two
add123 = add12 + three
add34 = three + four
add2345 = two + add34 + five
total = add123 + add2345
with tf.Session() as sess:
six = sess.run(add123)
fourteen = sess.run(add2345)
twenty = sess.run(total)
print(six)
print(fourteen)
print(twenty)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment