When will you grow up?

Transfer Learning 본문

02. Study/Deep Learning

Transfer Learning

미카이 2017. 11. 28. 01:57

Transfer Learning이란?

- 일반적으로 우리가 사용하는 Deep Learning에서 여러가지 문제점이 존재할 수 있다.

흔한경우를 보면, 학습시켜야할 데이터수가 적을수도 있고, 충분한 학습을 위한 서버컴퓨터가 없을수도 있다. 여러가지 이유가 존재하겠지만,

그래서 일반적으로 VGG,ResNet,gooGleNet등 이미 이러한 사전에 학습이 완료된 모델(Pre-Training Model)을 가지고 우리가 원하는 학습에 미세 조정 즉, 작은변화를 이용하여 학습시키는 방법이 Transfer Learning이다. 

이야기하자면, 이미학습된 weight들을 transfer(전송)하여 자신의 model에 맞게 학습을 시키는 방법입니다.



Keras에서는 이미 학습된 주요 모델들을 간편하게 제공합니다.


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
# 필요한 모듈 import
import time
import matplotlib.pyplot as plt
import numpy as np
np.random.seed(2017
from keras.applications.vgg19 import VGG19
from keras.applications.vgg19 import preprocess_input, decode_predictions
from keras.preprocessing import image
from keras.models import Model
import cv2
 
# vgg모델 불러오기
model = VGG19(weights='imagenet', include_top=True)
# model layer 
model.summary()
cs


                                      [model.summary()]



학습된 VGGModel은 ImageNet 기반으로 학습이 된 Model이므로, output이 총 1000개의 class를 구분하는데, 

우리가 사용하는 모델에 맞게 output으로 맞게 분류 할 것이다.


또한 사전에 훈련 된 네트워크는 잘 학습이 되었다고 가정을 하기 때문에, 우리는 너무 많이 가중치를 수정하기를 원하지 않을 것이다.


모델을 fine-turing 방법은 크게 3가지 방법이 있다.


1. Feature extraction

2. pre-trained model을 모델 구조를 이용

3. 다른 레이어를 고정시키고 일부분 layer를 조정


추후 작성 예정...


reference

https://towardsdatascience.com/transfer-learning-using-keras-d804b2e04ef8

https://deeplearningsandbox.com/how-to-use-transfer-learning-and-fine-tuning-in-keras-and-tensorflow-to-build-an-image-recognition-94b0b02444f2

https://www.analyticsvidhya.com/blog/2017/06/transfer-learning-the-art-of-fine-tuning-a-pre-trained-model/



Comments