1. What is Computer Vision ?
컴퓨터 비전(Computer Vision)은 기계의 시각에 해당하는 부분을 연구하는 컴퓨터 과학의 최신 연구 분야중 하나이다. 공학적인 관점에서, 컴퓨터 비전은 인간의 시각이 할 수 있는 몇가지 일을 수행하는 자율적인 시스템을 만드는 것을 목표로 한다. 그리고 과학 관점에서는 컴퓨터 비전은 이미지에서 정보를 추출하는 인공 시스템 관련 이론에 관여한다.
Neural Network는 인간이 시각을 통해 얻는 정보를 충분히 비슷하게 이해할 수 있다. 이러한 작업에 가장 적합한 Neural Netork는 합성곱 신경망(Convolutional Neural Network; CNN)이다.
합성곱 신경망은 시각적 영상을 분석하는 데 사용되는 다층의 feed-forward 적인 인공신경망의 한 종류이다. 필터링 기법을 인공신경망에 적용하여 이미지를 효과적으로 처리할 수 있는 심층 신경망 기법으로 행렬로 표현된 필터의 각 요소가 데이터 처리에 적합하도록 자동으로 학습하는 과정을 통해 이미지를 분류하는 기법이다.
2. The Convolutional Classifer
이미지 분류에 활용되는 합성곱 신경망(CNN)은 convolutional base와 dense head로 구성된다. convolutional base는 이미지에서 특징(feature)를 추출하기 위해 사용된다. convolution 연산에 사용되는 layer로 구성되지만 다른 종류의 layer도 포함한다(추출기).
dense head는 이미지의 class를 결정하기 위해 사용된다(분류기). Neural Network에서 사용되는 dense layer로 구성되지만 dropout과 같은 다른 layer도 포함한다.
3. Training the Classifier
Convolutional Classifier은 훈련을 위해 두가지 단계를 거쳐가게 된다.
1. 어떤 변수들을 이미지에서 추출할 것인지(base 단계)
2. 변수들을 통해 어떤 클래스에 분류할 것인지(head 단계)
요즘 합성곱 신경망은 미리 훈련된 모델의 base를 사용하게 된다. 미리 훈련된 base를 통과하고 훈련되지 않는 head에 데이터를 넘기게 된다. 미리 훈련된 모델을 사용하는 기술을 transfer learning이라고 한다.
전이 학습(Transfer learning)
사전 훈련된 모델은 이전에 대규모 데이터셋에서 훈련된 저장된 네트워크로, 일반적으로 대규모 이미지 분류 작업에서 훈련된 것이다.
4. Examples
# Define Pretrained Base
# We'll use VGG16 model
pretrained_base = tf.Keras.models.load_model('../input/cv-course-models/cv-course-models/vgg16-pretrained-base',
)
# Attach Head
from tensorflow import keras
from tensorflow.keras import layers
model = keras.Sequential([
pretrained_base,
layers.Flatten(),
layers.Dense(6, activation = 'relu'),
layers.Dense(1, activation = 'sigmoid')
])
# Train model
model.compile(
optimizer = 'adam',
loss = 'binary_crossentropy',
metrics = ['binary_accuracy'],
)
history = model.fit(
ds_train,
validation_data = ds_valid,
epoch = 30,
verbose = 0,
)
4. Exercise : The Convolutional Classifier
Step 1 : Attach Head
from tensorflow import keras
from tensorflow.keras import layers
model = keras.Sequential([
pretrained_base,
layers.Flatten(),
# YOUR CODE HERE. Attach a head of dense layers.
layers.Dense(units = 6, activation = 'relu'),
layers.Dense(units = 1, activation = 'sigmoid')
])
Step 2 : Train
optimizer = tf.keras.optimizers.Adam(epsilon=0.01)
model.compile(
optimizer=optimizer,
loss = 'binary_crossentropy',
metrics=['binary_accuracy'],
)
Source of the course : https://www.kaggle.com/code/ryanholbrook/the-convolutional-classifier/tutorial
The Convolutional Classifier
Explore and run machine learning code with Kaggle Notebooks | Using data from multiple data sources
www.kaggle.com
'Course > [Kaggle] Data Science' 카테고리의 다른 글
[DL] Convolution and ReLU (0) | 2022.03.23 |
---|---|
[DL] Binary Classification (0) | 2022.03.02 |
[DL] Dropout and Batch Normalization (0) | 2022.03.02 |
[DL] Overfitting and Underfitting (0) | 2022.03.01 |
[DL] Stochastic Gradient Descent (0) | 2022.03.01 |