In [9]:
%matplotlib inline
import matplotlib.pyplot as plt
import tensorflow as tf
print(tf.__version__)


1.2.0

In [10]:
a = tf.constant(1)
print(a)


Tensor("Const_1:0", shape=(), dtype=int32)

In [11]:
with tf.Session() as sess:
    print(a.eval())


1

In [12]:
x = tf.constant(35, name="x")
y = tf.Variable(x + 10, name="y")

텐서플로는 빌딩구조와 실행 구조가 분리 되어있다.

먼저 그래프를 설계하고 나서 그 그래프를 세션에게 실행해 달라고 부탁 한다.


In [13]:
with tf.Session() as sess:
    sess.run(tf.global_variables_initializer())
    print(sess.run(y))


45

In [14]:
x2 = tf.linspace(-1.0, 1.0, 10)

In [15]:
print(x2)


Tensor("LinSpace_1:0", shape=(10,), dtype=float32)

In [19]:
with tf.Session() as sess:
    res = sess.run(x2)
    print(res)


[-1.         -0.77777779 -0.55555558 -0.33333331 -0.1111111   0.11111116
  0.33333337  0.55555558  0.77777779  1.        ]

In [20]:
#get_default_graph() -> 잘 모르겠음
g = tf.get_default_graph()
print([op.name for op in g.get_operations()])


['Const', 'x', 'add/y', 'add', 'y', 'y/Assign', 'y/read', 'init', 'LinSpace/start', 'LinSpace/stop', 'LinSpace/num', 'LinSpace', 'Const_1', 'x_1', 'add_1/y', 'add_1', 'y_1', 'y_1/Assign', 'y_1/read', 'init_1', 'LinSpace_1/start', 'LinSpace_1/stop', 'LinSpace_1/num', 'LinSpace_1']

In [ ]:


In [ ]: