1. Visualize patches that maximally activate neurons

각 행은 pool5에서 추출한 임의의 neuron이 가장 activate 시키는 부분을 보여준다.

 

2. Visualize the filters/kernels(raw weights)

이미지에 직접 작용하는 필터는 conv1에 있는 필터이므로, 이것만 해석 가능하다. 

다음의 layer 들의 weight들은 시각화할 수 있지만 low image에 대한 것이 아닌 layer1의 activation에 대한 시각화이기 때문에 큰 의미가 있지는 않다.

3. Visualize the representation

classify 하기 직전의 fc7 layer에서 추출한 representation으로 시각화하는 방법이 있다.

 

대표적인 방법으로 t-sne 시각화 방법이 있다. cnn의 시각으로 볼 때 유사하는 것을 가깝게 위치시켜 준다.

MNIST data

4. Occlusion experiments

occlusder를 슬라이딩 시켜 어느 부분에 위치해 있을 때 정확하게 classify 하는 확률이 변하는지 확인

5. Visualizing Activations

1. Deconvolution-based approach

Q: how can we compute the gradient of any arbitrary neuron in the network w.r.t. the image?

임의의 뉴런이 있는 곳까지 forward pass를 해주고, activation을 구한다.

그 후 해당 layer의 뉴런의 gradient를 1, 그 외에는 gradient를 0로 둔 뒤 back propagation을 수행한다.

Guidied backpropagation을 사용하면 positve한 influence한 반영하게 되어 선명한 이미지를 얻을 수 있다.

relu 대신 modifed relu를 사용하면 Guidied backpropagation을 사용할 수 있다.

backward deconvnet은 relu의 영향을 받지 않아, -인 값들은 0으로 처리 된다.

 

 

2. Optimizationi-based approach

이미지를 파라미터로 이용하는 방법, weight의 update X

 

 

1. Find images that maximize some class score

2. Visualize the Data gradient

하얀 부분이 영향력을 주는 부분

이런 방법을 사용해 segmentation을 수행하는 grabcut이라는 알고리즘도 있다.

 

 

임의의 뉴런에 적용해보면 다음과 같은 과정을 수행할 수 있다.

L2 regularization 대신 blur된 이미지를 사용한다고 한다.

 

 

Question: Given a CNN code, is it possible to reconstruct the original image?

FC 7 layer의 code로 이미지를 복원할 수 있을까?

 

Find an image such that:

- Its code is similar to a given code

- It “looks natural” (image prior regularization)

 

예시

사실 FC 7 layer만이 아니라 다른 layer에서도 복원이 가능하다.

 

 

ex) 구글의 deep dream도 image에 대한 optimization 기법을 사용한다.

gradient를 activation 값으로 사용하게 되어 relu에서 boost 효과가 일어나 여러가지 그림을 합성한 듯한 이미지가 나타나게 됨

 

ex) NeuralStyle

1. content 이미지를 convnet에 넣고, 각각의 layer에서 low activation을 저장한다.

2. Style 이미지를 넣고, style gram matrices를 얻는다.

3. Optimize over image to have

- The content of the content image (activations match content)

- The style of the style image (Gram matrices of activations match style)

 

 

 

Question: Can we use this to “fool” ConvNets??(속이다)

=> Adversial Attack

 

 

0.5씩 조정하여 적대적인 X를 만들 수 있다.  class 0에 해당하는 이미지를 class 1로 분류하게 만들 수 있다.

이는 linear classifier의 본질적인 문제이다.

 

“primary cause of neural networks’ vulnerability to adversarial perturbation is their linear nature“

(and very high-dimensional, sparsely-populated input spaces)

 

Backpropping to the image is powerful. It can be used for:

- Understanding (e.g. visualize optimal stimuli for arbitrary neurons)

- Segmenting objects in the image (kind of)

- Inverting codes and introducing privacy concerns

- Fun (NeuralStyle/DeepDream)

- Confusion and chaos (Adversarial examples)

 

 

 

https://ocw.mit.edu/courses/18-06-linear-algebra-spring-2010/resources/lecture-9-independence-basis-and-dimension/

 

