티스토리 뷰

TensorFlow

 - 앞으로의 네트워크엔 Keras와 TensorFlow를 교대로 사용하며 설계하게 될 것이다.

 - Keras는 신경망 네트워크를 빠르고 간편하게 구축하는데에 적합하다.

 - 하지만, 그렇기 때문에 세부적으로 설계하는데엔 제한적이다.

 - 텐서플로우는 신경망 네트워크를 low-level 단에서 작동하는 방식을 이해하는데 유용하다.

 - refresh를 위한 링크

 - Linear Functions

 - Softmax

 - Cross Entropy

 - Batching and Epochs






 - notMNIST 데이터셋으로부터 이미지를 분류하는 네트워크를 설계해보자.

 - 네트워크는 A부터 J까지의 알파벳을 나타내는 이미지들을 적절하게 분류한다.

 - 이미지에 따라 자동으로 알파벳을 감지하고, 분류한다.






Install

 - 먼저 텐서플로우를 사용하기위한 환경을 설치하자.

 - Conda를 설치하면 자동으로 같이 설치되지만, 다음과 같이 확인해본다.

 - Anaconda shell에 위와같이 연달아 입력하여 환경을 셋팅해준다.





Hello, world!

1
2
3
4
5
6
7
8
9
import tensorflow as tf
 
# Create TensorFlow object called tensor
hello_constant = tf.constant('Hello World!')
 
with tf.Session() as sess:
    # Run the tf.constant operation in the session
    output = sess.run(hello_constant)
    print(output)
cs

>>






Tensor

 - 텐서플로우상에서 데이터들은 integer, float, string과 같은 형태로 저장되지 않는다.

 - 값들은 tensor라 불리는 오브젝트로 캡슐화된다.

 - 위의 경우에서 

1
 hello_constant = tf.constant('Hello World!')
cs
1
hello_constant
cs

 - 이 둘은 0차원 스트링 텐서(0-dimensional string tensor)이다.




1
2
3
4
5
6
# A is a 0-dimensional int32 tensor
= tf.constant(1234
# B is a 1-dimensional int32 tensor
= tf.constant([123,456,789]) 
# C is a 2-dimensional int32 tensor
= tf.constant([ [123,456,789], [222,333,444] ])
cs

 - 텐서는 위와같이 다양한 차원으로 선언할 수 있다.

 - tf.constant()는 자주 사용하게 될 오퍼레이션이다.

 - tf.constant()에 의해 리턴되는 값은 constant tensor라 부르고

 - 이 텐서값은 절대 변하지 않는다.




Session

 - TensorFlow의 API는 수학적 프로세스를 시각화 하는 과정에서 만들어졌다.

 - 실행 한 텐서플로우 코드를 그래프로 변환해보면 다음과같다.

 - 위의 TensorFlow Session은 그래프를 실행하기위한 환경이다.

 - 세션은 GPU, CPU, 원격장치 등에 작업을 할당하는 역할을 함

1
2
3
4
with tf.Session() as sess:
    # Run the tf.constant operation in the session
    output = sess.run(hello_constant)
    print(output)
cs

 - 이전에 hello_constant로 텐서를 생성해 두었으므로, 세션에서 이 텐서를 사용하는 단계이다.

 - 위의 코드는 tf.Session()을 사용하여 세션의 인스턴스 sess를 만든다.

 - 그 다음 sess.run()함수는 텐서를 계산하고 결과를 리턴한다.

댓글
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
TAG
more
«   2024/04   »
1 2 3 4 5 6
7 8 9 10 11 12 13
14 15 16 17 18 19 20
21 22 23 24 25 26 27
28 29 30
글 보관함