SlideShare a Scribd company logo
패턴인식을 위
한 인공신경망
Caps-net 구현
한상훈(Adonis Han)
동적 경로배정
Dynamic Routing - Dynamic routing,
also called adaptive routing is a
process where a router can forward
data via a different route or given
destination based on the current
conditions of the communication
circuits within a system.
Sara Sabour, Nicholas Frost, Geoffrey
Hinton
캡슐(capsule)
인간의 뇌는 "캡슐(capsule)"이라는 모듈을
가지고 있다.
이 캡슐은 자세(위치, 크기, 방향), 변형, 속도,
반사계수, 색조, 텍스처 등 다양한 유형의 시
각적 자극과 인코딩을 처리 할 때 특히 유용
하다.
뇌는 낮은 수준의 시각 정보를 "routing"하는
메커니즘을 가져야 하며 이것이 이미지를
처리하기위한 최고의 capsule이라고 믿는 것.
Model of
Capsnet
결론 – 패턴인식(영상) 데이터셋 적용 후
결과
Dataset – MNIST (digit으로된 사진데이
터)
• We get a low test error (0:25%) on a 3
layer network previously only achieved
by deeper networks.
• An under-trained CapsNet with early
stopping which achieved 99.23%
accuracy on the expanded MNIST test.
결론부터 : Capsnet Architect
이 논문의 목적은 이 전체 공간을 탐색하는 것이 아니라 간단한 구현이 효과
적이며 dynamic routing이 도움이 된다는 것을 보여주는 것.
PrimaryCaps
Dynamic routing
• 총 2개의 캡슐 레이어가 있기 때문에 위 설명 과정에서
PrimaryCaps가 layer l이 되고 DigitCaps가 layer l+1이 된다.그리고
PrimaryCaps는 총 1152개가 있으며 DigitCaps는 10개
• 즉, i가 1부터 1152까지, j가 1부터 10까지.
• 다이나믹 루팅은 몇 번의 이터레이션을 거칠지 하이퍼 파라미터
를 지정해줄 수 있다.
• 먼저 PrimaryCaps와 DigitCaps를 이어주는 값 bi을 0으로 설정 그리
고 이 bij를 softmax에 통과시켜 coupling coefficient를 만든다.
• 소프트맥스를 거쳐주면 모든 coupling coefficient의 합이 1이 되게
만들 수 있으며 이 값은 캡슐 i와 캡슐 j의 연결 강도가 된다그 이후
에는 PrimaryCaps의 property를 8개에서 16개로 바꿔주는 작업을
거침.
Capsnet Formula instances
u : prediction vectors
sj : total input
vj : vector output of capsule
c : coupling coeeficient
capsule i and all the capsule sum = 1
초기로그 b 는 cap i 와 cap j 의 결합되어야 하는 로그 사전확률인 라우팅 소프트맥스에 의해 결정됨.
Dynamic routing
• 여기서 Wij은 8 x 16의 크기를 가진 가중치 행렬
(weight matrix)이며 PrimaryCaps가 이 행렬과 곱해지면
벡터의 크기가 8개에서 16개로 바뀐다.
• DigitCaps의 벡터 길이와 같아지게 만들어주는 식.
• 그 이후에는 u^j|i와 Cij를 곱해서 길이 16으로 변환시
킨 PrimaryCaps를 DigitCaps로 얼마나 보낼지 정해준다.
• 그리고 같은 digitcaps로 연결된 캡슐 벡터들을 더해주
면 sj를 구할 수 있다.
Digit Caps -
Squashing
캡슐의 출력 벡터의 길이가 전체구성된(entity)
확률을 나타내기를 원한다. 현재 입력에 캡슐이
나타내는 값이 존재하므로 비선형 "스쿼싱“ 은
capsule의 출력 vector의 길이를 찌부러트린다. 작은
vector인 경우 0으로 채우고 vector 길면 출력
벡vector를 1로 제한한다.
L2 norm : probability of entity exists
Elements : properties of entity
계약 별 라우팅
(routing-by-agreement)
 마지막으로 bij를 업데이트 하는 과정을 거침.
 여기서 aij를 agreement라고 불리운다. U, vj는