Lecture 9: Independence, basis, and dimension | Linear Algebra | Mathematics | MIT OpenCourseWare

What does it mean for vectors to be independent? How does the idea of independence help us describe subspaces like the nullspace? A basis is a set of vectors, as few as possible, whose combinations produce all vectors in the space. The number of basis vect

ocw.mit.edu

해당 강의를 참고하여 공부한 내용을 정리하였습니다.

새 창에서 열기

 

 

컴퓨터 비전의 주요 TASK

Classification + Localization

Classification

Input : image => Output : class label

평가지표 : Accuracy

 

Localization

Input : image => Output : box in the image

평가지표 : Intersection over Union

 

Idea #1 : Localization as Regression

 

Step 1 : Train (or download) a classification model (AlexNet, VGG, GoogLeNet)

Step 2 : Attach new fully-connected “regression head” to the network

Step 3 : Train the regression head only with SGD and L2 loss

Step 4 :  At test time use both heads

 

 

Per-class(클래스에 특화된) vs class agnostic regression(클래스에 범용적인)

Class specific: C x 4 numbers (one box per class)

Class agnostic: 4 numbers (one box) 

 

 

어디에 regression head를 붙여야 될까?

=> After conv layers, After last FC layer

 

Aside : Localizing multiple objects

정해진 수 K가 있다면 detection을 사용하지 않고 regression만으로도 localization이 가능하다.

 

Aside :  Human Pose Estimation

사람의 관절의 수를 정해져 있기 때문에 regression 만으로도 쉽게 localization이 가능하다.

 

Localization as Regression

- 매우 간단하다.

- 나름 강력하다.

 

 

Idea #2 : Sliding Window

- Run classification + regression network at multiple locations on a highresolution image

- Convert fully-connected layers into convolutional layers for efficient computation

- Combine classifier and regressor predictions across all scales for final prediction

 

대표적인 예시 : Overfeat

- Winner of ILSVRC 2013 localization challenge

 

window를 슬라이딩 시켜 regression head에서 bounding box 4개, classification head에서 score 4개를 다음과 같이 만들어 낸다.

 

 

위 bbox들을 merge하고, 최종 score도 산출해 낸다.

 

실제로도 4개보다 훨씬 많은 sliding window를 사용한다.

이렇게 되면 연산 자체가 heavy해져 효율적이지 못하다.

따라서 fc layer를 conv layer로 바꿔 주었다. 

 

 

 

 

ImageNet Classification+Localization

ResNet은 완전히 다른 방법인 RPN(Regional Proposal Network)를 사용해 엄청난 성능 향상을 이뤄냄.

 

 

Object Detection

Detection as Regression?

- 이미지에 따라서 object의 개수가 달라져 output의 개수도 달라지기 때문에 regression이 적당하지 않다.

- but,,, YOLO(You Only Look Once)에서는 regression을 사용하긴 한다.

 

Detection as Classification

box 영역을 보고 classification을 진행하여 detection을 하는 방법

 

Problem: Need to test many positions and scales

(다양한 사이즈의 많은 window를 필요로 하게 됨.)

Solution: If your classifier is fast enough, just do it

(무거운 classifier만 아니라면, 그냥 해라..)

 

Problem: Need to test many positions and scales, and use a computationally demanding classifier (CNN)

(무거운 연산인 CNN을 필요로 하는 경우)

Solution: Only look at a tiny subset of possible positions

(의심되는 지역만 보자... Region Proposals)

 

ex) HOG, DPM

 

Region Proposals

정확도, 클래스에 상관하지 않고 그냥 blobby한 영역을 매우 빠르게 잡아내는 것

- Find “blobby” image regions that are likely to contain objects

- “Class-agnostic” object detector 

- Look for “blob-like” regions

 

대표적인 방법으로는 Selective Search가 있다.

 

그 외에도 많은 방법들이 있다. (Edgeboxes를  추천해주심)

 

 

그래서 이런 Region Proposal과 CNN를 결합하여 사용한 것이 바로 R-CNN이다.

R-CNN

input 이미지를 받아 proposal method를 사용하여 ROI를 뽑아낸다.(약 2000개)

