TensorFlow 튜토리얼 — 전이 학습과 파인튜닝

TensorFlow 튜토리얼 — 전이 학습과 파인튜닝

TensorFlow 전이 학습 튜토리얼은 MobileNetV2 기반으로 두 단계 전략을 다뤄요.

1단계: 특징 추출(Feature Extraction)

  • 사전 학습 모델을 로드하되 include_top=False 로 분류 헤드를 빼고, 가중치를 고정한다.
  • 사전 학습된 특징 추출기 위에 새 분류 레이어(tf.keras.layers.Dense)를 쌓는다.
  • 데이터 증강과 함께 모델 전체를 학습시켜, 동결된 특징 위에서 분류기를 빠르게 맞춘다.
base_model = tf.keras.applications.MobileNetV2(input_shape=(160,160,3),
                                               include_top=False, weights='imagenet')
base_model.trainable = False
global_average_layer = tf.keras.layers.GlobalAveragePooling2D()
prediction_layer = tf.keras.layers.Dense(10)
model = tf.keras.Sequential([base_model, global_average_layer, prediction_layer])

2단계: 파인튜닝(Fine-Tuning)

  • 특징 추출기를 동결 해제(base_model.trainable=True)해, 전체 모델을 낮은 학습률로 다시 학습시켜 사전 학습 특징을 우리 데이터에 맞게 다듬는다.
  • 파인튜닝이 특징 추출보다 더 높은 정확도를 내지만, 학습률·과적합 관리가 필요하다.

더 알아보기