yolo 학습

승주·2024년 8월 17일

1차

# 학습 파라미터 설정
epochs = 100  # 에폭 수
batch_size = 32  # 배치 크기
learning_rate = 0.0001  # 학습률
patience = 25

# 데이터셋 경로 설정
data = r'/content/Data/data.yaml'  
timestamp= datetime.datetime.now().strftime('%y%m%d_%H%M%S')

sys.stdout = open(f'train_log_{timestamp}.txt', 'w')

# 학습 시작
model.train(
    data=data,
    epochs=epochs,
    batch=batch_size,
    lr0=learning_rate,
    patience = patience,
    imgsz=640,
    workers=4,
    project='fruit_hand_detection',  # 프로젝트 이름
    name='exp',  # 실험 이름
    optimizer='Adam',
    augment=True,  # 기본 augment ->test시 
    auto_augment = None,
    mosaic=0.6,  # 모자이크 활성화
    erasing = 0.3,
    copy_paste = 0.3,
    # mixup=0.3,  # 믹스업 활성화
    # cutout=0.3,  # 컷아웃 활성화 (0.5는 컷아웃 강도)
    verbose=True,
    save_period = 5
)

sys.stdout.close()
train: Scanning /content/Data/train/labels.cache... 55830 images, 0 backgrounds, 0 corrupt: 100%|██████████| 55830/55830 [00:00<?, ?it/s]
/usr/lib/python3.10/multiprocessing/popen_fork.py:66: RuntimeWarning: os.fork() was called. os.fork() is incompatible with multithreaded code, and JAX is multithreaded, so this will likely lead to a deadlock.
  self.pid = os.fork()
val: Scanning /content/Data/val/labels.cache... 3000 images, 0 backgrounds, 0 corrupt: 100%|██████████| 3000/3000 [00:00<?, ?it/s]
      1/100      28.2G     0.2375     0.3536     0.5691      0.932         67        640: 100%|██████████| 1745/1745 [10:07<00:00,  2.87it/s]
                 Class     Images  Instances      Box(P          R      mAP50  mAP50-95)     Mask(P          R      mAP50  mAP50-95): 100%|██████████| 47/47 [00:23<00:00,  1.99it/s]
      2/100      15.6G     0.2097     0.2749     0.4257     0.9136         53        640: 100%|██████████| 1745/1745 [09:54<00:00,  2.94it/s]
                 Class     Images  Instances      Box(P          R      mAP50  mAP50-95)     Mask(P          R      mAP50  mAP50-95): 100%|██████████| 47/47 [00:22<00:00,  2.08it/s]
      3/100      15.6G     0.1937     0.2497     0.3828      0.906         52        640: 100%|██████████| 1745/1745 [09:38<00:00,  3.02it/s]
                 Class     Images  Instances      Box(P          R      mAP50  mAP50-95)     Mask(P          R      mAP50  mAP50-95): 100%|██████████| 47/47 [00:22<00:00,  2.07it/s]
      4/100      15.7G     0.1866     0.2381     0.3591     0.9039         40        640: 100%|██████████| 1745/1745 [09:38<00:00,  3.02it/s]
                 Class     Images  Instances      Box(P          R      mAP50  mAP50-95)     Mask(P          R      mAP50  mAP50-95): 100%|██████████| 47/47 [00:22<00:00,  2.06it/s]
      5/100      15.6G     0.1804     0.2309     0.3408     0.9001         52        640: 100%|██████████| 1745/1745 [09:38<00:00,  3.02it/s]
                 Class     Images  Instances      Box(P          R      mAP50  mAP50-95)     Mask(P          R      mAP50  mAP50-95): 100%|██████████| 47/47 [00:22<00:00,  2.06it/s]
      6/100      15.9G     0.1753     0.2231     0.3284     0.8976         60        640: 100%|██████████| 1745/1745 [09:38<00:00,  3.02it/s]
                 Class     Images  Instances      Box(P          R      mAP50  mAP50-95)     Mask(P          R      mAP50  mAP50-95): 100%|██████████| 47/47 [00:22<00:00,  2.07it/s]
      7/100      15.6G      0.172     0.2206     0.3174     0.8964         54        640: 100%|██████████| 1745/1745 [09:39<00:00,  3.01it/s]
                 Class     Images  Instances      Box(P          R      mAP50  mAP50-95)     Mask(P          R      mAP50  mAP50-95): 100%|██████████| 47/47 [00:22<00:00,  2.08it/s]
      8/100      15.7G     0.1691     0.2148     0.3099     0.8954         50        640: 100%|██████████| 1745/1745 [09:38<00:00,  3.02it/s]

