반응형
블로그 이미지
개발자로서 현장에서 일하면서 새로 접하는 기술들이나 알게된 정보 등을 정리하기 위한 블로그입니다. 운 좋게 미국에서 큰 회사들의 프로젝트에서 컬설턴트로 일하고 있어서 새로운 기술들을 접할 기회가 많이 있습니다. 미국의 IT 프로젝트에서 사용되는 툴들에 대해 많은 분들과 정보를 공유하고 싶습니다.
솔웅

최근에 올라온 글

최근에 달린 댓글

최근에 받은 트랙백

글 보관함

카테고리


반응형

7. Convolutional Neural Networks — Dive into Deep Learning 1.0.0-beta0 documentation (d2l.ai)

 

7. Convolutional Neural Networks — Dive into Deep Learning 1.0.0-beta0 documentation

 

d2l.ai

 

 

Image data is represented as a two-dimensional grid of pixels, be it monochromatic or in color. Accordingly each pixel corresponds to one or multiple numerical values respectively. So far we ignored this rich structure and treated them as vectors of numbers by flattening the images, irrespective of the spatial relation between pixels. This deeply unsatisfying approach was necessary in order to feed the resulting one-dimensional vectors through a fully connected MLP.

 

이미지 데이터는 단색이든 컬러이든 픽셀의 2차원 그리드로 표현됩니다. 따라서 각 픽셀은 각각 하나 또는 여러 개의 수치에 해당합니다. 지금까지 우리는 이 풍부한 구조를 무시하고 픽셀 간의 공간적 관계에 관계없이 이미지를 flattening 하여 숫자 벡터로 처리했습니다.  fully connected MLP를 통해 resulting one-dimensional vectors를 공급하기 위해서는 매우 만족스럽지 못한 이 접근 방식이 필요했습니다.

 

Because these networks are invariant to the order of the features, we could get similar results regardless of whether we preserve an order corresponding to the spatial structure of the pixels or if we permute the columns of our design matrix before fitting the MLP’s parameters. Preferably, we would leverage our prior knowledge that nearby pixels are typically related to each other, to build efficient models for learning from image data.

 

이러한 네트워크는 features의 순서에 대해 변하지 않기 때문에 픽셀의 공간 구조에 해당하는 순서를 유지하는지 또는 MLP의 매개 변수를 맞추기 전에 디자인 행렬의 열을 치환하는지 여부에 관계없이 유사한 결과를 얻을 수 있습니다. 바람직하게는 주변 픽셀이 일반적으로 서로 관련되어 있다는 사전 지식을 활용하여 이미지 데이터에서 학습하기 위한 효율적인 모델을 구축합니다.

 

This chapter introduces convolutional neural networks (CNNs) (LeCun et al., 1995), a powerful family of neural networks that are designed for precisely this purpose. CNN-based architectures are now ubiquitous in the field of computer vision. For instance, on the Imagnet collection (Deng et al., 2009) it was only the use of convolutional neural networks, in short Convnets that provided significant performance improvements (Krizhevsky et al., 2012).

 

이 장에서는 정확히 이러한 목적을 위해 설계된 강력한 신경망 제품군인 CNN(Convolutional Neural Networks)(LeCun et al., 1995)을 소개합니다. CNN 기반 아키텍처는 이제 컴퓨터 비전 분야에서 유비쿼터스(어디에나 있는, 필수의 것)입니다. 예를 들어, Imagnet 컬렉션(Deng et al., 2009)에서 상당한 성능 향상을 제공한 Convnets에서 컨볼루션 신경망만 사용했습니다(Krizhevsky et al., 2012).

 

Modern CNNs, as they are called colloquially owe their design to inspirations from biology, group theory, and a healthy dose of experimental tinkering. In addition to their sample efficiency in achieving accurate models, CNNs tend to be computationally efficient, both because they require fewer parameters than fully connected architectures and because convolutions are easy to parallelize across GPU cores (Chetlur et al., 2014). Consequently, practitioners often apply CNNs whenever possible, and increasingly they have emerged as credible competitors even on tasks with a one-dimensional sequence structure, such as audio (Abdel-Hamid et al., 2014), text (Kalchbrenner et al., 2014), and time series analysis (LeCun et al., 1995), where recurrent neural networks are conventionally used. Some clever adaptations of CNNs have also brought them to bear on graph-structured data (Kipf and Welling, 2016) and in recommender systems.

 

