smart computing labsclab.konkuk.ac.kr/attachments/lecture/4/chapter11.pdf · 2019-12-05 · sclab...
TRANSCRIPT
SCLABSmart Computing LAB
웹기술및응용Chapter�11.
SCLABSmart Computing LAB
PytorchPytorch Framework
• Python�기반의과학연산패키지
• Numpy를 대체하고 GPU의연산력을사용
• 최대한의유연성과속도를제공하는딥러닝개발및연구플랫폼
pip3�install torch
pip3�install�torchvision
Ref: https://pytorch.org/
SCLABSmart Computing LAB
PytorchTensor
• Tensor는 Numpy의 ndarray와 유사함
• GPU를사용한연산가속을지원
SCLABSmart Computing LAB
PytorchTensor�Operations
SCLABSmart Computing LAB
PytorchShape�Changing
SCLABSmart Computing LAB
Training�Neural�NetworkRegression
1+4�=�9
2+5�=�12
3+6�=�15
4+7�=�18
8+11�=�?
SCLABSmart Computing LAB
Training�Neural�NetworkRegression
자료구조를 공부한 시간(x)
기말고사 점수(Y)
8 96
7 83
5 61
3 35
2 24
SCLABSmart Computing LAB
Training�Neural�NetworkLinear�Hypothesis
H(x)�=�Wx +�b의 형태로표현
0
9
18
27
36
45
54
63
72
81
90
99
0 1 2 3 4 5 6 7 8 9
기말고사점수
(Y)
공부한 시간(x)
공부 시간에 따른 기말고사 점수H(x)�=�12x�+�0
SCLABSmart Computing LAB
Training�Neural�NetworkLinear�Hypothesis
0
9
18
27
36
45
54
63
72
81
90
99
0 1 2 3 4 5 6 7 8 9
기말고사점수
(Y)
공부한 시간(x)
공부 시간에 따른 기말고사 점수
Which hypothesis�is�better?
SCLABSmart Computing LAB
Training�Neural�NetworkCost�function(Loss�function)
H(x)�=�Wx +�b
• 𝐻 𝑥 − 𝑌의값들의 평균을구한다
(𝐻 𝑥 − 𝑌)'
SCLABSmart Computing LAB
Training�Neural�NetworkCost�function(Loss�function)
H(x)�=�Wx +�b
96
83
61
35
24
cost = ( ' )'* +, ( - )-. +, ( . )/0 +, ( 1 )2- +, ( 2 )3/ +
.
SCLABSmart Computing LAB
Training�Neural�NetworkCost�function(Loss�function)
𝑐𝑜𝑠𝑡 =𝐻 2 − 24 ' + 𝐻 3 − 35 ' + 𝐻 5 − 61 ' + 𝐻 7 − 83 ' + 𝐻 8 − 96 '
5
𝑐𝑜𝑠𝑡 =𝐻 𝑥 0 − 𝑌 0 '
+ 𝐻 𝑥 ' − 𝑌 ' '+ …+ 𝐻 𝑥 D − 𝑌 D '
𝑚
H(x)�=�Wx +�b
궁극적인목표는가장작은 cost값을갖도록하는W와 b를구하는것
𝑐𝑜𝑠𝑡 =1𝑚 F
GH0
D
𝐻(𝑥) − 𝑦(G)'
𝑐𝑜𝑠𝑡(𝑊, 𝑏) =1𝑚FGH0
D
𝐻(𝑥) − 𝑦(G) '
SCLABSmart Computing LAB
Training�Neural�NetworkHow to minimize cost�value
x Y
8 96
7 83
5 61
3 35
2 24
에서 𝐻 𝑥 = 𝑊𝑥 로간략히표현하면
W=12라면,
cost�=�'*)'* +, -/)-. +, /M)/0 +, 2*)2- +, 3/)3/ +
.
=�M,0,0,0,M
.= 0.6
𝑐𝑜𝑠𝑡(𝑊) =1𝑚 F
GH0
D
𝑊𝑥(G) − 𝑦(G)'로표현이가능
𝑐𝑜𝑠𝑡(𝑊) =1𝑚FGH0
D
𝐻(𝑥) − 𝑦(G) '
SCLABSmart Computing LAB
Training�Neural�NetworkHow to minimize cost�value
x Y
8 96
7 83
5 61
3 35
2 24
W=11이라면,
cost�=�'')'* +, --)-. +, ..)/0 +, 11)2- +, 22)3/ +
.
=�*,*,-/,-/,/*
.= 28.8
W=13이라면,
cost�=�'/)'* +, -3)-. +, /.)/0 +, 30)2- +, 0M*)3/ +
.
=�*,0/,0/,/*,/*
.= 32.8
SCLABSmart Computing LAB
Training�Neural�NetworkHow to minimize cost�value
0
500
1000
1500
2000
2500
3000
3500
4000
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
cost
(W)
W
W값에 따른 cost값
𝑐𝑜𝑠𝑡(𝑊) =1𝑚FGH0
D
𝑊𝑥(G) − 𝑦(G) '
SCLABSmart Computing LAB
Training�Neural�NetworkGradient�Descent�Algorithm
• 함수의기울기를구하여기울기가낮은쪽으로계속이동시켜극값에이를때까지반복
• 주어진 cost�function에서 cost를 최소화하는W,b를구할수있음
• 한개의w가아닌다양한조건의 Linear�regression에서도사용되어질수있음
예)�cost(W1,�W2,�W3…)
• 시작점에서 cost가 줄어드는방향으로W값을조금씩바꿈
0
500
1000
1500
2000
2500
3000
3500
4000
1 3 5 7 9 11 13 15 17 19 21 23
W=21,�cost=?
W=17,�cost=?
W=14,�cost=?
…
SCLABSmart Computing LAB
MNIST�Example손글씨인식하기
SCLABSmart Computing LAB
MNIST�Example손글씨인식하기
SCLABSmart Computing LAB
MNIST�Example손글씨인식하기
SCLABSmart Computing LAB
MNIST�Example손글씨인식하기
SCLABSmart Computing LAB
MNIST�Example손글씨인식하기
SCLABSmart Computing LAB
MNIST�Example손글씨인식하기
SCLABSmart Computing LAB
MNIST�Example손글씨인식하기
SCLABSmart Computing LAB
Flask�File�Upload
SCLABSmart Computing LAB
Practice연습문제
실습. Python�Flask를 이용하여다음조건을만족하는코드를작성하시오
조건 1) POST MAN을이용해손글씨이미지파일을 Post Method로업로드하시오
조건 2) Flask를 이용해 Post Method로받은이미지파일을저장하시오
조건 3) 이미지파일을MNIST를이용해어떤숫자인지구분하시오
SCLABSmart Computing LAB
Homework과제
• 공통사항
- 과제 제출 주소
http://sclab.konkuk.ac.kr/lecture/homework/4
- 과제 제출 방법
• 홈페이지에 로그인(가입) 후 Lecture à 웹 기술 및 응용 à 과제제출 페이지에서
과제 압축 후 업로드하여 제출
(반드시 압축하여 제출 해야하며, 제출 기한 엄수)
• 압축파일명은 학번_이름.zip 의 형태로 작성
• 과제
- 실습시간에 작성한 Python 코드를 압축하여 제출하기
- 제출기한 : 2019.12.05(목) 자정까지
SCLABSmart Computing LAB
THANK�YOU- END�-