Class: 모든 클래스에 대한 성능을 평균한 결과
Images: 클래스별로 평가된 이미지 수
Instances: 클래스별로 탐지된 객체 인스턴스 수
Box(P): 바운딩 박스의 정밀도
Box(R): 바운딩 박스의 재현율
Box(mAP50): IoU가 0.5일 때의 평균 정밀도
Box(mAP50-95): IoU가 0.5에서 0.95까지 변화할 때의 평균 정밀도

  • 학습 잘 안되고 있는 줄 알고 날려버림 ㅠㅠㅠ

2차

수정사항

  1. mosaic = 0.5
  2. erasing, copy_pase= 0.4
  3. lr = 0.0005
  4. AdamW
# 학습 파라미터 설정
epochs = 100  # 에폭 수
batch_size = 32  # 배치 크기
learning_rate = 0.0005  # 학습률
patience = 25

# 학습 시작
model.train(
    data=data,
    epochs=epochs,
    batch=batch_size,
    lr0=learning_rate,
    patience = patience,
    imgsz=640,
    workers=4,
    project='fruit_hand_detection',  # 프로젝트 이름
    name='exp_2',  # 실험 이름
    optimizer='AdamW',
    augment=True,  # 기본 augment ->test시
    mosaic=0.5,  # 모자이크 활성화
    erasing = 0.3,
    copy_paste = 0.3,
    # mixup=0.3,  # 믹스업 활성화
    # cutout=0.3,  # 컷아웃 활성화 (0.5는 컷아웃 강도)
    # verbose=True,
    save_period = 5
)

수정 취소

  • patience =10 최대한 학습 시키기 위해서 25로 유지
  • batch = 64 로 했다가, 오히려 loss가 너무 높게 나와서 줄임



  1. exp
# train

from ultralytics import YOLO
import sys
import datetime

# 모델 로드
model = YOLO('models/yolov8m-seg.pt')

# 학습 파라미터 설정
epochs = 100  # 에폭 수
batch_size = 32  # 배치 크기
learning_rate = 0.0005  # 학습률
patience = 25

# 데이터셋 경로 설정
data = r'/content/Data/data.yaml'
timestamp= datetime.datetime.now().strftime('%y%m%d_%H%M%S')

sys.stdout = open(f'train_log_{timestamp}.txt', 'w')

# 학습 시작
model.train(
    data=data,
    epochs=epochs,
    batch=batch_size,
    lr0=learning_rate,
    patience = patience,
    imgsz=640,
    workers=4,
    project='fruit_hand_detection',  # 프로젝트 이름
    name='exp',  # 실험 이름
    optimizer='AdamW',
    # augment=True,  # 기본 augment ->test시
    # mosaic=0.5,  # 모자이크 활성화
    # erasing = 0.3,
    # copy_paste = 0.3,
    # mixup=0.3,  # 믹스업 활성화
    # cutout=0.3,  # 컷아웃 활성화 (0.5는 컷아웃 강도)
    # verbose=True,
    save_period = 5
)

sys.stdout.close()

문제

  1. persimmon을 hallabong으로 인식

  2. 정확도 낮고 불안정

erasing , mosaic 활용

0개의 댓글