공부방/Upstage AI Lab 4기

[CV 대회] 끄적

Eddie_D 2024. 10. 29. 13:21

해보면 좋을 것

1. augmentation

2. seed 앙상블

 

Augraphy

문서 이미지를 augmentation 할 때 쓸 수 있음. 무한복사

-> 클린한 학습데이터를 더럽게 aug를 많이해서 학습을 시키면 어떨까?? (테스트데이터는 이미 더티함)

https://github.com/sparkfish/augraphy

 

GitHub - sparkfish/augraphy: Augmentation pipeline for rendering synthetic paper printing, faxing, scanning and copy machine pro

Augmentation pipeline for rendering synthetic paper printing, faxing, scanning and copy machine processes - sparkfish/augraphy

github.com

 

Ensemble

여러 방식으로 시도해보기! 모델 앙상블(ResNet, VGG, Effenet, transformer 등등), 데이터 앙상블(폴드 나눠서), 시드 앙상블(???), 이미지 사이즈 조절해가면서 앙상블, 

시드 앙상블: 신경망 가중치들이 seed 값에 따라 다르게 초기화됨. 이걸 바꿔가면서 해보라는 말인듯. (실제 프로젝트에서 자주 사용되는 기법이라고 클로드 설명)
시드값이 달라지면 결과가 다르게 나오는 이유: 

 

  • 모델 초기화: 신경망의 가중치(weight)들이 seed 값에 따라 다르게 초기화됩니다
  • 데이터 샘플링: 미니배치를 구성할 때 데이터가 다르게 섞입니다
  • 드롭아웃 등 랜덤성이 있는 레이어의 동작이 달라집니다

seed 앙상블하는 법: 

  1. 동일한 모델 아키텍처로 여러 개의 모델을 학습시킵니다
  2. 각 모델마다 다른 seed 값을 사용합니다
  3. 추론 시에는 각 모델의 예측값을 평균내서 최종 예측을 만듭니다

 

더보기

참고)

# seed 설정 예시
import torch
import numpy as np
import random

def set_seed(seed):
    torch.manual_seed(seed)
    torch.cuda.manual_seed_all(seed)
    np.random.seed(seed)
    random.seed(seed)

# 서로 다른 seed로 여러 모델 학습
seeds = [42, 123, 555, 789, 999]
models = []

for seed in seeds:
    set_seed(seed)
    model = YourModel()  # 모델 정의
    # 모델 학습
    train_model(model)
    models.append(model)

# 추론 시 앙상블
def ensemble_predict(models, x):
    predictions = []
    for model in models:
        pred = model(x)
        predictions.append(pred)
    
    # 예측값들의 평균 계산
    final_pred = torch.mean(torch.stack(predictions), dim=0)
    return final_pred