각각의 ROI는 다른 위치와 크기를 가지게 됨.

정사각형으로 warp을  시킴

Conv에 들어가게 됨.

그 후 regression과 SVM을 이용한 classify를 진행시킴.

 

 

Step 1: Train (or download) a classification model for ImageNet (AlexNet)

 

Step 2: Fine-tune model for detection

- Instead of 1000 ImageNet classes, want 20 object classes + background (21개의 class로 바꿔줘야함.)

- Throw away final fully-connected layer, reinitialize from scratch

- Keep training model using positive / negative regions from detection images

 

Step 3: Extract features

- Extract region proposals for all images

- For each region: warp to CNN input size, run forward through CNN, save pool5 features to disk

- Have a big hard drive: features are ~200GB for PASCAL dataset!

Step 4: Train one binary SVM per class to classify region features

ex) 고양이라면, 고양이인지? 아닌지? 2개 중 하나로 positive, netgative 분류를 함.

Step 5 (bbox regression): For each class, train a linear regression model to map from cached features to offsets to GT boxes to make up for “slightly wrong” proposals

(region proposal이 항상 정확한 것은 아니기 때문에, cache 해놓은 feature에서 regression을 이용해 정확도를 높혀주는 작업이다. 이는 mAP를 3~4% 정도 높혀준다.

 

 

Object Detection : Datasets

PASCAL VOC, ImageNet Detection, MS-COCO...

 

Object Detection : Evaluation

mean average precision (mAP)

R-CNN의 문제점

1. Slow at test-time: need to run full forward pass of CNN for each region proposal

2. SVMs and regressors are post-hoc: CNN features not updated in response to SVMs and regressors

3. Complex multistage training pipeline

 

 

Fast R-CNN

CNN과 region proposal 추출의 순서를 바꾼 것

이미지를 우선 CNN에 돌려 고해상도의 conv feature map을 생성한다. 

여기서 proposal method를 사용해 ROI를 추출하고, 이를  ROI Pooling이라는 기법을 사용해 

FC layer로 넘겨줘 classifier와 regression을 수행한다.

 

R-CNN Problem #1: Slow at test-time due to independent forward passes of the CNN

Solution: Share computation of convolutional layers between proposals for an image

 

R-CNN Problem #2: Post-hoc training: CNN not updated in response to final classifiers and regressors

R-CNN Problem #3: Complex training pipeline

Solution: Just train the whole system end-to-end all at once!

 

high-res conv feature = > low-res conv feature로 바꿔주는 것을 ROI Pooling이 해결해주게 됨.

 

ROI Pooling의 과정

 

 

 

Fast R-CNN 결과

R-CNN은 각각의 Region proposal에 대해 별개로 forward pass

Fast R-CNN은 Region proposal간의 conv layer의 computation을 share하기 때문에 빠르게 된다.

 

Fast R-CNN의 Problem

region proposal을 포함하게 되면 2초나 걸려 real-time으로는 사용하기 힘듬.

Fast R-CNN의 Solution:

Just make the CNN do region proposals too!

 

 

Faster R-CNN

이전까지는 Region Proposal을 외부에서 진행해왔음.

Region Proposal Network를 삽입하여 내부에서 Region Proposal을 수행하게 함.

 

 

 

Faster R-CNN : Region Proposal Network

기본적으로 Convolution Net이다. sliding  3x3 window로 Region Proposal을 생성해냄.

 

 

Faster R-CNN : Training

 

Faster R-CNN : Results

YOLO: You Only Look Once Detection as Regression

Detection을 Regression으로 간주하고 적용하는 기법 이전에는 Detection을 classification으로 간주했었음.

 

Divide image into S x S grid Within each grid cell(일반적으로 7x7)

predict: B Boxes: 4 coordinates + confidence Class scores: C numbers

Regression from image to 7 x 7 x (5 * B + C) tensor

 

Direct prediction using a CNN

 

Faster R-CNN 보다 빠르지만, 성능이 좋지는 않다.

 

Recap Localization:

- Find a fixed number of objects (one or many)

- L2 regression from CNN features to box coordinates

- Much simpler than detection; consider it for your projects!

- Overfeat: Regression + efficient sliding window with FC -> conv conversion

- Deeper networks do better

 

Object Detection:

- Find a variable number of objects by classifying image regions

- Before CNNs: dense multiscale sliding window (HoG, DPM)

- Avoid dense sliding window with region proposals

- R-CNN: Selective Search + CNN classification / regression

- Fast R-CNN: Swap order of convolutions and region extraction

- Faster R-CNN: Compute region proposals within the network

- Deeper networks do better

https://ocw.mit.edu/courses/18-06-linear-algebra-spring-2010/resources/lecture-8-solving-ax-b-row-reduced-form-r/

 

Lecture 8: Solving Ax = b: row reduced form R | Linear Algebra | Mathematics | MIT OpenCourseWare

When does Ax = b have solutions x, and how can we describe those solutions? We describe all solutions to Ax = b based on the free variables and special solutions encoded in the reduced form R. These video lectures of Professor Gilbert Strang teaching 18.06

ocw.mit.edu

해당 강의를 참고하여 공부한 내용을 정리하였습니다.

새 창에서 열기

https://ocw.mit.edu/courses/18-06-linear-algebra-spring-2010/resources/lecture-7-solving-ax-0-pivot-variables-special-solutions/

 

Lecture 7: Solving Ax = 0: pivot variables, special solutions | Linear Algebra | Mathematics | MIT OpenCourseWare

We apply the method of elimination to all matrices, invertible or not. Counting the pivots gives us the rank of the matrix. Further simplifying the matrix puts it in reduced row echelon form R and improves our description of the nullspace. These video lect

ocw.mit.edu

해당 강의를 참고하여 공부한 내용을 정리하였습니다.

새 창에서 열기

 

 

Convolution Layer

이미지의 width, height, depth
필터는 이미지의 depth와 같다.

이미지에 필터를 convolve, 이미지에 공간적으로 슬라이딩하여 dot product 연산을 수행하는 것

 

 

한 로케이션 당  75번의 연산으로 한 숫자를 만들어 낸다.

one filter, one activation map
re-representation 했다.
필터의 개수 = 다음 이미지의 depth, 필터의 depth = 이미지 depth

 

 

첫번째 필터는 이미지의 weight를 시각화한것, 뒤의 것들은 앞단의 filter에 기반해서 시각화한 것.

hierarchy 구조로 복잡한 이미지를 인식하게 됨.

 

 

필터와 signal(image), 2개의 signal이 convolution 작용을 하기 때문에 convolutional layer라고 불린다.

 

 

 

 

 output size의 일반화

 

 

패딩을 사용하여 size를 보존할 수 있다.

이미지의 사이즈가 계속 줄어들면 volume 자체가 shrink해버린다. 너무 빠른 shrinking은 좋지 않다...

 

Ex 1)

