본문 바로가기
대학생활/수업

게임인공지능 14주차 - 데이터 증강

by se.jeon 2023. 12. 5.
728x90
반응형

CNN 분석

- CNN으로 검증 정확도를 높임

- 여전히 트레이닝 정확도가 검증 정확도보다 높음

 

CNN 솔루션

- 정제 데이터가 더 나은 예시를 제공

- 데이터세트의 다양성이 모델의 일반화에 도움이 됨

 

데이터 증강 (Data Augmentation)

데이터를 증강하여 추가 예시를 제공하는 방법

- 이미지 반전 (Image Flipping)

- 이미지 회전 (Image Roatation)

- 이미지 확대/축소 (Image Zooming)

- 이미지 너비 및 높이 이동

- 이미지 밝기 (Brightness)

- 이미지 채널 전환 (Channel Shifting)

 

증강 처리 과정

- 크기 조정

- 회색조

- '배치'

 

데이터 증강 클래스 : ImageDataGenerator

flow_from_directory
- 폴더 형태로 된 데이터를 바로 가져와서 사용 가능
- 무작위 샘플에 대해 트레이닝 가능

flow method
- 증강 데이터의 배치 생성(iterator)
- img_iter = datagen.flow(x_train, y_train, batch_size=batch_size)

데이터 증강 설정
from tensorflow.keras.preprocessing.image import ImageDataGenerator

datagen = ImageDataGenerator(
    rotation_range=10, # randomly rotate images in the range (degrees, 0 to 180)
    zoom_range=0.1, # Randomly zoom image
    width_shift_range=0.1, # randomly shift images horizontally (fraction of total width)
    height_shift_range=0.1, # randomly shift images vertically (fraction of total height)
    horizontal_flip=True, # randomly flip images horizontally
    vertical_flip=False, # Don't randomly flip images vertically
)
https://www.tensorfl

 

https://www.tensorflow.org/api_docs/python/tf/keras/preprocessing/image/ImageDataGenerator

 

tf.keras.preprocessing.image.ImageDataGenerator  |  TensorFlow v2.14.0

Generate batches of tensor image data with real-time data augmentation.

www.tensorflow.org

 

증강 데이터를 이용한 학습

트레이닝 데이터세트를 생성기에 맞추기
datagen.fit(x_train)

• 증강 데이터세트로 트레이닝
batch_size = 32
img_iter = datagen.flow(x_train, y_train, batch_size=batch_size)

model.fit(img_iter,
    epochs=20,
    steps_per_epoch=len(x_train)/batch_size,
    validation_data=(x_valid, y_valid)
    )

 

실습

- 데이터 증강 방법

- 미국 수화 데이터를 증강하여 학습

- 학습결과 분석

728x90
반응형