C.W.K.
Stream
Lesson 06 of 06 · published

실전 — Object detection pipeline

~8 min · keras-cv

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

track 을 한데 모으기

이게 capstone 이야: 앞 다섯 lesson 의 전부 — backbone, detection head, augmentation, from_preset 관용구 — 가 돌아가는 pipeline 으로 조립된 거. 아래 형태가 앞으로 만질 모든 detection 문제에서 재사용할 모양이고, dataset 이랑 class 목록만 갈아끼우면 돼.

두 반쪽: inference 와 fine-tuning

inference 가 쉬운 반쪽 (첫 Code block): COCO-pretrained detector 로드, 이미지를 model 기대 size 로 resize, batch, predict 호출, box/class/confidence 읽기. 이것만으로도 COCO 80 class 에 대해 쓸 만한 object detector 야.

'실전' 이라는 이름값 하는 반쪽은 *자기 class 로 fine-tune* (둘째 Code block). 레시피는 track 모든 lesson 이 암시한 그거 — pretrained backbone 으로 detector 로드, backbone freeze, *네* class 수에 맞춘 head 부착, annotation 된 data 로 학습. backbone 이 이미 볼 줄 알기 때문에, 처음부터 학습하는 것보다 훨씬 적은 data 와 compute 면 돼 — 라벨링된 이미지 몇백 장이면 쓸 만한 prototype 까지.

솔직한 결론: model 코드는 작은 부분이야. production detection 의 skill ceiling 은 architecture 가 아니라 data 야. 깨끗한 annotation, 맞는 box 포맷, 멀쩡한 train/val split, precision/recall 필요에 맞춘 confidence threshold — 이게 어느 YOLO size 골랐냐보다 더 중요해.

Code

inference: YOLOV8 로드 + 이미지 한 장 detection·python
import keras_cv

# Load pretrained YOLOV8
model = keras_cv.models.YOLOV8Detector.from_preset(
    "yolo_v8_m_coco",
)

# Prepare image
image = keras.utils.load_img("photo.jpg", target_size=(640, 640))
image_array = keras.utils.img_to_array(image)
image_batch = keras.ops.expand_dims(image_array, axis=0)

# Run detection
predictions = model.predict(image_batch)
# Process bounding boxes, classes, and confidence scores
fine-tuning: 내 class 수에 맞춘 detection head·python
# Start from a pretrained backbone, new head for YOUR classes
detector = keras_cv.models.YOLOV8Detector.from_preset(
    "yolo_v8_s_backbone_coco",   # backbone weights only
    num_classes=len(my_class_names),
    bounding_box_format="xywh",  # MUST match your dataset
)

detector.compile(
    optimizer=keras.optimizers.Adam(1e-4),
    box_loss="ciou",
    classification_loss="binary_crossentropy",
)
detector.fit(train_ds, validation_data=val_ds, epochs=20)

# Persist and reload — same model, no extra glue
detector.save("my_detector.keras")
reloaded = keras.models.load_model("my_detector.keras")

External links

Exercise

작은 detection dataset 골라 (또는 Label Studio 같은 도구로 ~50 이미지 직접 annotate). YOLOv8s fine-tune: bounding_box_format 정확히 설정, 처음 몇 epoch backbone freeze 후 unfreeze. mAP ≥0.4 목표 (작은 dataset 은 noisy — 낮은 게 아니라 현실적인 기준). .save("...keras") 로 저장, 새 process 에서 reload, inference 여전히 되는지 확인. mAP 를 제일 많이 올린 단일 변경을 적어 — hyperparameter 아니라 data 였을 확률 높아.
Hint
mAP 가 0 근처면 learning rate 보다 box 포맷이나 label→class index 매핑부터 의심. training batch 몇 개를 box 그려서 시각화 — 입력의 box 가 틀렸으면 model 은 애초에 기회가 없었어.

Progress

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

댓글 0

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

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