본문 바로가기

잡다한 IT/머신러닝 & 딥러닝

01 Tensorflow basic


■ 기본적인 텐서플로우를 동작시키기 위한 구조 파악



import tensorflow as tf

- 텐서플로우 API 사용을 하려면 tensorflow를 임포트


tf.__version__

- version check


hello = tf.constant("Hello, TensorFlow!")

- 상수 텐서를 생성

- 1차원 텐서를 생성하고, 1차원 텐서 hello 에는 Hello,TensorFlow 라는 스트링이 존재


sess = tf.Session()

- Session 객체는 Operation 객체가 실행되고 Tensor 객체가 계산되는 환경을 캡슐화한다.

- class tf.Session는 TensorFlow 연산들을 실행하기 위한 클래스


sess.run(hello)

- fetches에서 연산과 텐서를 실행합니다.


sess.close()




1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
# Lab1 tensorflow basic
import tensorflow as tf
tf.__version__
 
# Create a constant op
# This op is added as a node to the default graph
hello = tf.constant("Hello, TensorFlow!")
 
# start a TF session
sess=tf.Session()
 
# run the op and get result
print(sess.run(hello))
print(str(sess.run(hello),encoding="utf-8"))
sess.close()
cs






반응형

'잡다한 IT > 머신러닝 & 딥러닝' 카테고리의 다른 글

02-3 Linear Regression : feed from variable  (0) 2018.08.07
02-2 Linear Regression : feed  (0) 2018.08.07
02-1 Linear Regression  (0) 2018.08.07
참고 사이트  (0) 2018.08.07
텐서 플로우 개요  (0) 2018.08.07