Input volume: 32x32x3 10 5x5 filters with stride 1, pad 2 Output volume size: ?

=> Output volume size: (32+2*2-5)/1+1 = 32 spatially, so 32x32x10

 

Ex 2)

Input volume: 32x32x3 10 5x5 filters with stride 1, pad 2 Number of parameters in this layer?

 each filter has 5*5*3 + 1 = 76 params (+1 for bias) => 76*10 = 760

 

 

1x1 filter? -> 의미가 있다.

 

 

각각은 input의 작은 부분과 연결되어 있다. -> local connectivity

모든 뉴런들을 동일한 파라미터를 공유한다.

 

위와 같은 그림의 뉴런들은 같은 local connectivity를 가지지만, 동일한 파라미터를 공유하고 있지 않다. 

 

즉, 동일한 depth내의 뉴런들은 parameter sharing을 하지만, 별개의 activation map에서 동일한 위치에 있는 뉴런들은 local connectivity를 가지는 같은 곳을 쳐다본다.

 

 

 

Pooling Layer

- representation을 작게, 더 관리할 수 있도록 만들어 준다.

- 각각의 activation map에 독립적으로 작용한다.

MAX pooling

Fully Connected Layer (FC layer)

- 열벡터화해서 fully connected하게 연결해 matrix multipication 연산을 해 마지막으로  softmax에서 분류를 하게끔 해준다.

 

