AI 웹 개발 과정/팀 프로젝트

팀 프로젝트 03 : 이미지 인식 - 3일차 / VGG16 모델 학습

만 기 2022. 5. 20. 23:06

 

 

CNN 모델 학습 : VGG16

 

간단 설명 :3X3의 작은 사이즈의 필터를 고정으로 사용해서 레이어를 깊게 만든다.

장점 : 필터 사이즈가 작아서 파라메터 개수가 줄어든다 ⇒ 학습효율성, 정규화할때 이점

단점 : 레이어가 깊어 메모리 차지를 많이하고 학습속도가 느리다.

 

- cnn 미세조정 가이드 : https://blog.keras.io/building-powerful-image-classification-models-using-very-little-data.html

 

Building powerful image classification models using very little data

Sun 05 June 2016 By Francois Chollet In Tutorials. Note: this post was originally written in June 2016. It is now very outdated. Please see this guide to fine-tuning for an up-to-date alternative, or check out chapter 8 of my book "Deep Learning with Pytho

blog.keras.io

 

- 이미지 증강

train_datagen = ImageDataGenerator(
  rescale=1./255, # 일반화
  rotation_range=10, # 랜덤하게 이미지를 회전 (단위: 도, 0-180)
  zoom_range=0.2, # 랜덤하게 이미지 확대 (%)
  width_shift_range=0.2,  # 랜덤하게 이미지를 수평으로 이동 (%)
  height_shift_range=0.2,  # 랜덤하게 이미지를 수직으로 이동 (%)
  horizontal_flip=True # 랜덤하게 이미지를 수평으로 뒤집기
)

test_datagen = ImageDataGenerator(
  rescale=1./255 # 일반화
)

 

- VGG16 학습

from tensorflow.keras.applications.vgg16 import VGG16
from tensorflow.keras.regularizers import l2 

input = Input(shape=(224, 224, 3))

base_model = VGG16(weights='imagenet', include_top=False, input_tensor=input, pooling='max')

x = base_model.output
output = Dense(8, activation='softmax', kernel_regularizer=l2(.001))(x)

model = Model(inputs=base_model.input, outputs=output)

opt = Adam(lr=.0001, beta_1=.99, beta_2=.999, epsilon=1e-8)
# opt = SGD(lr=.0001)

model.compile(loss='categorical_crossentropy', optimizer=opt, metrics=['acc'])

model.summary()

 

- 학습 결과 그래프