현실에서 데이터셋으로 사용하는 이미지 데이터는 결국 사람이 구도를 잡고 찍은 데이터이다. 유행에 따라 구도가 변할 수 있고 예쁜 사진을 찍기 위해 구도를 잡는다.
이렇게 사람이 찍은 이미지 데이터는 결국 편향(biased)된 데이터다. 편향된 데이터는 현실 세계 데이터 (real data)를 모두 반영할 수 없다.
따라서 학습시킨적 없는 데이터가 모델에게 주어진 경우 기능이 제대로 동작하지 않을 수 있다.
Data Augmentation을 적용해 real data를 가능한 커버할 수 있도록 한다면 모델의 성능은 더욱 증가할 것이다.
이미지 데이터에 적용할 수 있는 augmentation 기법은 다양하다.
def brightness_augmentation(img):
result = img.copy()
result[:,:,0] = result[:,:,0] + 20
result[:,:,1] = result[:,:,1] + 20
result[:,:,2] = result[:,:,2] + 20
result[:,:,0][result[:,:,0]>255] = 255
result[:,:,1][result[:,:,1]>255] = 255
result[:,:,2][result[:,:,2]>255] = 255
return result
def rotate_img(img):
return cv2.rotate(img, cv2.ROTATE_90_CLOCKWISE)
def flip_img (img):
return cv2.rotate(img, cv2.ROTATE_180)
def crop_img(img):
y_start = 500
crop_y_size = 1500
x_start = 500
crop_x_size = 1500
img_cropped = img[y_start : y_start + crop_y_size, x_start : x_start + crop_x_size, :]
return img_cropped