Case Study

LeNet-5

AlexNet

Input: 227x227x3 images

First layer (CONV1): 96 11x11 filters applied at stride 4

=> Q: what is the output volume size?

(227-11)/4+1 = 55, [55x55x96]

=> Q: What is the total number of parameters in this layer?

Parameters: (11*11*3)*96 = 35K

 

Input: 227x227x3 images

After CONV1: 55x55x96

Second layer (POOL1): 3x3 filters applied at stride 2

=> Q: what is the output volume size?

(55-3)/2+1 = 27, [27x27x96]

=> Q: what is the number of parameters in this layer?

0, pooling layer에서는 파라미터가 없다.

 

 

 

ZFNet

 

VGGNet

FC가 유용하지 않다(param이 너무 많음)는 의견이 나와 요즘에는 average pooling을 자주 사용한다.

 

=> 성능이 좋지만 복잡하다. FC layer를 average pooling으로 대체하여 파라미터 수를 줄였음.

 

ResNet

기존의 net들이 layer가 많아짐에 따라 error가 커지는 경향이 보임을 지적함.

resnet은 layer가 많아짐에 따라 error가 적어지는 경향을 보임. 많은 layer를 사용함.(152)

 

 

- Batch Normalization after every CONV layer

- Xavier/2 initialization from He et al.

- SGD + Momentum (0.9)

- Learning rate: 0.1, divided by 10 when validation error plateaus

- Mini-batch size 256

- Weight decay of 1e-5

- No dropout used

 

 

요약

- ConvNets stack CONV,POOL,FC layers

- Trend towards smaller filters and deeper architectures

- Trend towards getting rid of POOL/FC layers (just CONV)

- Typical architectures look like [(CONV-RELU)*N-POOL?]*M-(FC-RELU)*K,SOFTMAX where N is usually up to ~5, M is large, 0 <= K <= 2.

- but recent advances such as ResNet/GoogLeNet challenge this paradigm

 

TODO

- parameter update schemes

- Learning rate schedules

- Dropout

- Gradient checking

- Model ensembles

 

 

Parameter update

Stochastic Gradient Descent(sgd)

현재는 단순한 gradient descent 방법을 사용하고 있지만, 앞으로 복잡한 방법에 대해 설명할 예정

단순한 Stochastic Gradient Descent(sgd)는 느리다.

sgd => mini-batch(일부 데이터의 모음)로 loss function을 계산

 

왜 이렇게 sgd는 느릴까??

수직으로는 경사가 가파르고 수평으로 완만한 loss function을 생각해보자.

Q: What is the trajectory along which we converge towards the minimum with SGD?

수직으로는 빠르게 수평으로는 느리게 이동하여 다음과 같이 이동하게 될 것 이다.

그래서 sgd가 느리게 이동하게 되는 것이다. 

 

Momentum update

x를 직접 업데이트 하는 것이 아닌, v(속도)를 업데이트 하여 v를 통해 x를 업데이트 해준다.

(언덕에서 공을 굴리는 느낌)

mu=> 마찰계수

처음에는 overshooting이 발생하지만 결국에는 minimum에 빠르게 도달하게 된다. 

 

Nesterov Momentum update

NAG(Nesterov Accelerated Gradient)라고도 함. momentum보다 항상 covergence rate가 좋다.

일반적으로 momentum은 2개의 part로 나누어져있다. 

mu*v(momentum step) - learningrate*dx(gradient step)

gradient step을 계산하기 전에 momentum step을 계산하고 그 종료점에 gradient step을 구해준다.

shift 해주는 부분만 차이가 있다.

 

하지만, 불편한 부분이 있다.

세타와 다른 위치에서의 gradient를 구하는 것이 일반적인 다른 코드들과의 호환성 측면에서 떨어지게 된다.

그래서 phi를 도입하여 치환하여 위와 같은 식을 구할 수 있게 된다.

 

AdaGrad update

cache라는 개념을 도입하게 된다. cache는 building up이 되는 양수

per-parameter adaptive learning rate method라고 한다.

