Upload
others
View
0
Download
0
Embed Size (px)
Citation preview
제6장:����������� ������������������ 신경망����������� ������������������ 시스템과����������� ������������������ 딥러닝����������� ������������������ (인공지능����������� ������������������ 강의����������� ������������������ 슬라이드)����������� ������������������
(교재)����������� ������������������ 장병탁,����������� ������������������ 인공지능����������� ������������������ 개론,����������� ������������������ 2017����������� ������������������
장����������� ������������������ ����������� ������������������ 병����������� ������������������ ����������� ������������������ 탁����������� ������������������
서울대학교����������� ������������������ 컴퓨터공학부����������� ������������������ http://bi.snu.ac.kr/~btzhang/����������� ������������������
목차
6.1 신경망 모델 …….………………….…… 3
6.2 다층신경망 학습 ………………………. 22
6.3 컨볼류션 신경망 …..……….…………. 32
6.4 딥러닝 모델 …….......…...……….……. 53
6.5 딥러닝 활용 사례 ….…...……….……. 69
6.1 신경망 모델
3
감독학습 (분류) • 데이터 x가 주어졌을 때 해당되는 레이블 y를 찾는 문제
– ex1) x: 사람의 얼굴 이미지, y: 사람의 이름 – ex2) x: 혈당 수치, 혈압 수치, 심박수, y: 당뇨병 여부 – ex3) x: 사람의 목소리, y: 목소리에 해당하는 문장
• x: n차원 벡터, y: 정수 (Discrete)
• 대표적인 감독학습 (분류) 알고리듬 – Support Vector Machine – Decision Tree – K-Nearest Neighbor – Multi-Layer Perceptron (Artificial Neural Network; 인공신경망)
신경망
5
h+p://cs231n.stanford.edu/slides/winter1516_lecture4.pdf
Perceptron (1/2)
Perceptron (2/2)
x1 x2
1 w1 w2
b
x1
x2 w1*x1 + w2*x2 +b = 0
> 0: < 0:
Parameter Learning in Perceptron start: The weight vector w is generated randomly test: A vector x ∈ P ∪ N is selected randomly, If x∈P and w·∙x>0 goto test, If x∈P and w·∙x≤0 goto add, If x ∈ N and w ·∙ x < 0 go to test, If x ∈ N and w ·∙ x ≥ 0 go to subtract. add: Set w = w+x, goto test subtract: Set w = w-‐x, goto test
Perceptron Learning
© 2017, SNU BioIntelligence Lab, h+p://bi.snu.ac.kr/
1
0
0
-.06
-.1
.05
x1 x2 y 0 0 0 0 1 0 1 0 0 1 1 1
-.06 0
RIGHT
x1
x2
x0
Perceptron Learning
© 2017, SNU BioIntelligence Lab, h+p://bi.snu.ac.kr/
1
0
1
-.06
-.1
.05
x1 x2 y 0 0 0 0 1 0 1 0 0 1 1 1
-.01 0
RIGHT
Perceptron Learning
© 2017, SNU BioIntelligence Lab, h+p://bi.snu.ac.kr/
1
1
0
-.06
-.1
.05
x1 x2 y 0 0 0 0 1 0 1 0 0 1 1 1
-.16 0
RIGHT
Perceptron Learning
© 2017, SNU BioIntelligence Lab, h+p://bi.snu.ac.kr/
1
1
1
-.06
-.1
.05
x1 x2 y 0 0 0 0 1 0 1 0 0 1 1 1
-.11 0
WRONG
Perceptron Learning
© 2017, SNU BioIntelligence Lab, h+p://bi.snu.ac.kr/
1
1
1
-.06
-.1
.05
x1 x2 y 0 0 0 0 1 0 1 0 0 1 1 1
Fails to fire, so add proportion, , to weights.
Perceptron Learning
© 2017, SNU BioIntelligence Lab, h+p://bi.snu.ac.kr/
1
1
1
-.06+.01x1
-.1+.01x1
.05+.01x1
x1 x2 y 0 0 0 0 1 0 1 0 0 1 1 1
= .01
Perceptron Learning
© 2017, SNU BioIntelligence Lab, h+p://bi.snu.ac.kr/
1
-.05
-.09
.06
x1 x2 y 0 0 0 0 1 0 1 0 0 1 1 1
Perceptron Learning
© 2017, SNU BioIntelligence Lab, h+p://bi.snu.ac.kr/
1
0
1
-.05
-.09
.06
x1 x2 y 0 0 0 0 1 0 1 0 0 1 1 1
.01 1
Decrease!
Perceptron Learning
© 2017, SNU BioIntelligence Lab, h+p://bi.snu.ac.kr/
1
0
1
-.05-.01x1
-.09
.06-.01x1
x1 x2 y 0 0 0 0 1 0 1 0 0 1 1 1
= .01
Perceptron Learning
© 2017, SNU BioIntelligence Lab, h+p://bi.snu.ac.kr/
1
1
1
-.06
-.09
.07
x1 x2 y 0 0 0 0 1 0 1 0 0 1 1 1
= .01
-‐.08
Perceptron Learning
© 2017, SNU BioIntelligence Lab, h+p://bi.snu.ac.kr/
1
1
1
-.06+.01x1
-.09+.01x1
.06+.01x1
x1 x2 y 0 0 0 0 1 0 1 0 0 1 1 1
= .01
Sigmoid Unit
Learning Algorithm for Sigmoid Unit
• Loss Func_on
• Gradient Descent Update
!!f (s)=1/(1+e− s ),!!! ∂ f
∂s= f (s)(1− f (s))
!!!∂E∂W
= ∂E∂ f
∂ f∂s
∂s∂W
= −( y − f )∂ f∂sX = −( y − f ) f (1− f )X
!!!
W←W−η ∂E∂W
W←W+η( y − f ) f (1− f )X
Target Unit Output
!!E = 12( y − f )
2
6.2 다층신경망 학습
22
Need for Multiple Units and Multiple Layers
• Multiple boundaries are needed (e.g. XOR problem)
à Multiple Units
• More complex regions are needed (e.g. Polygons)
à Multiple Layers
h+p://cs.stanford.edu/people/karpathy/convnetjs/demo/classify2d.html
Structure of Multilayer Perceptron
24 h+p://cs231n.stanford.edu/slides/winter1516_lecture4.pdf
Multilayer Perceptron (MLP; Artificial Neural Network)
Input Output
Learning Parameters of MLP • Loss Function
– We have the same Loss Function – But the # of parameters are now much
more (Weight for each layer and each unit)
– To use Gradient Descent, we need to calculate the gradient for all the parameters
• Recursive Computation of Gradients – Computation of loss-gradient of
the top-layer weights is the same as before
– Using the chain rule, we can compute the loss-gradient of lower-layer weights recursively (Backpropagation)
Target Unit Output
!!E = 12( y − f )
2
Backpropagation Learning Algorithm (1/3)
• Delta for top-‐layer units
(1) Weight update rule for top layer !!δ (k ) = ∂E
∂si( j ) =
∂E∂ f
∂ f∂si
( j ) = −( y − f )∂ f∂si
( j ) = −( y − f ) f (1− f )
!!E = 12( y − f )
2
!!!∂E∂W
= ∂E∂s
∂s∂W
=δ (k )X
!!!
W←W−η ∂E∂W
=W−ηδ (k )X
W←W+η( y − f ) f (1− f )X
!!δ (k ) = ∂E
∂si( j )
Backpropagation Learning Algorithm (2/3) • Weighted sum of lower-‐layer weights
)()1()( ji
jjis WX ⋅= −
!!!∂E
∂Wi( j ) =
∂E∂si
( j )∂si
( j )
∂Wi( j ) =
∂E∂si
( j ) X( j−1) =δ i
( j )X( j−1)
Local gradient
!!!
Wi( j ) ←Wi
( j ) +ηi( j )δ i
( j )X( j−1)
Wi( j ) ←Wi
( j ) +ηi( j ) fi
( j )(1− fi( j )) δ i( j+1)wil
( j+1)
l=1
mj+1
∑
(2) Weight update rule for lower layers
Delta for lower layer units
• Applying chain rule, recursive rela_on between delta’s
!!δ i( j ) = fi
( j )(1− fi( j )) δ i( j+1)wil
( j+1)
l=1
mj+1
∑
Algorithm: Back PropagaDon 1. Randomly IniDalize weight parameters 2. Calculate the acDvaDons of all units (with input data) 3. Calculate top-‐layer delta 4. Back-‐propagate delta from top to the boMom 5. Calculate actual gradient of all units using delta’s 6. Update weights using gradient eescent rule 7. Repeat 2~6 unDl convergence
Backpropagation Learning Algorithm (3/3)
An Example of the MLP
• Example
© 2016, SNU CSE Biointelligence Lab., h+p://bi.snu.ac.kr
n 64-‐2-‐3 network for classifying 3 characters
n 64-‐dim inputs n 2 hidden units n 3 output units
n Learned i-‐to-‐h weights n Describe feature groupings useful for classifica_on
Limitations and Breakthroughs • Limitations
– Backpropagation barely changes lower-layer parameters (vanishing gradient)
– Therefore, deep networks cannot be fully (effectively) trained with back propagation
• Breakthroughs – Deep belief networks (unsupervised pre-training) – Convolutional neural networks (reducing redundant parameters) – Rectified linear unit (constant gradient propagation)
Input x
Output y'
Target y Error Error Error
Back-‐propaga_on
6.3 컨볼루션 신경망
32
33
n 훈련해야할 파라미터의 개수가 매우 커짐
신경망을 사용한 이미지 처리
n 이미지의 위치, 크기, 각도 변화 등에 취약함
n 이미지의 위치가 변하는 경우 (1/2)
일반 신경망으로 이미지를 분류할 때 문제점
34
왼쪽으로 이동
n 이미지의 위치가 변하는 경우 (2/2)
일반 신경망으로 이미지를 분류할 때 문제점
35
왼쪽으로 2픽셀 이동할 경우154개의 입력이 변화함 �77개 : 검은색 -> 흰색 77개 : 흰색 -> 검은색
n 이미지의 크기, 각도, 또는 모양이 변하는 경우
일반 신경망으로 이미지를 분류할 때 문제점
36
n 입력 데이터의 형태가 거의 무시됨 n 가공되지 않은 raw data로만 문제를 다룸
Feature 1
Feature 2
일반 신경망으로 이미지를 분류할 때 문제점
적절한 결정 영역을 찾아야함
n 검은색과 흰색 패턴(흑백)의 개수:
n 256개 회색 스케일인 경우 패턴의 개수:
32*32 10242 2=
32*32 1024256 256=
32 * 32 input image
가능한 입력 조합의 개수
n 우리 뇌 속 시각 피질의 신경 세포들은 물체의 방향과 장소가 바뀌어도 별 문제없이 인식할 수 있음
n 이러한 신경생물학적 관찰이 컨볼루션 신경망 구조 설계에 동기를 부여
n 컨볼루션 신경망은 물체의 위치와 방향에 관계없이 물체의 고유한 특징을 학습할 수 있음
n 다층 신경망의 한 종류임
n 역전파 알고리즘을 사용하여 학습
n 이미지의 픽셀값으로부터 직접 시각 패턴을 학습할 수 있음
컨볼루션 신경망이란?
39
n 일반 분류기
n 컨볼루션 신경망
컨볼루션 신경망: 딥러닝
40
분류 특징 추출을 위한
전처리단계 입력 f1 … fn
출력
f1
f 2
출력 특징 추출 입력 이미지의 이동 및 왜곡에 불변
분류
컨볼루션 신경망의 구조
41
특징 추출 층 또는 컨볼루션 층
풀링 층 (이동 및 왜곡에 불변)
컨볼루션 층
풀링 층
특징 맵 (커널)
입력 이미지
추출된 특징 벡터
n 입력 이미지 속 다양한 위치에서 동일한 특징들을 탐색
컨볼루션 층
42
특징
서로 다른 특징 맵 (커널)
컨볼루션 과정
43
w13 w12 w11
w23 w22 w21
w33 w32 w31
1 0 -1
1 0 -1
1 0 -1
컨볼루션 임계치
w13 w12 w11
w23 w22 w21
w33 w32 w31
입력
특징 맵 (커널) 특징 맵 (커널)
가중치
입력
n 필터를 이미지 위로 슬라이딩해줌 n 내적(dot product) 계산
필터의 모양
1 0 1 0 1 0 1 0 1
http://ufldl.stanford.edu/wiki/index.php/UFLDL_Tutorial
Stride: 1
컨볼루션: 피처맵 (커널) 계산
컨볼루션: 입력 이미지에서 피처맵까지
45
컨볼루션: 입력 이미지에서 피처맵까지
46
컨볼루션: 입력 이미지에서 피처맵까지
47
컨볼루션: 입력 이미지에서 피처맵까지
48
컨볼루션 과정 정리
49
n 한 개의 특징 맵이 컨볼루션 과정을 통해 특징을 탐색할 때 특징 맵의 가중치 값은 변경되지 않음 (가중치 공유)
n 이와 같은 방식으로 특징 맵은 입력 이미지의 다양한 위치에서 동일한 특징을 탐색할 수 있음
n 모델이 갖는 파라미터의 개수를 줄여줌 n 특징 맵이 나타내고자 하는 템플릿과 이미지의 국소 부분이 일치한다면, 특징 맵의
뉴런이 발화
입력����������� ������������������ 이미지����������� ������������������ 컨볼루션����������� ������������������ 층����������� ������������������
풀링 과정 (1/2)
50
n 물체의 위치와 각도 변화에 잘 대처할 수 있게 해줌 n 각 특징 맵의 해상도를 줄여줌 -> 모델의 파라미터의 개수를
줄임 n 최대 / 평균 풀링을 주로 사용
특징 맵
풀링 층
n 풀링을 사용하지 않는다면 n 예>
n 96x96 픽셀 크기의 이미지 n 8x8 크기의 필터를 400개 설정 n 필터 하나당 생성하는 피처맵 크기:
(96−8+1)∗(96−8+1)=7,921 n 이미지 하나당 피처맵 크기: 3,168,400 n 오버피팅이 일어나기 쉬움
n 풀링의 예 n 최대 풀링 n 평균 풀링
풀링 과정 (2/2)
http://ufldl.stanford.edu/tutorial/supervised/Pooling/
풀링의 예시
http://ufldl.stanford.edu/tutorial/supervised/Pooling/
6.4 딥러닝 모델
53
왜 딥러닝?
• Mul_ple boundaries are needed (e.g. XOR problem) à Mul_ple Units
• More complex regions are needed (e.g. Polygons) à Mul_ple Layers
딥러닝 개념 (Revisited)
u Shallow Learning
u Deep Learning
Classifier Fea tu re Ex t rac t ion P r e p r o c e s s i n g Input
f1 … fn Output
f1
f 2
Output …. F e a t u r e E x t r a c t i o n
Input Classifier F e a t u r e E x t r a c t i o n
F e a t u r e E x t r a c t i o n
딥러닝 아키텍쳐 1: Convolu_onal Neural Nets (CNN)
[LeCun, 1998]
딥러닝 아키텍쳐 2: Deep Belief Networks
(DBN) 1000 neurons
500 neurons
500 neurons
250 neurons
250 neurons
30
1000 neurons
28x28
28x28
linear units
[Hinton et al., 2006]
딥러닝 아키텍쳐 3: Deep Hypernetworks (DHN)
r r r r w w w w w
c1
h
xGrowing
Growing and shrinking
c2
e1
e2
e3
e4
e5
𝑐""𝑐#"
𝑐$" 𝑐%"
𝑐##𝑐"#
(b) Hypergraph representation of (a)
h
c1
c2
“it”
“playful”
“start”“crong”
“sky”
“plane”
“robot”
(a) Example of deep concept hierarchy learned from Pororo videos
r
[Zhang et al., 2012] [Ha et al., 2015]
59
딥러닝 아키텍쳐 4: Recurrent Neural Networks (RNNs)
딥모델 적용분야 비교 Deep Belief Net
(DBN) Convol. NN
(CNN) Deep Hypernet
(DHN)
감독/무감독 감독/무감독 감독 감독/무감독
변별/생성 모델
생성 변별 생성
예측/모듈이해
예측++/모듈-
예측+++/모듈+
예측+/모듈+++
추론가능성
추론++ 추론-‐ 추론++++
연결성
Full/Compact Par_al/Convolved Par_al/Sparse
깊이
깊이+++ 깊이++++
깊이++
배치/온라인 학습
배치
배치
온라인
Amount of data
Perf
orm
ance
Large NN
Medium NN
Small NN
Traditional alg.
Trend 1: Scale driving deep learning process
Amount of data
Perf
orm
ance
Large NN
Medium NN
Small NN
Traditional alg.
Small amount of data
Trend 1: Scale driving deep learning process
Amount of data
Perf
orm
ance
Large NN
Medium NN
Small NN
Traditional alg.
Small amount of data
Traditional alg. with feature engineering would be better
Trend 1: Scale driving deep learning process
Amount of data
Perf
orm
ance
Large NN
Medium NN
Small NN
Traditional alg.
Large amount of data
Trend 1: Scale driving deep learning process
Amount of data
Perf
orm
ance
Large NN
Medium NN
Small NN
Traditional alg.
Large amount of data
Deep learning approach would be better
Trend 1: Scale driving deep learning process
Trend 2: The rise of end-to-end learning
Goal: Build an ultimate predict system Training Val Test
Trend 2: The rise of end-to-end learning
Goal: Build an ultimate predict system Training Val Test
End-to-End works only when you have enough data
to learn function of needed level of complexity
Deep learning bucket
General case DL
For sequence RNN/LSTM/GRU
For Image or 2D/3D data
Other: Unsupervised/RL
6.5 딥러닝 활용 사례
69
Deep Neural Network
Deep learning approach
Deep Neural Network
Deep learning approach
CNN Application Example
72
Rectified Linear Unit
CNN의 예: LeNet5
73
n 입력으로 32x32 픽셀 크기의 이미지를 받음 n C1,C3,C5: 컨볼루션 층 (5 × 5크기의 피처 맵)
n S2, S4: 풀링 층 (인자 2에 의한 풀링, 피처의 크기가 절반으로 축소)
n F6: 단층 신경망 (fully-connected)
Input image: 32x32
C1: 6x28x28
S2: 6x14x14 C3: 6x10x10 S4: 16x15x15
C5: 120
F6: 84
RBF output: 10
CNN의 예: LeNet5
74
• 약 187,000개 뉴런들 사이 연결 존재 • 약 14,000개의 모델 파라미터 존재
http://yann.lecun.com/exdb/lenet/
Input image: 32x32
C1: 6x28x28
S2: 6x14x14 C3: 6x10x10
S4: 16x15x15
C5: 120
F6: 84
RBF output: 10
장점: 물체의 위치와 각도 변화에 대한 불변성
75 http://yann.lecun.com/exdb/lenet/
장점: 물체의 위치와 각도 변화에 대한 불변성
76 http://yann.lecun.com/exdb/lenet/
CNN의 예: LeNet5
77
n 메모리 관점에서 일반적인 다층퍼셉트론보다 더 많은 용량을 차지함 (많은 수의 파라미터)
n 실행 시간 관점에서 컨볼루션 과정이 많은 계산을 필요하고 전체 실행 시간 중 약 2/3의 비중을 차지
n 같은 개수의 파라미터를 갖는 신경망보다 약 3배 가까이 실행시간이 느림
n 120만 개의 고해상도 이미지 n 1,000개의 서로 다른 클래스 n 50,000 검증 이미지, 150,000개의 테스트 이미지
ImageNet Challenge
78
쉬운 클래스
어려운 클래스
ImageNet Challenge
79
ImageNet 데이터 집합에 대한 매년 성능 향상
80
이미지����������� ������������������ 분류의����������� ������������������ Top-5����������� ������������������ 에러����������� ������������������
ILSVRC’10 ILSVRC’11 ILSVRC’12����������� ������������������ AlexNet
ILSVRC’13 ILSVRC’14����������� ������������������ VGG
ILSVRC’14����������� ������������������ GoogleNet
ILSVRC’15����������� ������������������ ResNet
19����������� ������������������ layers 22����������� ������������������ layers
28.2
25.8
16.4
11.7
7.3 6.7
3.57
152����������� ������������������ layers
shallow 8����������� ������������������ layers 8����������� ������������������ layers