TensorFlow Tutorial - isl-homepage.github.io€¦ · 4 TensorFlow Dev Summit - 17.02.16...

67
TensorFlow Tutorial 전현호 2019-04-10 1

Transcript of TensorFlow Tutorial - isl-homepage.github.io€¦ · 4 TensorFlow Dev Summit - 17.02.16...

Page 1: TensorFlow Tutorial - isl-homepage.github.io€¦ · 4 TensorFlow Dev Summit - 17.02.16 텐서플우 1.0 공식버전릴리즈 빨라짐: 8GPUs + inception v3 모델을사용할경우7.3배속도향상

TensorFlow Tutorial전현호

2019-04-10 1

Page 2: TensorFlow Tutorial - isl-homepage.github.io€¦ · 4 TensorFlow Dev Summit - 17.02.16 텐서플우 1.0 공식버전릴리즈 빨라짐: 8GPUs + inception v3 모델을사용할경우7.3배속도향상

2

Page 3: TensorFlow Tutorial - isl-homepage.github.io€¦ · 4 TensorFlow Dev Summit - 17.02.16 텐서플우 1.0 공식버전릴리즈 빨라짐: 8GPUs + inception v3 모델을사용할경우7.3배속도향상

3

What is TensorFlow?

텐서플로우( TensorFlow ) : 구글에서개발한기계학습및딥러닝용오픈소스라이브러리

왜텐서플로우를사용해야하는가?

구현이쉬움 ( 연산, 신경망구조 )

여러 CPU 및 GPU에서동작이가능함 데이터및구조를시각적으로확인할수있음 ( TensorBoard )

기타등등 ( 뒤에서설명 )

다차원배열

Page 4: TensorFlow Tutorial - isl-homepage.github.io€¦ · 4 TensorFlow Dev Summit - 17.02.16 텐서플우 1.0 공식버전릴리즈 빨라짐: 8GPUs + inception v3 모델을사용할경우7.3배속도향상

4

TensorFlow Dev Summit - 17.02.16

텐서플로우 1.0 공식버전릴리즈

빨라짐 : 8GPUs + inception v3 모델을사용할경우 7.3배속도향상64GPUs + Inception v3 모델을사용할경우 58배속도향상

유연해짐 : 더고급수준의 API 추가및딥러닝라이브러리중하나인 Keras와완벽한호환성을제공하는새로운 tf.keras 모듈이추가됨

기타등등

Python tf_upgrade.py --infile InputFile --outfile OutputFile

pip install tensorflow로대부분환경에서바로업데이트가능

Page 5: TensorFlow Tutorial - isl-homepage.github.io€¦ · 4 TensorFlow Dev Summit - 17.02.16 텐서플우 1.0 공식버전릴리즈 빨라짐: 8GPUs + inception v3 모델을사용할경우7.3배속도향상

5

Install TensorFlow

1. Anaconda3 4.2.0 버전설치 (Python 3.5)

anaconda

Page 6: TensorFlow Tutorial - isl-homepage.github.io€¦ · 4 TensorFlow Dev Summit - 17.02.16 텐서플우 1.0 공식버전릴리즈 빨라짐: 8GPUs + inception v3 모델을사용할경우7.3배속도향상

6

Install TensorFlow

1. Anaconda3 4.2.0 버전설치 (Python 3.5)

Page 7: TensorFlow Tutorial - isl-homepage.github.io€¦ · 4 TensorFlow Dev Summit - 17.02.16 텐서플우 1.0 공식버전릴리즈 빨라짐: 8GPUs + inception v3 모델을사용할경우7.3배속도향상

7

Install TensorFlow

1. Anaconda3 4.2.0 버전설치 (Python 3.5)

Page 8: TensorFlow Tutorial - isl-homepage.github.io€¦ · 4 TensorFlow Dev Summit - 17.02.16 텐서플우 1.0 공식버전릴리즈 빨라짐: 8GPUs + inception v3 모델을사용할경우7.3배속도향상

8

Install TensorFlow