흔히 불리는 이름인 Modern CNNs은 생물학, 집단 이론 및 healthy dose of experimental tinkering에서 영감을 받아 디자인되었습니다. 정확한 모델을 달성하는 샘플 효율성 외에도 CNN은 완전히 연결된 아키텍처보다 더 적은 매개변수가 필요하고 컨볼루션이 GPU 코어에서 쉽게 병렬화되기 때문에 계산적으로 효율적인 경향이 있습니다(Chetlur et al., 2014). 결과적으로 실무자들은 가능할 때마다 CNN을 적용하는 경우가 많으며 오디오(Abdel-Hamid et al., 2014), 텍스트(Kalchbrenner et al., 2014) 그리고 recurrent neural networks들이 전통적으로 사용 되었던 곳인 time series analysis (LeCun et al., 1995)와 같은 곳들에 1차원 시퀀스 구조의 작업에서도 점점 더 신뢰할 수 있는 경쟁자로 부상하고 있습니다.  CNN의 일부 영리한 적응은 또한 그래프 구조 데이터(Kipf and Welling, 2016)와 추천 시스템에 영향을 미쳤습니다.

 

First, we will dive more deeply into the motivation for convolutional neural networks. This is followed by a walk through the basic operations that comprise the backbone of all convolutional networks. These include the convolutional layers themselves, nitty-gritty details including padding and stride, the pooling layers used to aggregate information across adjacent spatial regions, the use of multiple channels at each layer, and a careful discussion of the structure of modern architectures. We will conclude the chapter with a full working example of LeNet, the first convolutional network successfully deployed, long before the rise of modern deep learning. In the next chapter, we will dive into full implementations of some popular and comparatively recent CNN architectures whose designs represent most of the techniques commonly used by modern practitioners.

 

먼저, 컨볼루션 신경망의 motivation 에 대해 더 깊이 파고들 것입니다. 그런 다음 모든 컨볼루션 네트워크의 중추를 구성하는 기본 작업을 살펴봅니다. 여기에는 컨볼루션 레이어 자체, 패딩 및 스트라이드를 포함한 핵심 세부 정보, 인접한 공간 영역에서 정보를 집계하는 데 사용되는 풀링 레이어, 각 레이어에서 다중 채널 사용 및 현대 아키텍처 구조에 대한 신중한 논의가 포함됩니다. 최신 딥 러닝이 부상하기 오래 전에 성공적으로 배포된 최초의 컨볼루션 네트워크인 LeNet의 전체 작업 예제로 이 장을 마무리할 것입니다. 다음 장에서는 현대 실무자가 일반적으로 사용하는 대부분의 기술을 대표하는 디자인을 가진 인기 있고 비교적 최근의 CNN 아키텍처의 전체 구현에 대해 자세히 알아볼 것입니다.

 

Convolutional Neural Networks (CNN)란? 

 

Convolutional Neural Networks (CNNs) are a class of deep learning models specifically designed for processing structured grid-like data, such as images or time series data. They are widely used in computer vision tasks, including image classification, object detection, and image segmentation.

 

합성곱 신경망(Convolutional Neural Networks, CNNs)은 이미지나 시계열 데이터와 같은 구조적인 격자 형태의 데이터를 처리하기 위해 특별히 설계된 딥러닝 모델의 한 종류입니다. CNN은 이미지 분류, 물체 검출, 이미지 세분화 등의 컴퓨터 비전 작업에서 널리 사용됩니다.

 

The key idea behind CNNs is to exploit the spatial structure of the input data by using convolutional layers. A convolutional layer applies a set of learnable filters (also known as kernels) to the input data, performing a convolution operation. This operation enables the network to automatically learn local patterns or features present in the input.

 

CNN의 핵심 아이디어는 convolutional layers을 사용하여 입력 데이터의 공간적 구조를 활용하는 것입니다. convolutional layers은 학습 가능한 필터(커널) 세트를 입력 데이터에 적용하여 convolution 연산을 수행합니다. 이러한 연산은 네트워크가 입력에 있는 지역적인 패턴이나 특징을 자동으로 학습할 수 있게 해줍니다.

 

CNNs typically consist of multiple layers, including convolutional layers, pooling layers, and fully connected layers.

Convolutional layers extract local features, while pooling layers downsample the feature maps, reducing their spatial dimensions. Finally, fully connected layers process the high-level features and produce the desired outputs, such as class probabilities.

 

CNN은 일반적으로 convolutional layers, pooling layers, fully connected layers 등 여러 계층으로 구성됩니다. Convolutional layers은 local features을 추출하고, pooling layersfeature maps의 다운샘플링을 하여 공간적인 차원을 축소합니다. 마지막으로 fully connected layershigh-level features을 처리하고, 원하는 출력(예: 클래스 확률)을 생성합니다.

 

By leveraging the hierarchical structure of CNNs, these networks can learn complex representations of the input data, automatically capturing relevant features at different levels of abstraction. This makes CNNs highly effective in visual tasks, as they can learn to recognize patterns, shapes, and structures in images, leading to state-of-the-art performance in various computer vision applications.

 