서로 차원 수가 같기 때문에 결과값이 스칼라가
되며 이를 logit bij에 업데이트 해주면 드디어
routing iteration이 한 번 끝난다.
계약 별 라우팅
(routing-by-agreement)
특성 및 장점
1. routing by agreement는 max-pooling과 같은 현재 메커니즘보다
우수함.
2. Max pooling route는 하위 계층에서 탐지된 가장 강력한 피처를
기반으로한다.
3. 가능한 모든 parents에 대해 capsule은 prediction vector를 찾을
수 있으며 prediction vector는 자신의 weight와 weight matrix을
곱하여 계산된다.
4. 어느 parents가 largest scalar prediction vector product가 capsule
결합을 증가시킨다. parents의 나머지는 그들의 결합을 줄인다.
5. 이러한 유형의 "계약 별 라우팅 (routing-by-agreement)"은 매우
원시적인 형태의 max-pooling으로 구현 된 라우팅. 한 레이어의
뉴런이 모든 레이어를 무시하도록 허용.
Capsnet in code (Python Keras)
Train code
MNIST
데이터 가시화
Dimension Perturbation method
Capsnet in code (Python)
Conclusion
캡슐의 특징
• 하위 캡슐은 다이나믹 루팅 과정을 통해 이를
가장 잘 처리할 수 있는 상위 캡슐로 연결.
• 하위 캡슐에서는 local information이 “place-
coded”상위 캡슐에서는 훨씬 더 많은
positional information이 “rate-coded”(조합 된
다)됨.
• 다이나믹 루팅 과정을 통해서 캡슐은 더 복잡
한 entity를 훨씬 자유롭게 표현이 가능.
Conclusion
• capsule은 신경층의 중첩 세트이다.(다른 내부
에 신경층을 중첩)
• CapsNet에서는 단일 레이어 안에 더 많은 레
이어를 추가 할 수 있다.
• (일반적인 신경망에서는 더 많은 레이어를 계
속 추가한다.)
• capsule내부신경의 상태가 화상 안에 하나의
엔티티의 특성을 포착하여 엔티티의 존재를
나타내는 vector를 출력한다.
Conclusion
“고차원 공간에서의 우연의 일치는 매우 적다”
• 캡스넷(CapsNet)의 경우 entity를 고차원 공간
에서 바라보게 되는데, 이렇게 바라보면 눈,
코, 입의 공간적인 관계까지 고려한다. 고차
원 공간에서조차 제대로 된 얼굴이 나왔다면
이건 얼굴이 맞다고 판단할 수 있다.
• 캡슐은 벡터로 이루어져 있기에 다이나믹 루
팅(dynamic routing)을 통해 오브젝트 파트(눈,
코,입 등)들의 상대적 위치까지 조합할 수 있
다.(맥스 풀링은 학습가능 파라미터가 존재하
지 않고 특징값만 찾아냄)
Ref
https://jayhey.github.io/deep%20learning/2017/11/28/CapsNet_1/
https://www.nextobe.com/singlepost/2017/11/02/CapsNetCapsule-
Network
Sabour, Sara, Nicholas Frosst, and Geoffrey E. Hinton. “Dynamic
routing between capsules.” Advances in Neural Information Processing
Systems. 2017.
https://github.com/XifengGuo - CapsNet-Keras
정석으로 배우는 딥러닝 스고모리 유우스케 저/손민규 감수/김범준 역 |
위키북스
Ref Page below
계약 별 라우팅 (routing-by-agreement):
the output of the capsule gets sent to an appropriate parent in the layer above. Initially, the output is routed to all possible parents but is scaled down by coupling oefficients that
sum to 1. For each possible parent, the capsule computes a “prediction vector” by multiplying its own output by a weight matrix. If this prediction vector has a large scalar product
with the output of a possible parent, there is top-down feedback which increases the coupling coefficient for that parent and decreasing it for other parents. This increases the
contribution that the capsule makes to that parent thus further increasing the scalar product of the capsule’s prediction with the parent’s output.
캡슐의 출력이 레이어의 적절한 부모에게 전송되도록하는 메커니즘 초기에 출력은 가능한 모든 부모에게 전달되지
만 결합 계수에 의해 축소된다. 가능한 한 각 부모에 대해, 캡슐은 그 각각의 부모에 대해 "예측 벡터"를 가중치 행렬
에 의한 자체 출력을 도와준다. 이 예측 벡터의 출력이 큰 스칼라 곱을 갖는 경우 부모단위가 있을수 있기에 상위에 대
한 커플링 계수(coupling coefficient)를 증가시키며 캡슐의 기여를 증가시킨다. 부모(parents)의 출력과 함께 캡슐 예측
의 스칼라 곱을 더 증가시킨다.
-> routing by agreement는 max-pooling과 같은 현재 메커니즘보다 우수합니다. Max pooling route는 하위 계층에서 탐지된 가장 강력한 피처를 기반으로 합니다.
계약 별 라우팅 (routing-by-agreement):
routing implemented by max-pooling, which allows neurons in one layer to ignore all but the most
active feature detector in a local pool in the layer below.
이러한 유형의 "계약 별 라우팅 (routing-by-agreement)"은 매우 원시적인 형태의 max-pooling
으로 구현 된 라우팅. 한 레이어의 뉴런이 모든 레이어를 무시하도록 허용.
아래의 계층에있는 로컬 풀의 활성 기능 감지기를 사용하여 동적 라우팅 메커니즘은 세분화
에 필요한 설명성을 구현하는 효과적인 방법이다.
Architecture of Dynamic routing
• 총 2개의 캡슐 레이어가 있기 때문에 위 설명 과정에서 PrimaryCaps가 layer l이 되고 DigitCaps가 layer l+1이 된다.그리고
PrimaryCaps는 총 1152개가 있으며 DigitCaps는 10개
• 즉, i가 1부터 1152까지, j가 1부터 10까지
• 다이나믹 루팅은 몇 번의 이터레이션을 거칠지 하이퍼 파라미터를 지정해줄 수 있다.
• 먼저 PrimaryCaps와 DigitCaps를 이어주는 값 bij을 0으로 설정 그리고 이 bij를 softmax에 통과시켜 coupling coefficient를
만듭니다.
• 소프트맥스를 거쳐주면 모든 coupling coefficient의 합이 1이 되게 만들 수 있으며 이 값은 캡슐 i와 캡슐 j의 연결 강도가 됩
니다. 그 이후에는 PrimaryCaps의 property를 8개에서 16개로 바꿔주는 작업을 거칩니다.
• 여기서 Wij은 8 x 16의 크기를 가진 가중치 행렬(weight matrix)이며 PrimaryCaps가 이 행렬과 곱해지면 벡터의 크기가 8개
에서 16개로 바뀝니다. 이제 DigitCaps의 벡터 길이와 같아지게 만들어주는 식이라고 생각하시면 됩니다. 그 이후에는 u^j|i
와 Cij를 곱해서 길이 16으로 변환시킨 PrimaryCaps를 DigitCaps로 얼마나 보낼지 정해준다. 그리고 같은 digitcaps로 연결된
캡슐 벡터들을 더해주면 sj를 구할 수 있다.
Explanation
of Algorithm
Unlike max-pooling however, we do not
throw away information about the precise
position of the entity within the region.
How the vector inputs and outputs of
a capsule are computed
Squashing We want the length of the output
vector of a capsule to represent the probability that the entity represented
by the capsule is present in the current input. short vectors get shrunk to
almost zero length and long vectors get shrunk to a length slightly. We
leave it to discriminative learning to make good use of this non-linearity.
캡슐의 출력 벡터의 길이가 전체구성된(entity)
확률을 나타내기를 원함. 현재 입력에 캡슐이
나타내는 값이 존재하므로 비선형 "스쿼싱“ 은
capsule의 출력 vector의 길이를 찌부러트린
다. 작은 vector인 경우 0으로 채우고 vector
길면 출력 벡vector를 1로 제한한다.
Coupling coefficients
The initial coupling coefficients are then
iteratively refined by measuring the agreement
between the current output v(j) of each capsule, j,
in the layer above and the prediction u(j)(i) made
by capsule i.
초기 coupling coefficients 는 vj(각 캡슐)과 캡슐 i
의 예측되는 값 u로 측정된다. 이 방식은 log
likelihood 를 조성한다. 모든 coupling에 대해 새
로운 값을 계산하기 전에 초기로짓에 추가한다.
소프트맥스를 거쳐주면 모든 coupling
coefficient의 합이 1이 되게 만들 수 있으며 이 값
은 캡슐 i와 캡슐 j의 연결 강도가 된다. 그 이후
에는 PrimaryCaps의 property를 8개에서 16개로
바꿔주는 작업을 거친다.
local grid of vectors
each capsule outputs a local grid of
vectors to each type of capsule in
the layer above using different
transformation matrices for each
member of the grid as well as for
each type of capsule.
CNN에서 각 캡슐은 각 유형의 캡슐에
로컬 그리드백터를 출력. 그리드 각
구성원에 대해 다른 변환행렬
(transformation matrices )을 사용.
Margin loss for digit existence
instantiation vector : We are using the
length of the instantiation vector to
represent the probability that a
capsule’s entity exists. The down-
weighting of the loss for absent digit
classes stops the initial learning from
shrinking the lengths of the activity
vectors of all the digit capsules. The
total loss is simply the sum of the
losses of all digit capsules.
digit is present in the image하면 top-level
capsule 의 digit class k 가 instantiation vector
을 갖기 원함.
그리고 multiple digits을 하기 위해 별도의
margin loss를 사용한다. 부재 숫자 클래스에
대한 손실의 가중치 부여는 초기 학습이 모든
숫자 캡슐의 활동 벡터 길이를 줄이는 것을 중
지한다. 총 손실은 단순히 모든 숫자 캡슐의 손
실 합계이다. vector의 방향은 엔티티의 속성을
나타냄.
Margin loss for digit existence
 digit class k가 존재한다면, 캡슐 벡터의 크기는 큰 값을 가진다.
 만약 입력 데이터에 digit k가 나타났다면 Tk값은 1.
 그리고 m+와 m−는 각각 0.9, 0.1이다. ( λ는 정답 클래스에 속하지 않는 레이블에 대한 loss의 영향도를 줄
여주는 역할을 한다.)
 MNIST 에서는 adam optimizer를 사용했다.
