본문 바로가기
C.W.K.
Stream
Lesson 07 of 07 · published

실전 — EfficientNet 미세 조정

~8 min · transfer

Level 0Keras 도제
0 XP0/97 lessons0/20 achievements
0/120 XP to next level120 XP to go0% complete

전체 흐름을 한 스크립트에 담기

이 예제는 트랙의 절차를 새 이미지 분류 프로젝트에서 재사용할 수 있는 흐름으로 묶어. 고정한 EfficientNetV2S 백본을 불러와 작은 출력 헤드를 붙이고 먼저 헤드만 학습해. 이어서 백본의 위쪽 레이어를 풀고 1e-5의 학습률로 미세 조정해. 아래 코드는 두 단계를 모두 포함한 완성된 프로그램이야.

출력 헤드의 선택을 살펴봐

이 출력 헤드는 기본 특징 추출 예제보다 조금 더 표현력이 있어. GlobalAveragePooling2D 뒤와 최종 분류기 앞에 Dense(128, relu) 병목 레이어를 두어 백본 특징을 내 클래스에 맞게 다시 조합할 여지를 줘. Dropout(0.3)은 작은 자료에서 과적합을 줄여. 마지막 Dense(5, softmax)는 실제 클래스 수에 맞게 바꾸고, 다른 백본 프리셋이 별도 해상도를 요구한다면 input_shape도 조정해.

템플릿을 실제 프로젝트로 확장하기

실제 과제로 옮길 때 주로 바뀌는 것은 데이터 파이프라인인 train_dsval_ds, 그리고 두 단계의 에포크 수야. 백본 고정과 해제, 두 번의 컴파일, 학습률을 100배 낮추는 흐름은 그대로 유지할 수 있어. 반복 가능한 절차를 템플릿으로 만들면 전이 학습의 기계적인 부분보다 자료와 평가지표에 집중할 수 있어.

Code

전체 전이 학습 파이프라인(특징 추출과 미세 조정)·python
import keras
from keras import layers

# Load pretrained EfficientNetV2S
base = keras.applications.EfficientNetV2S(
    weights="imagenet", include_top=False,
    input_shape=(224, 224, 3),
)
base.trainable = False

# Build model
inputs = keras.Input(shape=(224, 224, 3))
x = base(inputs, training=False)
x = layers.GlobalAveragePooling2D()(x)
x = layers.Dense(128, activation="relu")(x)
x = layers.Dropout(0.3)(x)
outputs = layers.Dense(5, activation="softmax")(x)
model = keras.Model(inputs, outputs)

# Phase 1: Feature extraction
model.compile(optimizer="adam", loss="categorical_crossentropy", metrics=["accuracy"])
model.fit(train_ds, epochs=10, validation_data=val_ds)

# Phase 2: Fine-tuning
base.trainable = True
for layer in base.layers[:-20]:
    layer.trainable = False
model.compile(optimizer=keras.optimizers.Adam(1e-5), loss="categorical_crossentropy", metrics=["accuracy"])
model.fit(train_ds, epochs=20, validation_data=val_ds)

External links

Exercise

Oxford Flowers나 Food-101 같은 공개 데이터셋을 골라 위 EfficientNet 전이 학습 파이프라인을 처음부터 끝까지 구현해. 검증 정확도 85% 이상을 달성하고 스크립트를 재사용 가능한 전이 학습 템플릿으로 저장해.

Progress

Progress is local-only — sign in to sync across devices.
이 페이지에서 버그를 발견하셨거나 피드백이 있으세요?문제 신고

댓글 0

🔔 답글 알림 (로그인 필요)
로그인댓글을 남기려면 로그인해 주세요.

아직 댓글이 없어요. 첫 댓글을 남겨보세요.