Convolution

2020. 1. 10. 15:43
728x90

Convolution (합성곱) : a sufficient parameter of a network using convolution kernel (filter)

일단 딥러닝을 하기위해서는 tensorflow 와 keras가 필요하다.

*Tensorflow : 기계 학습과 딥러닝을 위해 구글에서 만든 오픈소스 라이브러리. 즉, 딥러닝을 위한 도구이다.

*keras : API/interface for specifying deep learning model

예를 들어, 숫자 2가 적힌 이미지를 인식하는 과정에서 픽셀을 숫자로 바꾼다 - 여백(흰 배경)은 0으로, 색이 어두워질수록 숫자가 높아진다.

2D tensor (kaggle.com)

위와 같이 숫자 이미지 2의 픽셀을 숫자로 변환시킬 수 있다. 이제 여기서부터 컨볼루션을 적용해보자. Let us multiply a small tensor to a a little section of the image. 

By moving the red kernel to the side and down the row to convert the pixel into digits that represent darkness of the image. 

코드작성을 해보자. (코드 작성 후, 코드가 맞는지부터 확인해주는 check() 함수를 사용해보자)

EX1. In the video, you saw a convolution that detected horizontal lines. Now let's create verticle line detector and run the cell to see a raw image as well as the output from applying this convolution to the image. 

from learntools.core import binder
binder.bind(globals())
from learntools.deep_learning.exercise_1 import *
print("Setup Complete") #Set up code checking. Show image.

 

To create vertical line convolution, both numbers on the left of the convolution should be the same, to avoid picking up other patterns. As you can see below, the numbers on the left of each bracket are the same (2).

If you wish to ceate horizontal line detector, you should match both numbers in each bracket. For instance, horizontal_line_conv = [[2, 2], [-1, -1]].

vertical_line_conv = [[2, -2], 
                      [2, -2]]
q_1.check()
visualize_conv(original_image, vertical_line_conv)

 

EX2. Ex1 shows 2x2 tensor and I've showed you 3x3 tensor as well. This means, the tensor can be in any size like 3x3, 4x5, and so on. When you compare the number of visual patterns that can be captured by small convolutions, you can see that the larger the size of convolution, the more possible visual patterns can be captured. In other words, larger convolution can capture the parts that smaller convolution can capture but the other way doesn't work in some cases.

728x90