1. Anaconda3 4.2.0 버전설치 (Python 3.5)

Page 9: TensorFlow Tutorial - isl-homepage.github.io€¦ · 4 TensorFlow Dev Summit - 17.02.16 텐서플우 1.0 공식버전릴리즈 빨라짐: 8GPUs + inception v3 모델을사용할경우7.3배속도향상

9

Install TensorFlow

2. TensorFlow 설치 – CPU 버전

- cmd창에 pip install tensorflow 입력

Page 10: TensorFlow Tutorial - isl-homepage.github.io€¦ · 4 TensorFlow Dev Summit - 17.02.16 텐서플우 1.0 공식버전릴리즈 빨라짐: 8GPUs + inception v3 모델을사용할경우7.3배속도향상

10

Install TensorFlow

3. 설치확인

- Python을실행시킨후 import tensorflow를통해에러가나는지확인

Page 11: TensorFlow Tutorial - isl-homepage.github.io€¦ · 4 TensorFlow Dev Summit - 17.02.16 텐서플우 1.0 공식버전릴리즈 빨라짐: 8GPUs + inception v3 모델을사용할경우7.3배속도향상

11

Install TensorFlow

GPU 버전설치과정

1. CUDA 8.0 버전설치 (https://developer.nvidia.com/cuda-downloads )

Page 12: TensorFlow Tutorial - isl-homepage.github.io€¦ · 4 TensorFlow Dev Summit - 17.02.16 텐서플우 1.0 공식버전릴리즈 빨라짐: 8GPUs + inception v3 모델을사용할경우7.3배속도향상

12

Install TensorFlow

2. cuDNN 5.1 버전설치 ( https://developer.nvidia.com/cudnn )

간단한등록과정을요구함

Page 13: TensorFlow Tutorial - isl-homepage.github.io€¦ · 4 TensorFlow Dev Summit - 17.02.16 텐서플우 1.0 공식버전릴리즈 빨라짐: 8GPUs + inception v3 모델을사용할경우7.3배속도향상

13

Install TensorFlow

3. cuDNN 파일의압축풀기

4. 결과로나오는 bin, include, lib 폴더를 CUDA가설치된경로로접근하여붙여넣기

Page 14: TensorFlow Tutorial - isl-homepage.github.io€¦ · 4 TensorFlow Dev Summit - 17.02.16 텐서플우 1.0 공식버전릴리즈 빨라짐: 8GPUs + inception v3 모델을사용할경우7.3배속도향상

14

Install TensorFlow

5. Tensorflow 설치 - GPU 버전

- cmd창에 pip install tensorflow-gpu 입력

- CPU버전과마찬가지로설치가잘되었는지확인

Page 15: TensorFlow Tutorial - isl-homepage.github.io€¦ · 4 TensorFlow Dev Summit - 17.02.16 텐서플우 1.0 공식버전릴리즈 빨라짐: 8GPUs + inception v3 모델을사용할경우7.3배속도향상

15

Install TensorFlow

6. quit()을통해 python 종료

Page 16: TensorFlow Tutorial - isl-homepage.github.io€¦ · 4 TensorFlow Dev Summit - 17.02.16 텐서플우 1.0 공식버전릴리즈 빨라짐: 8GPUs + inception v3 모델을사용할경우7.3배속도향상

16

Install TensorFlow

MNIST 예제를학습시켜동작확인 ( 3 hidden layer )

Page 17: TensorFlow Tutorial - isl-homepage.github.io€¦ · 4 TensorFlow Dev Summit - 17.02.16 텐서플우 1.0 공식버전릴리즈 빨라짐: 8GPUs + inception v3 모델을사용할경우7.3배속도향상

17

Data type

cmd - jupyter notebook

※주의 : 경로상에관련파일이있지않을경우 404 에러발생

Page 18: TensorFlow Tutorial - isl-homepage.github.io€¦ · 4 TensorFlow Dev Summit - 17.02.16 텐서플우 1.0 공식버전릴리즈 빨라짐: 8GPUs + inception v3 모델을사용할경우7.3배속도향상

18

Data type

jupyter notebook - h

Page 19: TensorFlow Tutorial - isl-homepage.github.io€¦ · 4 TensorFlow Dev Summit - 17.02.16 텐서플우 1.0 공식버전릴리즈 빨라짐: 8GPUs + inception v3 모델을사용할경우7.3배속도향상

19

Data type

※ https://www.tensorflow.org/versions/r0.12/api_docs/python/

Page 20: TensorFlow Tutorial - isl-homepage.github.io€¦ · 4 TensorFlow Dev Summit - 17.02.16 텐서플우 1.0 공식버전릴리즈 빨라짐: 8GPUs + inception v3 모델을사용할경우7.3배속도향상

20

Data type- Code

Page 21: TensorFlow Tutorial - isl-homepage.github.io€¦ · 4 TensorFlow Dev Summit - 17.02.16 텐서플우 1.0 공식버전릴리즈 빨라짐: 8GPUs + inception v3 모델을사용할경우7.3배속도향상

21

Data type

그래프생성

Page 22: TensorFlow Tutorial - isl-homepage.github.io€¦ · 4 TensorFlow Dev Summit - 17.02.16 텐서플우 1.0 공식버전릴리즈 빨라짐: 8GPUs + inception v3 모델을사용할경우7.3배속도향상

22

Data type

그래프생성

Page 23: TensorFlow Tutorial - isl-homepage.github.io€¦ · 4 TensorFlow Dev Summit - 17.02.16 텐서플우 1.0 공식버전릴리즈 빨라짐: 8GPUs + inception v3 모델을사용할경우7.3배속도향상

23

Data type

그래프생성

Page 24: TensorFlow Tutorial - isl-homepage.github.io€¦ · 4 TensorFlow Dev Summit - 17.02.16 텐서플우 1.0 공식버전릴리즈 빨라짐: 8GPUs + inception v3 모델을사용할경우7.3배속도향상

24

Data type

그래프생성

Page 25: TensorFlow Tutorial - isl-homepage.github.io€¦ · 4 TensorFlow Dev Summit - 17.02.16 텐서플우 1.0 공식버전릴리즈 빨라짐: 8GPUs + inception v3 모델을사용할경우7.3배속도향상

25

Data type

그래프생성

Page 26: TensorFlow Tutorial - isl-homepage.github.io€¦ · 4 TensorFlow Dev Summit - 17.02.16 텐서플우 1.0 공식버전릴리즈 빨라짐: 8GPUs + inception v3 모델을사용할경우7.3배속도향상

26

Data type

그래프생성

Page 27: TensorFlow Tutorial - isl-homepage.github.io€¦ · 4 TensorFlow Dev Summit - 17.02.16 텐서플우 1.0 공식버전릴리즈 빨라짐: 8GPUs + inception v3 모델을사용할경우7.3배속도향상

27

Data type

그래프생성

Page 28: TensorFlow Tutorial - isl-homepage.github.io€¦ · 4 TensorFlow Dev Summit - 17.02.16 텐서플우 1.0 공식버전릴리즈 빨라짐: 8GPUs + inception v3 모델을사용할경우7.3배속도향상

28

Data type

그래프생성

Page 29: TensorFlow Tutorial - isl-homepage.github.io€¦ · 4 TensorFlow Dev Summit - 17.02.16 텐서플우 1.0 공식버전릴리즈 빨라짐: 8GPUs + inception v3 모델을사용할경우7.3배속도향상

29

Data type

그래프생성

Page 30: TensorFlow Tutorial - isl-homepage.github.io€¦ · 4 TensorFlow Dev Summit - 17.02.16 텐서플우 1.0 공식버전릴리즈 빨라짐: 8GPUs + inception v3 모델을사용할경우7.3배속도향상

30

Data type

그래프생성

Page 31: TensorFlow Tutorial - isl-homepage.github.io€¦ · 4 TensorFlow Dev Summit - 17.02.16 텐서플우 1.0 공식버전릴리즈 빨라짐: 8GPUs + inception v3 모델을사용할경우7.3배속도향상

31

Data type

그래프생성

Page 32: TensorFlow Tutorial - isl-homepage.github.io€¦ · 4 TensorFlow Dev Summit - 17.02.16 텐서플우 1.0 공식버전릴리즈 빨라짐: 8GPUs + inception v3 모델을사용할경우7.3배속도향상

32

Data type

그래프생성

Page 33: TensorFlow Tutorial - isl-homepage.github.io€¦ · 4 TensorFlow Dev Summit - 17.02.16 텐서플우 1.0 공식버전릴리즈 빨라짐: 8GPUs + inception v3 모델을사용할경우7.3배속도향상

33

Data type

그래프생성

Page 34: TensorFlow Tutorial - isl-homepage.github.io€¦ · 4 TensorFlow Dev Summit - 17.02.16 텐서플우 1.0 공식버전릴리즈 빨라짐: 8GPUs + inception v3 모델을사용할경우7.3배속도향상

34

Data type

그래프생성

Page 35: TensorFlow Tutorial - isl-homepage.github.io€¦ · 4 TensorFlow Dev Summit - 17.02.16 텐서플우 1.0 공식버전릴리즈 빨라짐: 8GPUs + inception v3 모델을사용할경우7.3배속도향상

35

Data type

그래프생성

Page 36: TensorFlow Tutorial - isl-homepage.github.io€¦ · 4 TensorFlow Dev Summit - 17.02.16 텐서플우 1.0 공식버전릴리즈 빨라짐: 8GPUs + inception v3 모델을사용할경우7.3배속도향상

36

Data type

그래프생성

Page 37: TensorFlow Tutorial - isl-homepage.github.io€¦ · 4 TensorFlow Dev Summit - 17.02.16 텐서플우 1.0 공식버전릴리즈 빨라짐: 8GPUs + inception v3 모델을사용할경우7.3배속도향상

37

Data type

그래프생성

Page 38: TensorFlow Tutorial - isl-homepage.github.io€¦ · 4 TensorFlow Dev Summit - 17.02.16 텐서플우 1.0 공식버전릴리즈 빨라짐: 8GPUs + inception v3 모델을사용할경우7.3배속도향상

38

Data type

그래프생성

Page 39: TensorFlow Tutorial - isl-homepage.github.io€¦ · 4 TensorFlow Dev Summit - 17.02.16 텐서플우 1.0 공식버전릴리즈 빨라짐: 8GPUs + inception v3 모델을사용할경우7.3배속도향상

39

Data type

그래프생성

Page 40: TensorFlow Tutorial - isl-homepage.github.io€¦ · 4 TensorFlow Dev Summit - 17.02.16 텐서플우 1.0 공식버전릴리즈 빨라짐: 8GPUs + inception v3 모델을사용할경우7.3배속도향상

40

Data type

그래프생성

Page 41: TensorFlow Tutorial - isl-homepage.github.io€¦ · 4 TensorFlow Dev Summit - 17.02.16 텐서플우 1.0 공식버전릴리즈 빨라짐: 8GPUs + inception v3 모델을사용할경우7.3배속도향상

41

Data type

그래프생성

Page 42: TensorFlow Tutorial - isl-homepage.github.io€¦ · 4 TensorFlow Dev Summit - 17.02.16 텐서플우 1.0 공식버전릴리즈 빨라짐: 8GPUs + inception v3 모델을사용할경우7.3배속도향상

42

Data type

세션

Python이 C기반이기때문에상호간의호환성이좋음

Python에서생성된모델은디바이스에서실제구조가만들어짐. 이과정을 ‘세션에보낸다.’

또는 ‘세션에올린다.’ 고표현함.

하드웨어단계에서구현되었기때문에매우빠른연산이가능해짐 -> TF의장점

Page 43: TensorFlow Tutorial - isl-homepage.github.io€¦ · 4 TensorFlow Dev Summit - 17.02.16 텐서플우 1.0 공식버전릴리즈 빨라짐: 8GPUs + inception v3 모델을사용할경우7.3배속도향상

43

Data type

테스트 - constant

Page 44: TensorFlow Tutorial - isl-homepage.github.io€¦ · 4 TensorFlow Dev Summit - 17.02.16 텐서플우 1.0 공식버전릴리즈 빨라짐: 8GPUs + inception v3 모델을사용할경우7.3배속도향상

44

Data type

테스트 - constant

Page 45: TensorFlow Tutorial - isl-homepage.github.io€¦ · 4 TensorFlow Dev Summit - 17.02.16 텐서플우 1.0 공식버전릴리즈 빨라짐: 8GPUs + inception v3 모델을사용할경우7.3배속도향상

45

Data type

테스트 - Variable

Page 46: TensorFlow Tutorial - isl-homepage.github.io€¦ · 4 TensorFlow Dev Summit - 17.02.16 텐서플우 1.0 공식버전릴리즈 빨라짐: 8GPUs + inception v3 모델을사용할경우7.3배속도향상

46

Data type

테스트 - Variable

Variable은별도의초기화가필요함!

Page 47: TensorFlow Tutorial - isl-homepage.github.io€¦ · 4 TensorFlow Dev Summit - 17.02.16 텐서플우 1.0 공식버전릴리즈 빨라짐: 8GPUs + inception v3 모델을사용할경우7.3배속도향상

47

Data type

테스트 - Variable

Page 48: TensorFlow Tutorial - isl-homepage.github.io€¦ · 4 TensorFlow Dev Summit - 17.02.16 텐서플우 1.0 공식버전릴리즈 빨라짐: 8GPUs + inception v3 모델을사용할경우7.3배속도향상

48

Data type

테스트 - placeholder

Page 49: TensorFlow Tutorial - isl-homepage.github.io€¦ · 4 TensorFlow Dev Summit - 17.02.16 텐서플우 1.0 공식버전릴리즈 빨라짐: 8GPUs + inception v3 모델을사용할경우7.3배속도향상

49

Linear regression + Plot

Page 50: TensorFlow Tutorial - isl-homepage.github.io€¦ · 4 TensorFlow Dev Summit - 17.02.16 텐서플우 1.0 공식버전릴리즈 빨라짐: 8GPUs + inception v3 모델을사용할경우7.3배속도향상

50

Linear regression + Plot

Page 51: TensorFlow Tutorial - isl-homepage.github.io€¦ · 4 TensorFlow Dev Summit - 17.02.16 텐서플우 1.0 공식버전릴리즈 빨라짐: 8GPUs + inception v3 모델을사용할경우7.3배속도향상

51

Linear regression + Plot

Page 52: TensorFlow Tutorial - isl-homepage.github.io€¦ · 4 TensorFlow Dev Summit - 17.02.16 텐서플우 1.0 공식버전릴리즈 빨라짐: 8GPUs + inception v3 모델을사용할경우7.3배속도향상

52

MNIST

MNIST

When one learns how to program, there's a tradition that the first thing you do is print "Hello World."

Just like programming has Hello World, machine learning has MNIST.

Page 53: TensorFlow Tutorial - isl-homepage.github.io€¦ · 4 TensorFlow Dev Summit - 17.02.16 텐서플우 1.0 공식버전릴리즈 빨라짐: 8GPUs + inception v3 모델을사용할경우7.3배속도향상

53

MNIST

MNIST

When one learns how to program, there's a tradition that the first thing you do is print "Hello World."

Just like programming has Hello World, machine learning has MNIST.

Page 54: TensorFlow Tutorial - isl-homepage.github.io€¦ · 4 TensorFlow Dev Summit - 17.02.16 텐서플우 1.0 공식버전릴리즈 빨라짐: 8GPUs + inception v3 모델을사용할경우7.3배속도향상

54

MLP

Input layer - 3 hidden layer – output layer

Page 55: TensorFlow Tutorial - isl-homepage.github.io€¦ · 4 TensorFlow Dev Summit - 17.02.16 텐서플우 1.0 공식버전릴리즈 빨라짐: 8GPUs + inception v3 모델을사용할경우7.3배속도향상

55

MLP

Input layer - 3 hidden layer – output layer

Page 56: TensorFlow Tutorial - isl-homepage.github.io€¦ · 4 TensorFlow Dev Summit - 17.02.16 텐서플우 1.0 공식버전릴리즈 빨라짐: 8GPUs + inception v3 모델을사용할경우7.3배속도향상

56

MLP

Input layer - 3 hidden layer – output layer

Page 57: TensorFlow Tutorial - isl-homepage.github.io€¦ · 4 TensorFlow Dev Summit - 17.02.16 텐서플우 1.0 공식버전릴리즈 빨라짐: 8GPUs + inception v3 모델을사용할경우7.3배속도향상

57

MLP

Failure

Page 58: TensorFlow Tutorial - isl-homepage.github.io€¦ · 4 TensorFlow Dev Summit - 17.02.16 텐서플우 1.0 공식버전릴리즈 빨라짐: 8GPUs + inception v3 모델을사용할경우7.3배속도향상

58

MLP

Failure

Page 59: TensorFlow Tutorial - isl-homepage.github.io€¦ · 4 TensorFlow Dev Summit - 17.02.16 텐서플우 1.0 공식버전릴리즈 빨라짐: 8GPUs + inception v3 모델을사용할경우7.3배속도향상

59

CNN ( ConvNet )

버그

CPU버전삭제로해결

Page 60: TensorFlow Tutorial - isl-homepage.github.io€¦ · 4 TensorFlow Dev Summit - 17.02.16 텐서플우 1.0 공식버전릴리즈 빨라짐: 8GPUs + inception v3 모델을사용할경우7.3배속도향상

60

CNN ( ConvNet )

Page 61: TensorFlow Tutorial - isl-homepage.github.io€¦ · 4 TensorFlow Dev Summit - 17.02.16 텐서플우 1.0 공식버전릴리즈 빨라짐: 8GPUs + inception v3 모델을사용할경우7.3배속도향상

61

Q&A

Page 62: TensorFlow Tutorial - isl-homepage.github.io€¦ · 4 TensorFlow Dev Summit - 17.02.16 텐서플우 1.0 공식버전릴리즈 빨라짐: 8GPUs + inception v3 모델을사용할경우7.3배속도향상

62

example

Page 63: TensorFlow Tutorial - isl-homepage.github.io€¦ · 4 TensorFlow Dev Summit - 17.02.16 텐서플우 1.0 공식버전릴리즈 빨라짐: 8GPUs + inception v3 모델을사용할경우7.3배속도향상

63

Before any opt

Page 64: TensorFlow Tutorial - isl-homepage.github.io€¦ · 4 TensorFlow Dev Summit - 17.02.16 텐서플우 1.0 공식버전릴리즈 빨라짐: 8GPUs + inception v3 모델을사용할경우7.3배속도향상

64

After 1 opt iter

Page 65: TensorFlow Tutorial - isl-homepage.github.io€¦ · 4 TensorFlow Dev Summit - 17.02.16 텐서플우 1.0 공식버전릴리즈 빨라짐: 8GPUs + inception v3 모델을사용할경우7.3배속도향상

65

After 10 opt iter

Page 66: TensorFlow Tutorial - isl-homepage.github.io€¦ · 4 TensorFlow Dev Summit - 17.02.16 텐서플우 1.0 공식버전릴리즈 빨라짐: 8GPUs + inception v3 모델을사용할경우7.3배속도향상

66

After 1000 opt iter

Page 67: TensorFlow Tutorial - isl-homepage.github.io€¦ · 4 TensorFlow Dev Summit - 17.02.16 텐서플우 1.0 공식버전릴리즈 빨라짐: 8GPUs + inception v3 모델을사용할경우7.3배속도향상

67

After 1000 opt iter