Relu (Rectified
Linear Unit)
• gradient vanishing을 풀기 위해서 sigmoid -> ReLU로
교체
• rectifier 함수, 은닉층에 주로 쓰인다.
• Tanh를 사용하면 경사가 소실되기 어렵게 되어 좋긴
하지만 sigmoid 함수와 마찬가지로 고차원 데이터를
다룰 경우처럼 값이 커질 경우 경사가 소실(vanishing
gradient)되는 문제가 발생한다.
• Tanh와 달리 곡선이 없음. Relu를 미분하면 계단함수
가 됨.
• F’(x) = 1 or 0 (x가 양수일때 1 음수일때 0)
• 즉, relu의 도함수는 x가 아무리 커져도 1을 반환하므
로 경사가 소실되지 않는다.
• 학습의 진행속도가 빠르다.
Relu in Capsnet
컨벌루션 레이어와 완전히 연결된 레이어가 하나씩 있다.
relu을 사용하여 픽셀에 적용하며 이때 검출기는 1차 캡슐에 입력으로 사용된다. 캡슐을 활성
화하기 위해서 랜더링 프로세스가 반전된다. 인스턴스화된 파트를 함께 결합하는 과정과 다름.
두번째 레이어 32채널은 cnn레이어인데 이곳에서의 primary 캡슐 출력은 각 캡슐에 primary
capsule 과 그 연속적인 캡슐레이어 사이에서 라우팅을 한다.
똑같이 callback 함수와 bij는 0으로 초기화된다. 초기캡슐의 output인 u 는 모두 캡슐(v0~v9)
에 동일한 확률(c)로 전송한다.
Optimizer - Adam
• Adadelta와 RMSprop이 직전의 스텝인 t-1까지 경사의 제곱의
이동평균 Vt=E(g)를 지수함수적으로 감쇠평균한 항을 저장해
가며 유지하고 매개변수의 변경식에 이 값을 사용했던 것과는
달리 Adam에서는 여기에 추가로 단순한 경사의 이동평균인
mt,를 지수함수적으로 감쇠시킨항도 사용한다.
• 이때 beta1,beta2∈ [0,1]은 하이퍼 매개변수이며 이동평균의
감쇠율을 조정한다.
• 2차모멘트Vt의 이동평균 E[Vt]와 2차 모멘트 E[g^2]의 관련성
을 구한다.
• 0으로 근사할 수 있도록 하이퍼 매개변수의 값을 설정하여
Unbias(편중되지 않는) 추정값을 구한다.
• Mt는 1차 모멘트(평균), 2차 모멘트(분산)의 추정값에 해당된다.
Optimizer –
Adam (2)
Wording of CNN
• 확실한건 사람, 사이클 복장, 도로, 자전거 등을 보고 저런 방식
으로 인식을 한다는 점입니다. Pooling은 이를 전혀 설명하지
못하고 있습니다.
• NN의 neuron과 layer들로는 entity를 표현을 할 수 없다는 것이
죠.
Wording of CNN
Max Pooling Layer 맥스풀링 레이어
예)MaxPooling2D(pool_size=(2,2))
-영역내에서 최대값 출력.
-영역내에 feature가 존재하는지의 여부
-전체영역이 축소.
max pooling이라는 방법을 도입합니다. 이 방법은 피쳐맵들의 spatial size를 줄여주어 higher layer들의 시야각(field of view)을 넓혀주는 역할을
합니다
맥스 풀링이 invariance를 보존한다는 장점이 있다고 주장했습니다. 하지만 힌튼은 강의에서 맥스 풀링이 잘못된 방법이며 “invariance”가 아닌
“equivariance”가 필요하다고 주장합니다.
확실한건 사람, 사이클 복장, 도로, 자전거 등을 보고 저런 방식으로 인식을 한다는 점입니다. Pooling은 이를 전혀 설명하지 못하고 있습니다.
또한 맥스 풀링은 학습 가능한 파라미터가 존재하지 않으며 단순히 가장 큰 특징적인 값만 뽑아내서 FOV를 넓히는 것 밖에 못한다는 것입니다.
wording
캡슐의 일반적인 개념을 구현할 수 있는 많은 방법이 있습니다. 이 논문의 목적은 이 전체
공간을 탐험하기위한 것이지만 간단하게 구현이 간단하다는 것을 보여줄 수 있습니다.
동적 라우팅이 도움이 됨. squashing은 비선형 따라서 CNN에서와 같이 각 레이어에
squashing 처리를 추가하는 대신 중첩된 레이어 집합에 squashing 처리를 추가 할 수 있습
니다. squashing 함수는 각 capsule의 vector 출력에 적용됨.
이것은 capsule의 출력 vector의 길이를 찌부러트리려고 시도합니다. 작은 vector인 경우 0
으로 채우고 vector 길면 출력 벡vector를 1로 제한하려고합니다. dynamic routing은 약간
의 계산 비용이 추가됩니다. 그러나 확실히 장점이 있습니다.
Explanation of Algorithm
We assume that our multi-layer visual system creates a parse tree-like structure on each fixation,
and we ignore the issue of how these single-fixation parse trees are coordinated over multiple
fixations. Parse trees are generally constructed on the fly by dynamically allocating memory.
단일 제품이 단일 식별 된 객체 및 그 속성보다 훨씬 많은 것을 제공한다고 가정한다.
다중 계층 시각 시스템은 각 고정에 구문 분석 트리 구조를 생성한다고 가정한다.
이러한 단일 고정구문 분석트리가 다중 고정을 통해 어떻게 조정되는지에 대한 문제를 우선
은 무시
Explanation of Algorithm
we explore an interesting alternative which is to use the overall length of the
vector of instantiation parameters to represent the existence of the entity and to
force the orientation. We ensure that the length of the vector output of a capsule
cannot exceed by applying a non-linearity that leaves the orientation of the vector
unchanged but scales down its magnitude.
우리는 캡슐의 벡터 출력 길이가 벡터의 방향을 변경하지 않고 크기를 줄이는
비선형 성을 적용하여 초과 할 수 없도록 한다.
Explanation
of
Algorithm
vector는 신경망의 모든 가능한 parents에 대해
capsule은 prediction vector를 찾을 수 있다.
prediction vector는 자신의 weight와 weight
matrix을 곱하여 계산.
어느 parents가 largest scalar prediction vector
product가 capsule 결합을 증가시키고 parents의
나머지는 그들의 결합을 줄인다.

More Related Content

Similar to [kor ver.]패턴인식을 위한 인공신경망 Caps-net 구현

From maching learning to deep learning episode2
From maching learning to deep learning episode2 From maching learning to deep learning episode2
From maching learning to deep learning episode2
Yongdae Kim
 
[컴퓨터비전과 인공지능] 7. 합성곱 신경망 2
[컴퓨터비전과 인공지능] 7. 합성곱 신경망 2[컴퓨터비전과 인공지능] 7. 합성곱 신경망 2
[컴퓨터비전과 인공지능] 7. 합성곱 신경망 2
jdo
 
Lecture 4: Neural Networks I
Lecture 4: Neural Networks ILecture 4: Neural Networks I
Lecture 4: Neural Networks I
Sang Jun Lee
 
07. PCA
07. PCA07. PCA
07. PCA
Jeonghun Yoon
 
Variational inference intro. (korean ver.)
Variational inference intro. (korean ver.)Variational inference intro. (korean ver.)
Variational inference intro. (korean ver.)
Kiho Hong
 
PR12 Season3 Weight Agnostic Neural Networks
PR12 Season3 Weight Agnostic Neural NetworksPR12 Season3 Weight Agnostic Neural Networks
PR12 Season3 Weight Agnostic Neural Networks
Kyunghoon Jung
 
Guided policy search
Guided policy searchGuided policy search
Guided policy search
Jaehyeon Park
 
[컴퓨터비전과 인공지능] 7. 합성곱 신경망 1
[컴퓨터비전과 인공지능] 7. 합성곱 신경망 1[컴퓨터비전과 인공지능] 7. 합성곱 신경망 1
[컴퓨터비전과 인공지능] 7. 합성곱 신경망 1
jdo
 
Chapter 19 Variational Inference
Chapter 19 Variational InferenceChapter 19 Variational Inference
Chapter 19 Variational Inference
KyeongUkJang
 