파라미터들이 다른 값의 lr을 가지게 되는 방법

 

=> 위의 예시에서 AdaGrad를 사용하게 되면, 수직으로는 gradient가 커서 cache가 커지게 되고 lr이 작아지게 되고, 수평으로는 결과적으로 lr이 커지게 된다.

 

=> 하지만 시간이 흐름에 따라 lr이 0에 가까워지게 되고 학습이 종료되게 된다.(단점) 

이를 보완한 것이 바로 RMSProp이다.

 

RMSProp update

decay rate(parameter)를 도입해 cache의 값을 서서히 올라가게 함.

Adam update

momentum과 RMSProp을 결합한 형태

\

 

그럼 어떤 learning rate를 사용해야 할까?

=> 초기에는 크게 후에는 줄여서 사용해야한다.

보통 exponential decay를 사용

 

지금까지 배운 update 방법은 1st order optimization method 이다.

=> loss function을 구하는데 있어 gradient 정보만을 사용하는 방법

 

Secone order optimization methods

Hessian을 통해 경사뿐만아니라 곡면의 구성을 알 수 있어, 바로 최저점으로 갈 수 있게 된다.

그렇다면 learning rate도 필요가 없게 된다. 

장점 : learning rate가 필요가 없게 된다. convergence rate가 빠르다

단점 : 사실 neural net에서는 현실적이지 못하다. 엄청 큰 행렬을 역행렬 연산을 해야하기 때문에..

 

하지만 다른 방법으로 시도해보자는 시도가 있음.

ex) BGFS, L-BFGS

 

그래서 결론은,

보통 adam을 사용하는 것이 좋고, full batch update를 할 수 있는 환경이라면 L-BFGS를 사용해보자.

 

Evaluation : Model Ensembles

1. Train multiple independent models

2. At test time average their results

=> Enjoy 2% extra performance

=> 단점: 여러개의 모델 관리 이슈, test 속도가 느려짐.

 

여러개의 모델이 아리나 단일 모델에서 checkpoint 간의 앙상블을 하더라도 성능향상을 보일 수 있다.

parameter vector들 간의 앙상블도 성능 향상을 보인다.

Regularization (dropout)

일부 뉴런(노드)를 0으로 랜덤으로 설정해줌

어떻게 좋은 아이디어일 수 있을까?

-> redundant(중복)을 하게 된다.

tail 부분이 ear부분을 볼려고 노력을 하게 된다.

다른 해석으로는 Droppit도 하나의 큰 ensemble로 보게 된다는 것이다. 

 

test time은 어떻게 하게 될까?

-> 모든 뉴런을 turn on(no dropout)으로 test한다.

p=0.5로 할 때 activation이 inflate되게 된다. 따라서 scaling이 필요하다.

predict에서 p를 곱해줘서 scaling 해야한다.

이를 편리하게 하기 위해 inverted dropout을 사용해 먼저 /p를 해주는 것이 일반적인 방법이다.

 

Convolutional Neural Network

본격적으로 활용.. LeNet

 

history...

Hubel & Wiesel,,, 방향

Topographical mapping in the cortex,,, locality

이를 컴퓨터를 활용해 인위적으로 시뮬레이션 해보자!..

Neurocognitron[Fukuchima 1980]

Gradient-based learning applied to document recognition [LeCun, Bottou, Bengio, Haffner 1998]

-> LeNet

 

ConvNet의 비약적인 발전

ImageNet Classification with Deep Convolutional Neural Networks [Krizhevsky, Sutskever, Hinton, 2012]

-> AlexNet

 

 

 

https://ocw.mit.edu/courses/18-06-linear-algebra-spring-2010/resources/lecture-6-column-space-and-nullspace/

 

Lecture 6: Column space and nullspace | Linear Algebra | Mathematics | MIT OpenCourseWare

This lecture discusses column space and nullspace. The column space of a matrix A tells us when the equation Ax = b will have a solution x. The nullspace of A tells us which values of x solve the equation Ax = 0. These video lectures of Professor Gilbert S

ocw.mit.edu

해당 강의를 참고하여 공부한 내용을 정리하였습니다.

새 창에서 열기

+ Recent posts