Augmentation 이용한 이미지 증강 작업(google colab)

밴루·2021년 8월 2일
0
post-thumbnail

데이터를 학습시키기 위해 데이터셋을 만드는 과정에서 이미지 데이터 수가 부족한 상황이 나타난다.

또 이미지 증강을 통해 다양한 관점에서 학습시키는 과정을 거쳐 좀 더 정확하고 다양한 학습이 가능하다.

Augmentation 라이브러리를 통해 간단한 이미지 증강 작업을 공부해보았다.




-Augmentation 라이브러리

파이썬 라이브러리로 회전, 확대, 왜곡, 반전 등의 함수를 사용할 수 있다.


1. colab 파일 생성

구글 드라이브에서 새로만들기 -> 더보기 -> google Colaboratory 로 파일을 생성해준다.



런타임 연결 및 구글 드라이브 연동
런타임과 구글 드라이브 연동을 해준다.

2.라이브러리 다운


pip install Augmentor

Colab에 Augmentor 라이브러리를 다운받아준다.

이미 다운 받았어서 결과는 다르게 나올 것이다.



3. 코드 입력


 import Augmentor


#증강 시킬 이미지 폴더 경로
img = Augmentor.Pipeline("/content/drive/MyDrive/study/augmentation/test")


# 좌우 반전
#img.flip_left_right(probability=1.0) 


# 상하 반전
#img.flip_top_bottom(probability=1.0)


#모퉁이 왜곡
#img.skew_corner(probability=1.0)


#회전&크롭
#img.rotate_without_crop(probability=1, max_left_rotation=0.8, max_right_rotation=0.8, expand=False, fillcolor=None)


# 왜곡
# img.random_distortion(probability=1, grid_width=10, grid_height=10, magnitude=30)


#확대
#img.zoom_random(probability=1, percentage_area=0.8)


#크롭
# img.crop_random(probability=1, percentage_area=0.8, randomise_percentage_area=False)


#랜덤 지우기
#img.random_erasing(probability=1.0, rectangle_area=0.3)/


# 증강 이미지 수
img.sample(1)



test 파일을 만들어 주석과 비율 변경을 반복하며 정도를 맞춰나갔다.

수시로 파일명을 변경해주면서 확인하는 것이 추후에 관리하기 편할 것이다.

4. 결과

무료 이미지를 다운받아 확인한 결과이다.

이외에도 다양한 증강 방법을 홈페이지에서 확인할 수 있다.





https://augmentor.readthedocs.io/en/master/

Augmentor — Augmentor 0.2.6 documentation

© Copyright 2016, Marcus D. Bloice Revision f3e62942.

augmentor.readthedocs.io

2개의 댓글

comment-user-thumbnail
2022년 10월 19일

IndexError Traceback (most recent call last)
in
32
33 # 증강 이미지 수
---> 34 img.sample(1)

/usr/local/lib/python3.7/dist-packages/Augmentor/Pipeline.py in sample(self, n, multi_threaded)
351
352 if len(self.operations) == 0:
--> 353 raise IndexError("There are no operations associated with this pipeline.")
354
355 if n == 0:

IndexError: There are no operations associated with this pipeline.

이런 오류가 뜹니다 ㅜㅜ구글링해봐도 안나오는데 혹시 아실까요?

1개의 답글