2.supervised learning(epoch#2)-3
2.supervised learning(epoch#2)-32.supervised learning(epoch#2)-3
2.supervised learning(epoch#2)-3
Haesun Park
 
Learning how to explain neural networks: PatternNet and PatternAttribution
Learning how to explain neural networks: PatternNet and PatternAttributionLearning how to explain neural networks: PatternNet and PatternAttribution
Learning how to explain neural networks: PatternNet and PatternAttribution
Gyubin Son
 
08. spectal clustering
08. spectal clustering08. spectal clustering
08. spectal clustering
Jeonghun Yoon
 
Deep learning overview
Deep learning overviewDeep learning overview
Deep learning overview
강민국 강민국
 
3.unsupervised learing(epoch#2)
3.unsupervised learing(epoch#2)3.unsupervised learing(epoch#2)
3.unsupervised learing(epoch#2)
Haesun Park
 
Chapter 6 Deep feedforward networks - 2
Chapter 6 Deep feedforward networks - 2Chapter 6 Deep feedforward networks - 2
Chapter 6 Deep feedforward networks - 2
KyeongUkJang
 
Attention is all you need 설명
Attention is all you need 설명Attention is all you need 설명
Attention is all you need 설명
Junho Lee
 
14장 입자 시스템과 스트림 출력.pptx
14장 입자 시스템과 스트림 출력.pptx14장 입자 시스템과 스트림 출력.pptx
14장 입자 시스템과 스트림 출력.pptx
HolyTak
 
[홍대 머신러닝 스터디 - 핸즈온 머신러닝] 2장. 머신러닝 프로젝트 처음부터 끝까지
[홍대 머신러닝 스터디 - 핸즈온 머신러닝] 2장. 머신러닝 프로젝트 처음부터 끝까지[홍대 머신러닝 스터디 - 핸즈온 머신러닝] 2장. 머신러닝 프로젝트 처음부터 끝까지
[홍대 머신러닝 스터디 - 핸즈온 머신러닝] 2장. 머신러닝 프로젝트 처음부터 끝까지
Haesun Park
 
Rnn keras
Rnn kerasRnn keras
Rnn keras
Park Seong Hyeon
 
DL from scratch(6)
DL from scratch(6)DL from scratch(6)
DL from scratch(6)
Park Seong Hyeon
 

Similar to [kor ver.]패턴인식을 위한 인공신경망 Caps-net 구현 (20)

From maching learning to deep learning episode2
From maching learning to deep learning episode2 From maching learning to deep learning episode2
From maching learning to deep learning episode2
 
[컴퓨터비전과 인공지능] 7. 합성곱 신경망 2
[컴퓨터비전과 인공지능] 7. 합성곱 신경망 2[컴퓨터비전과 인공지능] 7. 합성곱 신경망 2
[컴퓨터비전과 인공지능] 7. 합성곱 신경망 2
 
Lecture 4: Neural Networks I
Lecture 4: Neural Networks ILecture 4: Neural Networks I
Lecture 4: Neural Networks I
 
07. PCA
07. PCA07. PCA
07. PCA
 
Variational inference intro. (korean ver.)
Variational inference intro. (korean ver.)Variational inference intro. (korean ver.)
Variational inference intro. (korean ver.)
 
PR12 Season3 Weight Agnostic Neural Networks
PR12 Season3 Weight Agnostic Neural NetworksPR12 Season3 Weight Agnostic Neural Networks
PR12 Season3 Weight Agnostic Neural Networks
 
Guided policy search
Guided policy searchGuided policy search
Guided policy search
 
[컴퓨터비전과 인공지능] 7. 합성곱 신경망 1
[컴퓨터비전과 인공지능] 7. 합성곱 신경망 1[컴퓨터비전과 인공지능] 7. 합성곱 신경망 1
[컴퓨터비전과 인공지능] 7. 합성곱 신경망 1
 
Chapter 19 Variational Inference
Chapter 19 Variational InferenceChapter 19 Variational Inference
Chapter 19 Variational Inference
 
2.supervised learning(epoch#2)-3
2.supervised learning(epoch#2)-32.supervised learning(epoch#2)-3
2.supervised learning(epoch#2)-3
 
Learning how to explain neural networks: PatternNet and PatternAttribution
Learning how to explain neural networks: PatternNet and PatternAttributionLearning how to explain neural networks: PatternNet and PatternAttribution
Learning how to explain neural networks: PatternNet and PatternAttribution
 
08. spectal clustering
08. spectal clustering08. spectal clustering
08. spectal clustering
 
Deep learning overview
Deep learning overviewDeep learning overview
Deep learning overview
 
3.unsupervised learing(epoch#2)
3.unsupervised learing(epoch#2)3.unsupervised learing(epoch#2)
3.unsupervised learing(epoch#2)
 
Chapter 6 Deep feedforward networks - 2
Chapter 6 Deep feedforward networks - 2Chapter 6 Deep feedforward networks - 2
Chapter 6 Deep feedforward networks - 2
 
Attention is all you need 설명
Attention is all you need 설명Attention is all you need 설명
Attention is all you need 설명
 
14장 입자 시스템과 스트림 출력.pptx
14장 입자 시스템과 스트림 출력.pptx14장 입자 시스템과 스트림 출력.pptx
14장 입자 시스템과 스트림 출력.pptx
 
[홍대 머신러닝 스터디 - 핸즈온 머신러닝] 2장. 머신러닝 프로젝트 처음부터 끝까지
[홍대 머신러닝 스터디 - 핸즈온 머신러닝] 2장. 머신러닝 프로젝트 처음부터 끝까지[홍대 머신러닝 스터디 - 핸즈온 머신러닝] 2장. 머신러닝 프로젝트 처음부터 끝까지
[홍대 머신러닝 스터디 - 핸즈온 머신러닝] 2장. 머신러닝 프로젝트 처음부터 끝까지
 
Rnn keras
Rnn kerasRnn keras
Rnn keras
 
DL from scratch(6)
DL from scratch(6)DL from scratch(6)
DL from scratch(6)
 

More from Adonis Han

LDA : latent Dirichlet Allocation (Fairies NLP Series) - Korean Ver.
LDA : latent Dirichlet Allocation (Fairies NLP Series) - Korean Ver.LDA : latent Dirichlet Allocation (Fairies NLP Series) - Korean Ver.
LDA : latent Dirichlet Allocation (Fairies NLP Series) - Korean Ver.
Adonis Han
 
(Kor ver.)NLP embedding(word2vec) tutorial & implementation(Tensorflow)
(Kor ver.)NLP embedding(word2vec) tutorial & implementation(Tensorflow)(Kor ver.)NLP embedding(word2vec) tutorial & implementation(Tensorflow)
(Kor ver.)NLP embedding(word2vec) tutorial & implementation(Tensorflow)
Adonis Han
 
how to understand and implement the "WAVENET"
how to understand and implement the "WAVENET"how to understand and implement the "WAVENET"
how to understand and implement the "WAVENET"
Adonis Han
 
[kor ver.]Global GO (Bigdata-Cloud computing project - mainly in MVC model2)
[kor ver.]Global GO (Bigdata-Cloud computing project - mainly in MVC model2)[kor ver.]Global GO (Bigdata-Cloud computing project - mainly in MVC model2)
[kor ver.]Global GO (Bigdata-Cloud computing project - mainly in MVC model2)
Adonis Han
 
House pricing prediction in R(Regression Project)
House pricing prediction in R(Regression Project)House pricing prediction in R(Regression Project)
House pricing prediction in R(Regression Project)
Adonis Han
 
Facial detection by CNN(Convolution Neural Network) in Kaggle
Facial detection by CNN(Convolution Neural Network) in KaggleFacial detection by CNN(Convolution Neural Network) in Kaggle
Facial detection by CNN(Convolution Neural Network) in Kaggle
Adonis Han
 

More from Adonis Han (6)

LDA : latent Dirichlet Allocation (Fairies NLP Series) - Korean Ver.
LDA : latent Dirichlet Allocation (Fairies NLP Series) - Korean Ver.LDA : latent Dirichlet Allocation (Fairies NLP Series) - Korean Ver.
LDA : latent Dirichlet Allocation (Fairies NLP Series) - Korean Ver.
 
(Kor ver.)NLP embedding(word2vec) tutorial & implementation(Tensorflow)
(Kor ver.)NLP embedding(word2vec) tutorial & implementation(Tensorflow)(Kor ver.)NLP embedding(word2vec) tutorial & implementation(Tensorflow)
(Kor ver.)NLP embedding(word2vec) tutorial & implementation(Tensorflow)
 
how to understand and implement the "WAVENET"
how to understand and implement the "WAVENET"how to understand and implement the "WAVENET"
how to understand and implement the "WAVENET"
 
[kor ver.]Global GO (Bigdata-Cloud computing project - mainly in MVC model2)
[kor ver.]Global GO (Bigdata-Cloud computing project - mainly in MVC model2)[kor ver.]Global GO (Bigdata-Cloud computing project - mainly in MVC model2)
[kor ver.]Global GO (Bigdata-Cloud computing project - mainly in MVC model2)
 
House pricing prediction in R(Regression Project)
House pricing prediction in R(Regression Project)House pricing prediction in R(Regression Project)
House pricing prediction in R(Regression Project)
 
Facial detection by CNN(Convolution Neural Network) in Kaggle
Facial detection by CNN(Convolution Neural Network) in KaggleFacial detection by CNN(Convolution Neural Network) in Kaggle
Facial detection by CNN(Convolution Neural Network) in Kaggle
 

[kor ver.]패턴인식을 위한 인공신경망 Caps-net 구현

  • 2. 동적 경로배정 Dynamic Routing - Dynamic routing, also called adaptive routing is a process where a router can forward data via a different route or given destination based on the current conditions of the communication circuits within a system. Sara Sabour, Nicholas Frost, Geoffrey Hinton
  • 3. 캡슐(capsule) 인간의 뇌는 "캡슐(capsule)"이라는 모듈을 가지고 있다. 이 캡슐은 자세(위치, 크기, 방향), 변형, 속도, 반사계수, 색조, 텍스처 등 다양한 유형의 시 각적 자극과 인코딩을 처리 할 때 특히 유용 하다. 뇌는 낮은 수준의 시각 정보를 "routing"하는 메커니즘을 가져야 하며 이것이 이미지를 처리하기위한 최고의 capsule이라고 믿는 것.
  • 5. 결론 – 패턴인식(영상) 데이터셋 적용 후 결과 Dataset – MNIST (digit으로된 사진데이 터) • We get a low test error (0:25%) on a 3 layer network previously only achieved by deeper networks. • An under-trained CapsNet with early stopping which achieved 99.23% accuracy on the expanded MNIST test.
  • 6. 결론부터 : Capsnet Architect 이 논문의 목적은 이 전체 공간을 탐색하는 것이 아니라 간단한 구현이 효과 적이며 dynamic routing이 도움이 된다는 것을 보여주는 것.
  • 7.
  • 9. Dynamic routing • 총 2개의 캡슐 레이어가 있기 때문에 위 설명 과정에서 PrimaryCaps가 layer l이 되고 DigitCaps가 layer l+1이 된다.그리고 PrimaryCaps는 총 1152개가 있으며 DigitCaps는 10개 • 즉, i가 1부터 1152까지, j가 1부터 10까지. • 다이나믹 루팅은 몇 번의 이터레이션을 거칠지 하이퍼 파라미터 를 지정해줄 수 있다. • 먼저 PrimaryCaps와 DigitCaps를 이어주는 값 bi을 0으로 설정 그리 고 이 bij를 softmax에 통과시켜 coupling coefficient를 만든다. • 소프트맥스를 거쳐주면 모든 coupling coefficient의 합이 1이 되게 만들 수 있으며 이 값은 캡슐 i와 캡슐 j의 연결 강도가 된다그 이후 에는 PrimaryCaps의 property를 8개에서 16개로 바꿔주는 작업을 거침.
  • 10. Capsnet Formula instances u : prediction vectors sj : total input vj : vector output of capsule c : coupling coeeficient capsule i and all the capsule sum = 1 초기로그 b 는 cap i 와 cap j 의 결합되어야 하는 로그 사전확률인 라우팅 소프트맥스에 의해 결정됨.
  • 11. Dynamic routing • 여기서 Wij은 8 x 16의 크기를 가진 가중치 행렬 (weight matrix)이며 PrimaryCaps가 이 행렬과 곱해지면 벡터의 크기가 8개에서 16개로 바뀐다. • DigitCaps의 벡터 길이와 같아지게 만들어주는 식. • 그 이후에는 u^j|i와 Cij를 곱해서 길이 16으로 변환시 킨 PrimaryCaps를 DigitCaps로 얼마나 보낼지 정해준다. • 그리고 같은 digitcaps로 연결된 캡슐 벡터들을 더해주 면 sj를 구할 수 있다.
  • 12. Digit Caps - Squashing 캡슐의 출력 벡터의 길이가 전체구성된(entity) 확률을 나타내기를 원한다. 현재 입력에 캡슐이 나타내는 값이 존재하므로 비선형 "스쿼싱“ 은 capsule의 출력 vector의 길이를 찌부러트린다. 작은 vector인 경우 0으로 채우고 vector 길면 출력 벡vector를 1로 제한한다. L2 norm : probability of entity exists Elements : properties of entity
  • 13. 계약 별 라우팅 (routing-by-agreement)  마지막으로 bij를 업데이트 하는 과정을 거침.  여기서 aij를 agreement라고 불리운다. U, vj는 서로 차원 수가 같기 때문에 결과값이 스칼라가 되며 이를 logit bij에 업데이트 해주면 드디어 routing iteration이 한 번 끝난다.
  • 14. 계약 별 라우팅 (routing-by-agreement) 특성 및 장점 1. routing by agreement는 max-pooling과 같은 현재 메커니즘보다 우수함. 2. Max pooling route는 하위 계층에서 탐지된 가장 강력한 피처를 기반으로한다. 3. 가능한 모든 parents에 대해 capsule은 prediction vector를 찾을 수 있으며 prediction vector는 자신의 weight와 weight matrix을 곱하여 계산된다. 4. 어느 parents가 largest scalar prediction vector product가 capsule 결합을 증가시킨다. parents의 나머지는 그들의 결합을 줄인다. 5. 이러한 유형의 "계약 별 라우팅 (routing-by-agreement)"은 매우 원시적인 형태의 max-pooling으로 구현 된 라우팅. 한 레이어의 뉴런이 모든 레이어를 무시하도록 허용.
  • 15.
  • 16.
  • 17. Capsnet in code (Python Keras)
  • 20.
  • 22. Capsnet in code (Python)
  • 23. Conclusion 캡슐의 특징 • 하위 캡슐은 다이나믹 루팅 과정을 통해 이를 가장 잘 처리할 수 있는 상위 캡슐로 연결. • 하위 캡슐에서는 local information이 “place- coded”상위 캡슐에서는 훨씬 더 많은 positional information이 “rate-coded”(조합 된 다)됨. • 다이나믹 루팅 과정을 통해서 캡슐은 더 복잡 한 entity를 훨씬 자유롭게 표현이 가능.
  • 24. Conclusion • capsule은 신경층의 중첩 세트이다.(다른 내부 에 신경층을 중첩) • CapsNet에서는 단일 레이어 안에 더 많은 레 이어를 추가 할 수 있다. • (일반적인 신경망에서는 더 많은 레이어를 계 속 추가한다.) • capsule내부신경의 상태가 화상 안에 하나의 엔티티의 특성을 포착하여 엔티티의 존재를 나타내는 vector를 출력한다.
  • 25. Conclusion “고차원 공간에서의 우연의 일치는 매우 적다” • 캡스넷(CapsNet)의 경우 entity를 고차원 공간 에서 바라보게 되는데, 이렇게 바라보면 눈, 코, 입의 공간적인 관계까지 고려한다. 고차 원 공간에서조차 제대로 된 얼굴이 나왔다면 이건 얼굴이 맞다고 판단할 수 있다. • 캡슐은 벡터로 이루어져 있기에 다이나믹 루 팅(dynamic routing)을 통해 오브젝트 파트(눈, 코,입 등)들의 상대적 위치까지 조합할 수 있 다.(맥스 풀링은 학습가능 파라미터가 존재하 지 않고 특징값만 찾아냄)
  • 26.
  • 27. Ref https://jayhey.github.io/deep%20learning/2017/11/28/CapsNet_1/ https://www.nextobe.com/singlepost/2017/11/02/CapsNetCapsule- Network Sabour, Sara, Nicholas Frosst, and Geoffrey E. Hinton. “Dynamic routing between capsules.” Advances in Neural Information Processing Systems. 2017. https://github.com/XifengGuo - CapsNet-Keras 정석으로 배우는 딥러닝 스고모리 유우스케 저/손민규 감수/김범준 역 | 위키북스
  • 29. 계약 별 라우팅 (routing-by-agreement): the output of the capsule gets sent to an appropriate parent in the layer above. Initially, the output is routed to all possible parents but is scaled down by coupling oefficients that sum to 1. For each possible parent, the capsule computes a “prediction vector” by multiplying its own output by a weight matrix. If this prediction vector has a large scalar product with the output of a possible parent, there is top-down feedback which increases the coupling coefficient for that parent and decreasing it for other parents. This increases the contribution that the capsule makes to that parent thus further increasing the scalar product of the capsule’s prediction with the parent’s output. 캡슐의 출력이 레이어의 적절한 부모에게 전송되도록하는 메커니즘 초기에 출력은 가능한 모든 부모에게 전달되지 만 결합 계수에 의해 축소된다. 가능한 한 각 부모에 대해, 캡슐은 그 각각의 부모에 대해 "예측 벡터"를 가중치 행렬 에 의한 자체 출력을 도와준다. 이 예측 벡터의 출력이 큰 스칼라 곱을 갖는 경우 부모단위가 있을수 있기에 상위에 대 한 커플링 계수(coupling coefficient)를 증가시키며 캡슐의 기여를 증가시킨다. 부모(parents)의 출력과 함께 캡슐 예측 의 스칼라 곱을 더 증가시킨다. -> routing by agreement는 max-pooling과 같은 현재 메커니즘보다 우수합니다. Max pooling route는 하위 계층에서 탐지된 가장 강력한 피처를 기반으로 합니다.
  • 30. 계약 별 라우팅 (routing-by-agreement): routing implemented by max-pooling, which allows neurons in one layer to ignore all but the most active feature detector in a local pool in the layer below. 이러한 유형의 "계약 별 라우팅 (routing-by-agreement)"은 매우 원시적인 형태의 max-pooling 으로 구현 된 라우팅. 한 레이어의 뉴런이 모든 레이어를 무시하도록 허용. 아래의 계층에있는 로컬 풀의 활성 기능 감지기를 사용하여 동적 라우팅 메커니즘은 세분화 에 필요한 설명성을 구현하는 효과적인 방법이다.
  • 31. Architecture of Dynamic routing • 총 2개의 캡슐 레이어가 있기 때문에 위 설명 과정에서 PrimaryCaps가 layer l이 되고 DigitCaps가 layer l+1이 된다.그리고 PrimaryCaps는 총 1152개가 있으며 DigitCaps는 10개 • 즉, i가 1부터 1152까지, j가 1부터 10까지 • 다이나믹 루팅은 몇 번의 이터레이션을 거칠지 하이퍼 파라미터를 지정해줄 수 있다. • 먼저 PrimaryCaps와 DigitCaps를 이어주는 값 bij을 0으로 설정 그리고 이 bij를 softmax에 통과시켜 coupling coefficient를 만듭니다. • 소프트맥스를 거쳐주면 모든 coupling coefficient의 합이 1이 되게 만들 수 있으며 이 값은 캡슐 i와 캡슐 j의 연결 강도가 됩 니다. 그 이후에는 PrimaryCaps의 property를 8개에서 16개로 바꿔주는 작업을 거칩니다. • 여기서 Wij은 8 x 16의 크기를 가진 가중치 행렬(weight matrix)이며 PrimaryCaps가 이 행렬과 곱해지면 벡터의 크기가 8개 에서 16개로 바뀝니다. 이제 DigitCaps의 벡터 길이와 같아지게 만들어주는 식이라고 생각하시면 됩니다. 그 이후에는 u^j|i 와 Cij를 곱해서 길이 16으로 변환시킨 PrimaryCaps를 DigitCaps로 얼마나 보낼지 정해준다. 그리고 같은 digitcaps로 연결된 캡슐 벡터들을 더해주면 sj를 구할 수 있다.
  • 32. Explanation of Algorithm Unlike max-pooling however, we do not throw away information about the precise position of the entity within the region.
  • 33. How the vector inputs and outputs of a capsule are computed Squashing We want the length of the output vector of a capsule to represent the probability that the entity represented by the capsule is present in the current input. short vectors get shrunk to almost zero length and long vectors get shrunk to a length slightly. We leave it to discriminative learning to make good use of this non-linearity. 캡슐의 출력 벡터의 길이가 전체구성된(entity) 확률을 나타내기를 원함. 현재 입력에 캡슐이 나타내는 값이 존재하므로 비선형 "스쿼싱“ 은 capsule의 출력 vector의 길이를 찌부러트린 다. 작은 vector인 경우 0으로 채우고 vector 길면 출력 벡vector를 1로 제한한다.
  • 34. Coupling coefficients The initial coupling coefficients are then iteratively refined by measuring the agreement between the current output v(j) of each capsule, j, in the layer above and the prediction u(j)(i) made by capsule i. 초기 coupling coefficients 는 vj(각 캡슐)과 캡슐 i 의 예측되는 값 u로 측정된다. 이 방식은 log likelihood 를 조성한다. 모든 coupling에 대해 새 로운 값을 계산하기 전에 초기로짓에 추가한다. 소프트맥스를 거쳐주면 모든 coupling coefficient의 합이 1이 되게 만들 수 있으며 이 값 은 캡슐 i와 캡슐 j의 연결 강도가 된다. 그 이후 에는 PrimaryCaps의 property를 8개에서 16개로 바꿔주는 작업을 거친다.
  • 35. local grid of vectors each capsule outputs a local grid of vectors to each type of capsule in the layer above using different transformation matrices for each member of the grid as well as for each type of capsule. CNN에서 각 캡슐은 각 유형의 캡슐에 로컬 그리드백터를 출력. 그리드 각 구성원에 대해 다른 변환행렬 (transformation matrices )을 사용.
  • 36. Margin loss for digit existence instantiation vector : We are using the length of the instantiation vector to represent the probability that a capsule’s entity exists. The down- weighting of the loss for absent digit classes stops the initial learning from shrinking the lengths of the activity vectors of all the digit capsules. The total loss is simply the sum of the losses of all digit capsules. digit is present in the image하면 top-level capsule 의 digit class k 가 instantiation vector 을 갖기 원함. 그리고 multiple digits을 하기 위해 별도의 margin loss를 사용한다. 부재 숫자 클래스에 대한 손실의 가중치 부여는 초기 학습이 모든 숫자 캡슐의 활동 벡터 길이를 줄이는 것을 중 지한다. 총 손실은 단순히 모든 숫자 캡슐의 손 실 합계이다. vector의 방향은 엔티티의 속성을 나타냄.
  • 37. Margin loss for digit existence  digit class k가 존재한다면, 캡슐 벡터의 크기는 큰 값을 가진다.  만약 입력 데이터에 digit k가 나타났다면 Tk값은 1.  그리고 m+와 m−는 각각 0.9, 0.1이다. ( λ는 정답 클래스에 속하지 않는 레이블에 대한 loss의 영향도를 줄 여주는 역할을 한다.)  MNIST 에서는 adam optimizer를 사용했다.
  • 38. Relu (Rectified Linear Unit) • gradient vanishing을 풀기 위해서 sigmoid -> ReLU로 교체 • rectifier 함수, 은닉층에 주로 쓰인다. • Tanh를 사용하면 경사가 소실되기 어렵게 되어 좋긴 하지만 sigmoid 함수와 마찬가지로 고차원 데이터를 다룰 경우처럼 값이 커질 경우 경사가 소실(vanishing gradient)되는 문제가 발생한다. • Tanh와 달리 곡선이 없음. Relu를 미분하면 계단함수 가 됨. • F’(x) = 1 or 0 (x가 양수일때 1 음수일때 0) • 즉, relu의 도함수는 x가 아무리 커져도 1을 반환하므 로 경사가 소실되지 않는다. • 학습의 진행속도가 빠르다.
  • 39. Relu in Capsnet 컨벌루션 레이어와 완전히 연결된 레이어가 하나씩 있다. relu을 사용하여 픽셀에 적용하며 이때 검출기는 1차 캡슐에 입력으로 사용된다. 캡슐을 활성 화하기 위해서 랜더링 프로세스가 반전된다. 인스턴스화된 파트를 함께 결합하는 과정과 다름. 두번째 레이어 32채널은 cnn레이어인데 이곳에서의 primary 캡슐 출력은 각 캡슐에 primary capsule 과 그 연속적인 캡슐레이어 사이에서 라우팅을 한다. 똑같이 callback 함수와 bij는 0으로 초기화된다. 초기캡슐의 output인 u 는 모두 캡슐(v0~v9) 에 동일한 확률(c)로 전송한다.
  • 40. Optimizer - Adam • Adadelta와 RMSprop이 직전의 스텝인 t-1까지 경사의 제곱의 이동평균 Vt=E(g)를 지수함수적으로 감쇠평균한 항을 저장해 가며 유지하고 매개변수의 변경식에 이 값을 사용했던 것과는 달리 Adam에서는 여기에 추가로 단순한 경사의 이동평균인 mt,를 지수함수적으로 감쇠시킨항도 사용한다. • 이때 beta1,beta2∈ [0,1]은 하이퍼 매개변수이며 이동평균의 감쇠율을 조정한다. • 2차모멘트Vt의 이동평균 E[Vt]와 2차 모멘트 E[g^2]의 관련성 을 구한다. • 0으로 근사할 수 있도록 하이퍼 매개변수의 값을 설정하여 Unbias(편중되지 않는) 추정값을 구한다. • Mt는 1차 모멘트(평균), 2차 모멘트(분산)의 추정값에 해당된다.
  • 42. Wording of CNN • 확실한건 사람, 사이클 복장, 도로, 자전거 등을 보고 저런 방식 으로 인식을 한다는 점입니다. Pooling은 이를 전혀 설명하지 못하고 있습니다. • NN의 neuron과 layer들로는 entity를 표현을 할 수 없다는 것이 죠.
  • 43. Wording of CNN Max Pooling Layer 맥스풀링 레이어 예)MaxPooling2D(pool_size=(2,2)) -영역내에서 최대값 출력. -영역내에 feature가 존재하는지의 여부 -전체영역이 축소. max pooling이라는 방법을 도입합니다. 이 방법은 피쳐맵들의 spatial size를 줄여주어 higher layer들의 시야각(field of view)을 넓혀주는 역할을 합니다 맥스 풀링이 invariance를 보존한다는 장점이 있다고 주장했습니다. 하지만 힌튼은 강의에서 맥스 풀링이 잘못된 방법이며 “invariance”가 아닌 “equivariance”가 필요하다고 주장합니다. 확실한건 사람, 사이클 복장, 도로, 자전거 등을 보고 저런 방식으로 인식을 한다는 점입니다. Pooling은 이를 전혀 설명하지 못하고 있습니다. 또한 맥스 풀링은 학습 가능한 파라미터가 존재하지 않으며 단순히 가장 큰 특징적인 값만 뽑아내서 FOV를 넓히는 것 밖에 못한다는 것입니다.
  • 44. wording 캡슐의 일반적인 개념을 구현할 수 있는 많은 방법이 있습니다. 이 논문의 목적은 이 전체 공간을 탐험하기위한 것이지만 간단하게 구현이 간단하다는 것을 보여줄 수 있습니다. 동적 라우팅이 도움이 됨. squashing은 비선형 따라서 CNN에서와 같이 각 레이어에 squashing 처리를 추가하는 대신 중첩된 레이어 집합에 squashing 처리를 추가 할 수 있습 니다. squashing 함수는 각 capsule의 vector 출력에 적용됨. 이것은 capsule의 출력 vector의 길이를 찌부러트리려고 시도합니다. 작은 vector인 경우 0 으로 채우고 vector 길면 출력 벡vector를 1로 제한하려고합니다. dynamic routing은 약간 의 계산 비용이 추가됩니다. 그러나 확실히 장점이 있습니다.
  • 45. Explanation of Algorithm We assume that our multi-layer visual system creates a parse tree-like structure on each fixation, and we ignore the issue of how these single-fixation parse trees are coordinated over multiple fixations. Parse trees are generally constructed on the fly by dynamically allocating memory. 단일 제품이 단일 식별 된 객체 및 그 속성보다 훨씬 많은 것을 제공한다고 가정한다. 다중 계층 시각 시스템은 각 고정에 구문 분석 트리 구조를 생성한다고 가정한다. 이러한 단일 고정구문 분석트리가 다중 고정을 통해 어떻게 조정되는지에 대한 문제를 우선 은 무시
  • 46. Explanation of Algorithm we explore an interesting alternative which is to use the overall length of the vector of instantiation parameters to represent the existence of the entity and to force the orientation. We ensure that the length of the vector output of a capsule cannot exceed by applying a non-linearity that leaves the orientation of the vector unchanged but scales down its magnitude. 우리는 캡슐의 벡터 출력 길이가 벡터의 방향을 변경하지 않고 크기를 줄이는 비선형 성을 적용하여 초과 할 수 없도록 한다.
  • 47. Explanation of Algorithm vector는 신경망의 모든 가능한 parents에 대해 capsule은 prediction vector를 찾을 수 있다. prediction vector는 자신의 weight와 weight matrix을 곱하여 계산. 어느 parents가 largest scalar prediction vector product가 capsule 결합을 증가시키고 parents의 나머지는 그들의 결합을 줄인다.

Editor's Notes

  1. 동적 경로배정 Dynamic Routing - Dynamic routing, also called adaptive routing,[1][2] is a process where a router can forward data via a different route or given destination based on the current conditions of the communication circuits within a system.[3
  2. 통계적 추정(Estimation)의 정확성(Accuracy)에 대한 질적인 척도로 많이 사용됨 - 실제값(관측값)과 추정값과의 차이 즉, 잔차가 얼마인가를 알려주는데 많이 사용되는 척도 - 점추정에 있어 정확도 선택기준의 중요한 하나의 측도(measure)임 ㅇ 오차 또는 잔차를 일반화시키기 위한 척도 - 단순히, 절대값 오차(평균 절대값 오차, 최대 절대값 오차) 등도 가능 - 평균 제곱 오차 (MSE) . `오차(잔차)의 제곱에 대해 평균을 취한 것`으로 이를 추정의 질적 평가척도로 삼게됨 - 제곱근 평균 제곱 오차 (RMSE) . `오차(잔차)의 제곱에 대해 평균을 취하고 이를 제곱근한 것. 혼동행렬 (Confusion Matrix) • 정확도(Accuracy): 전체에서 올바른 예측 비율
  3. Input : 28 x 28 x 1 (우리가 잘 알고 있는 MNIST 데이터) Conv1 kernel : 9 x 9 x 256, stride 1 + ReLU Output : 20 x 20 x 256 Primary Caps : 9 x 9 x (32 x 8), stride 2 + ReLU(?) Digit Caps : dynamic routing 1. 처음 입력으로 들어오는 28 x 28 x 1의 MNIST digit이 들어온다. 2. 9 x 9짜리 256개의 필터를 가진 커널을 거쳐 20 x 20짜리 256갤의 피쳐 맵을 만듭니다. 3. 그 이후에 PrimaryCaps를 형성하는 과정 : 우리가 원래 알고있던 콘볼루션 필터를 거치는 작업을 거친다. 3-1)20 x 20짜리 256개의 피쳐맵. 3-2)9 x 9짜리 32 x 8개의 피쳐맵을 만드는 콘볼루션 필터를 거치면 PrimaryCaps가 나오게 된다. 4. 그렇게 나온 벡터를 위 그림처럼 reshape을 하게 됩니다. 즉, 캡슐 하나 당 8개의 property를 가질 수 있게한다. 5. 콘볼루션 필터를 거친 6 x 6 x (32 x 8) 피쳐맵을 (6 x 6 x 32) x 8로 reshape을 시켜주게 된다. 6. 이렇게 되면 총 6 x 6 x 32 = 1152개의 각각 8개의 property를 가지는 첫 번째 캡슐들이 생성됨. LSTM은 RNN의 히든 state에 cell-state를 추가한 구조 - RNN이 recurrent 하다고 불리는 이유는 동일한 태스크를 한 시퀀스의 모든 요소마다 적용하고, 출력 결과는 이전의 계산 결과에 영향을 받기 때문 "이 논문의 목적은 이 전체 공간을 탐색하는 것이 아니라 간단한 구현이 효과적이며 dynamic routing이 도움이된다는 것을 보여주는 것입니다.“
  4. 1. 처음 입력으로 들어오는 28 x 28 x 1의 MNIST digit이 들어온다. 2. 9 x 9짜리 256개의 필터를 가진 커널을 거쳐 20 x 20짜리 256갤의 피쳐 맵을 만듭니다. 3. 그 이후에 PrimaryCaps를 형성하는 과정 : 우리가 원래 알고있던 콘볼루션 필터를 거치는 작업을 거친다. 3-1)20 x 20짜리 256개의 피쳐맵. 3-2)9 x 9짜리 32 x 8개의 피쳐맵을 만드는 콘볼루션 필터를 거치면 PrimaryCaps가 나오게 된다. Reshape output 4. 그렇게 나온 벡터를 위 그림처럼 reshape을 하게 됩니다. 즉, 캡슐 하나 당 8개의 property를 가질 수 있게한다. 5. 콘볼루션 필터를 거친 6 x 6 x (32 x 8) 피쳐맵을 (6 x 6 x 32) x 8로 reshape을 시켜주게 된다. 6. 이렇게 되면 총 6 x 6 x 32 = 1152개의 각각 8개의 property를 가지는 첫 번째 캡슐들이 생성됨.
  5. 논문 그림 중 PrimaryCaps라고 써진 직육면체(?) 하나를 가져온다 생각하면 위 그림의 왼쪽 그림처럼 생각하시면 편합니다. 저 초록색 벡터가 하나의 캡슐이고 총 8개의 property를 가지게 됩니다. 즉, (36 x 32 = 1152)개의 캡슐이 한 캡슐 당 8개의 element(property)를 가지게 됩니다. 그리고 이 캡슐들이 다이나믹 루팅(dynamic routing) 과정을 통해 상위 레벨의 캡슐과 이어집니다. 최종적으로는 총 10개의 캡슐이 output으로 나옵니다. MNIST데이터셋의 클래스가 0부터 9까지로 10개이기 때문이겠죠? 각 캡슐은 16개의 원소로 이루어진 벡터이며 원소는 전부 entity(여기서는 digit)의 property를 나타냅니다.
  6. 위 과정을 계속 거치는게 dynamic routing이라고 할 수 있겠습니다.
  7. -뉴런의 모델링 : x - 입력되는 뉴런의 축삭돌기로부터 전달되는 신호의 양. w - 시냅스의 강도, 즉 입력되는 뉴런의 영향력을 나타냄. w*x - 입력되는 신호의 양 * 신호의 시냅스 강도 f - 규칙,즉 최종 합계가 다른 뉴런에게 전달되는 신호의 양을 결정짓는 규칙.(활성화함수) 필터 필터는 가중치를 의미한다. Max Pooling Layer맥스풀링 레이어 예)MaxPooling2D(pool_size=(2,2)) -영역내에서 최대값 출력. -영역내에 feature가 존재하는지의 여부 -전체영역이 축소. flatten 레이어 영상을 일차원으로 바꿔준다. Dense 레이어 가중치의 수 입출력을 모두 연결해줌
  8. Optimizaer Adam (Adaptive Moment Estimation) -RMSProp과 Momentum 방식을 합친 것 같은 알고리즘이다. -Momentum 방식과 유사하게 지금까지 계산해온 기울기의 지수평균을 저장하며, RMSProp과 유사하게 기울기의 제곱값의 지수평균을 저장한다. -Adam에서는 m과 v가 처음에 0으로 초기화되어 있기 때문에 학습의 초반부에서는 mt,vtmt,vt가 0에 가깝게 bias 되어있을 것이라고 판단하여 이를 unbiased 하게 만들어주는 작업을 거친다. Momentum Gradient Descent를 통해 이동하는 과정에 일종의 관성을 주는 것으로 과거에 이동했던 방식을 기억하면서 그 방향으로 일정 정도를 추가적으로 이동하는 방식임. 보통 0.9정도의 값을 사용한다. -Momentum 방식은 SGD가 Oscilation (진동)현상을 겪을 때 더욱 빛을 발한다. -이 방식을 사용할 경우 자주 이동하는 방향에 관성이 걸리게 되고, 진동을 하더라도 중앙으로 가는 방향에 힘을 얻기 때문에 SGD에 비해 상대적으로 빠르게 이동할 수 있다. -local minima를 빠져나오는 효과가 있을 것이라고도 기대할 수 있다. - momentum 방식을 이용할 경우 기존의 변수들 θ 외에도 과거에 이동했던 양을 변수별로 저장해야하므로 변수에 대한 메모리가 기존의 두 배로 필요하게 된다. Rmsprop의 기본적인 아이디어는, 이전 gradient들의 합에 따라 파라미터별로 learning rate을 조정하는 것입니다. 컨벌루션 레이어와 완전히 연결된 레이어가 하나씩 있다. relu activation functio을 사용하여 픽셀에 적용하며 이때 검출기는 1차 캡슐에 입력으로 사용된다. 캡슐을 활성화하기 위해서 랜더링 프로세스가 반전된다. 인스턴스화된 파트를 함께 결합하는 과정과 다름. 두번째 레이어 32채널은 cnn레이어인데 이곳에서의 primary 캡슐 출력은 각 캡슐에 primary capsule 과 그 연속적인 캡슐레이어 사이에서 라우팅을 한다. 똑같이 callback 함수와 bij는 0으로 초기화된다. 초기캡슐의 output인 u 는 모두 캡슐(v0~v9)에 동일한 확률(c)로 전송한다. activation functiondms adam 을 사용하였음.
  9. -> vector는 신경망의 모든 가능한 부모에게 전송됩니다. 가능한 모든 parents에 대해 capsule은 prediction vector를 찾을 수 있습니다. prediction vector는 자신의 weight와 weight matrix을 곱하여 계산됩니다. 어느 parents가 largest scalar prediction vector product가 capsule 결합을 증가시킵니다. parents의 나머지는 그들의 결합을 줄입니다.
  10. Max Pooling Layer 맥스풀링 레이어 예)MaxPooling2D(pool_size=(2,2)) -영역내에서 최대값 출력. -영역내에 feature가 존재하는지의 여부 -전체영역이 축소. 맥스 풀링이 invariance를 보존한다는 장점이 있다고 주장했습니다. 하지만 힌튼은 강의에서 맥스 풀링이 잘못된 방법이며 “invariance”가 아닌 “equivariance”가 필요하다고 주장합니다. 확실한건 사람, 사이클 복장, 도로, 자전거 등을 보고 저런 방식으로 인식을 한다는 점입니다. Pooling은 이를 전혀 설명하지 못하고 있습니다.
  11. 캡슐의 일반적인 개념을 구현할 수 있는 많은 방법이 있습니다. 이 논문의 목적은 이 전체 공간을 탐험하기위한 것이지만 간단하게 구현이 간단하다는 것을 보여줄 수 있습니다. 동적 라우팅이 도움이 됨.  squashing은 비선형 입니다. 따라서 CNN에서와 같이 각 레이어에 squashing 처리를 추가하는 대신 중첩된 레이어 집합에 squashing 처리를 추가 할 수 있습니다. squashing 함수는 각 capsule의 vector 출력에 적용됩니다. 이것은 capsule의 출력 vector의 길이를 찌부러트리려고 시도합니다. 작은 vector인 경우 0으로 채우고 vector 길면 출력 벡vector를 1로 제한하려고합니다. dynamic routing은 약간의 계산 비용이 추가됩니다. 그러나 확실히 장점이 있습니다.
  12. digit class k가 존재한다면, 캡슐 벡터의 크기는 큰 값을 가집니다. 실험 부분에서 설명드릴 내용이지만 multiple digit에 관련된 실험을 위해서 분리된 margin loss를 사용합니다. 만약 입력 데이터에 digit k가 나타났다면 TkTk값은 1이 됩니다. 그리고 m+m+와 m−m−는 각각 0.9, 0.1입니다. λλ는 정답 클래스에 속하지 않는 레이블에 대한 loss의 영향도를 줄여주는 역할을 합니다. 
  13. A simple CapsNet architecture is shown in Fig. 1. The architecture is shallow with only two convolutional layers and one fully connected layer. Conv1 has 256, 9 9 convolution kernels with a stride of 1 and ReLU activation. This layer converts pixel intensities to the activities of local feature detectors that are then used as inputs to the primary capsules. The primary capsules are the lowest level of multi-dimensional entities and, from an inverse graphics perspective, activating the primary capsules corresponds to inverting the rendering process. This is a very different type of computation than piecing instantiated parts together to make familiar wholes, which is what capsules are designed to be good at. The second layer (PrimaryCapsules) is a convolutional capsule layer with 32 channels of convolutional 8D capsules (i.e. each primary capsule contains 8 convolutional units with a 9 9 kernel and a stride of 2). Each primary capsule output sees the outputs of all 256 81 Conv1 units whose receptive fields overlap with the location of the center of the capsule. In total PrimaryCapsules has [3266] capsule outputs (each output is an 8D vector) and each capsule in the [6 6] grid is sharing their weights with each other. One can see PrimaryCapsules as a Convolution layer with Eq. 1 as its block non-linearity. The final Layer (DigitCaps) has one 16D capsule per digit class and each of these capsules receives input from all the capsules in the layer below. We have routing only between two consecutive capsule layers (e.g. PrimaryCapsules and DigitCaps). Since Conv1 output is 1D, there is no orientation in its space to agree on. Therefore, no routing is used between Conv1 and PrimaryCapsules. All the routing logits (bij ) are initialized to zero. Therefore, initially a capsule output (ui) is sent to all parent capsules (v0:::v9) with equal probability (cij ). Our implementation is in TensorFlow (Abadi et al. [2016]) and we use the Adam optimizer (Kingmaand Ba [2014]) with its TensorFlow default parameters, including the exponentially decaying learning rate, to minimize the sum of the margin losses in Eq. 4.
  14. -Momentum 방식과 유사하게 지금까지 계산해온 기울기의 지수평균을 저장하며, RMSProp과 유사하게 기울기의 제곱값의 지수평균을 저장한다. -Adam에서는 m과 v가 처음에 0으로 초기화되어 있기 때문에 학습의 초반부에서는 mt,vtmt,vt가 0에 가깝게 bias 되어있을 것이라고 판단하여 이를 unbiased 하게 만들어주는 작업을 거친다.