CNN은 계층 구조를 활용하여 입력 데이터의 복잡한 표현을 학습할 수 있으며, 다른 수준의 추상화에서 관련 있는 features 을 자동으로 파악할 수 있습니다. 이를 통해 CNN은 이미지에서 패턴, 형태, 구조를 인식하는 것을 학습하므로, 컴퓨터 비전 분야에서 다양한 응용에 대한 최첨단 성능을 달성할 수 있습니다.

 

https://youtu.be/9Cu2UfNO-gw

 

* CNN의 목표는 사진이 무엇인지 맞추는 것

* 너무 복잡한 이미지(Layer가 너무 많은 이미지)는 CNN으로 처리하기 어려웠으나 ReLU로 성능을 높였고 Dropout으로 training data에만 맞는 overfitting을 완화하여 CNN의 한계를 극복해서 많이 사용할 수 있게 됨

* Convolution : 부분들의 특징을 추출하는 것 (예: 새의 경우 눈, 부리, 날개, 깃털 등의 특징을 추출함)

* feature map : Convolution 결과를 기록한 것

* 일반 신경망은 모든 노드가 연결돼 있고 그 연결부위에 가중치를 주면서 학습함. 반면에 CNN은 고정된 연결이 없고 Convolution과정을 통해 출력을 계산 함. CNN은 필터의 가중치를 학습함. 

* filter : pattern을 추출 함. (필터가 다르면 패턴도 달라질 수있음)

학습 과정 - Convolution으로 부분들의 특징을 추출함 (filter의 갯수 만큼 feature map이 나옴) - Max Pooling으로 feature map의 크기를 줄임 (가장 큰 값만 추출하여 출력을 작게 만드는 방법) - 이렇게 Convolution과 Max Pooling을 하나의 단위로 하여 여러 층으로 깊게 쌓아 올림 - Convolution과 Max Pooling의 layer가 끝나면 고차원적인 패턴이 담긴 feature map이 나옴 - 이것을 fully connected layer에 붙여 feature map을 사진의 class로 최종 분류 함

 

 

https://youtu.be/ggBQj1NXUEg

* Overfitting : training data에만 최적합. test data에는 맞지 않음. (예: training에만 쓰였던 개만 개로 인식) generalization gap이 큰 경우.

* Fully connected layer : overfitting의 문제 야기할 수 있음, 계산이 너무 많아짐. 비효율적

* 위 두 문제 비효율성과 overfitting을 해결함으로서 CNN이 널리 쓰일 수 있었음

* Convolusion : 부분을 뒤집어서(convolusion) 필터를 shift시키면서 곱한 값을 더한 값들을 추출함.

 

https://youtu.be/YRhxdVk_sIs

Convolutional Calculation

 

https://youtu.be/QzY57FaENXg

Hidden Layer, Convolutional Layer, Filters, 첫번째 레이어에서는 가장 부분적으로 분석하고 레이어가 깊어 질 수록 점 점 더 크고 전체적인 분석이 가능하게 됨.

 

CNN - 음성인식, 이미지 처리

입력 이미지에서 features를 추출해서 그 이미지가 속하는 클래스로 분류 함.

Feature Learning 단계와 Classification 단계가 있음

 

https://youtu.be/BfzUCEXmOm0

 

Feature Learning : Convolution * ReLU -> Pooling (반드시 해야 되는 것은 아님) -> Convolution * ReLU -> Pooling...

Classification : Flatten -> Fully Connected -> Softmax

 

기존 신경망 : Affine * ReLU -> Affine * ReLU .... -> Softmax 로 Classification

CNN : Convolution * ReLU * (Pooling,Dropout)-> Convolution * ReLU * Pooling .... -> Softmax 로 Classification

 

CNN - 부분 부분을 나누어서 관계를 지음으로서 특징을 파악하고 Layer가 지날 수록 점점 더 큰 부분으로 확대한다.

중간에 Bias 넣어 줌

Padding 처리 : 입력 데이터와 출력데이터의 크기를 맞추기 위함. 행렬 주변을 모두 0으로 채운 후 계산. 

Stride : 필터를 적용하는 위치의 간격 (1칸, 2칸 ...)

필터(커널)의 크기와 Stride의 크기에 따라 출력행렬의 크기가 달라질 수 있다.

3차원 이미지 데이터 -> 필터도 이미지와 같은 채널 수를 가지고 있어야 함

Pooling : 가로 세로 방향의 공간을 줄이는 연산 (행렬의 크기를 줄임) , 최대값만 가져 감 (특징을 강조하게 됨)

Fully Connected Layer : 추출된 features 값을 기존 neural network에 넣어서 이미지를 분류함

Flatten - 추출된 features가 2차원 자료이므로 기존의 neural network에 전달하기 위해서 1차원 자료로 바꿔 줌

Softmax activation function : 

 

 

 

 

 

 

 

반응형