Skip to content

Augmentation

ObjectDetection 학습 시 사용 가능한 augmentation 종류는 다음과 같습니다 (총 12종류)

[
    "vertical_flip",
    "horizontal_flip",
    "rotate",
    "random_rotate90",
    "color_jitter",
    "blur",
    "adjust_gamma",
    "adjust_brightness_contrast",
    "iso_noise",
    "zoom",
    "ratio_jitter",
    "light_reflect",
]

이를 위한 image augmentation API는 Preview API와 Trainer Config의 2가지로 구성됩니다.

  • Preview API: 유저가 세팅한 파라미터에 대해 이미지 미리보기 제공
  • Trainer Config: 유저가 세팅한 파라미터를 학습에 사용하기 위해 Trainer.build()에 넣어주는 config

detection.ImageProcessor

Bases: _APIDecorator

Image Augmentation Preview를 위한 API 입니다. 각 augmentation들이 특정 파라미터 값에 대해 이미지를 어떻게 변형 시키는지 확인할 수 있습니다.

Note

일반적으로 학습 시에는 파라미터를 특정 이 아닌 범위로 설정하여 해당 범위에서 매번 랜덤한 값을 선택해 이미지에 적용합니다. 따라서 preview API의 입력 파라미터와 학습 시 넘겨주는 파라미터는 대부분 vs 범위의 차이를 가지게 됩니다. 예를 들어 preview API에서 rotate의 경우 angle (float) 값을 받지만, 학습 config에서는 angle_limit (List[float]) 범위를 받게됩니다. 각 augmentation을 학습에 사용시 필요한 config는 각 함수 설명의 Trainer Config 섹션을 참고하세요.

Usage

rotate augmentation preview 예제입니다. 상세 설명은 각 함수 설명 참고.

image = np.zeros((100, 100, 3), dtype=np.unit8)
error, augmented_image = ImageProcessor.rotate(image=image, angle=15)

vertical_flip(image)

image를 상하로 뒤집습니다.

Parameters:

Name Type Description Default
image np.ndarray

augmentation을 적용할 image 입니다.

data type: uint8
channel: H x W / H x W x 1  - Gray
         H x W x 3 - RGB
         H x W x 4 - RGBA

required

Returns:

Type Description
np.ndarray

np.ndarray: augmentation이 적용된 image 입니다.

Example
error, augmented_image = ImageProcessor.vertical_flip(image=image)
Trainer Config
{
    "_target_": "vertical_flip",
}

horizontal_flip(image)

image를 좌우로 뒤집습니다.

Parameters:

Name Type Description Default
image np.ndarray

augmentation을 적용할 image 입니다.

data type: uint8
channel: H x W / H x W x 1  - Gray
         H x W x 3 - RGB
         H x W x 4 - RGBA

required

Returns:

Type Description
np.ndarray

np.ndarray: augmentation이 적용된 image 입니다.

Example
error, augmented_image = ImageProcessor.horizontal_flip(image=image)
Trainer Config
{
    "_target_": "horizontal_flip",
}

rotate(image, angle=0.0)

image를 angle만큼 회전시킵니다.

Parameters:

Name Type Description Default
image np.ndarray

augmentation을 적용할 image 입니다.

data type: uint8
channel: H x W / H x W x 1  - Gray
         H x W x 3 - RGB
         H x W x 4 - RGBA

required
angle float

회전하는 각도 입니다. 유효 범위는 다음과 같습니다. [-360.0, 360.0]. Defaults to 0.0.

0.0

Returns:

Type Description
np.ndarray

np.ndarray: augmentation이 적용된 image 입니다.

Example
error, augmented_image = ImageProcessor.rotate(image=image, angle=60.0)
Trainer Config
{
    "_target_": "rotate",
    "angle_limit": List[float],  # angle 최소 최대 범위
}

random_rotate90(image, factor=0)

image를 [0, 90, 180, 270] 중 랜덤한 각도만큼 회전시킵니다.

Parameters:

Name Type Description Default
image np.ndarray

augmentation을 적용할 image 입니다.

data type: uint8
channel: H x W / H x W x 1  - Gray
         H x W x 3 - RGB
         H x W x 4 - RGBA

required
factor int

회전하는 각도 입니다. factor에 90을 곱한 값만큼 회전합니다. (ex. factor가 1일 경우 90도) 유효범위는 다음과 같습니다 [0, 3]. Defaults to 0.

0

Returns:

Type Description
np.ndarray

np.ndarray: augmentation이 적용된 image 입니다.

Example
error, augmented_image = ImageProcessor.random_rotate90(image=image, factor=1)
Trainer Config
{
    "_target_": "random_rotate90",
}

color_jitter(image, brightness=1.0, contrast=1.0, saturation=1.0, hue=0.0)

image의 밝기 (brightness), 대비 (contrast), 채도 (saturation), 색상 (hue)을 변경합니다.

Parameters:

Name Type Description Default
image np.ndarray

augmentation을 적용할 image 입니다.

data type: uint8
channel: H x W / H x W x 1  - Gray
         H x W x 3 - RGB
         H x W x 4 - RGBA

required
brightness float

밝기를 담당하는 요소입니다. 유효 범위는 다음과 같습니다. [0.01, 10.00]. Defaults to 1.0.

1.0
contrast float

대비를 담당하는 요소입니다. 유효 범위는 다음과 같습니다. [0.01, 10.00]. Defaults to 1.0.

1.0
saturation float

채도를 담당하는 요소입니다. 유효 범위는 다음과 같습니다. [0.01, 10.00]. Defaults to 1.0.

1.0
hue float

색상을 담당하는 요소입니다. 유효 범위는 다음과 같습니다. [-0.50, 0.50]. Defaults to 0.0.

0.0

Returns:

Type Description
np.ndarray

np.ndarray: augmentation이 적용된 image 입니다.

Example
error, augmented_image = ImageProcessor.color_jitter(image=image,
                                                     brightness=0.5,
                                                     contrast=0.5,
                                                     saturation=0.5,
                                                     hue=0.1)  #  augmentation 적용
Trainer Config
{
    "_target_": "color_jitter",
    "brightness_limit": List[float],  # brightness 최소 최대 범위
    "contrast_limit": List[float],  # contrast 최소 최대 범위
    "saturation_limit": List[float],  # saturation 최소 최대 범위
    "hue_limit": List[float],  # hue 최소 최대 범위
}

blur(image, ksize=1)

image에 averaging blur를 적용합니다.

Parameters:

Name Type Description Default
image np.ndarray

augmentation을 적용할 image 입니다.

data type: uint8
channel: H x W / H x W x 1  - Gray
         H x W x 3 - RGB
         H x W x 4 - RGBA

required
ksize int

blur kernel의 크기 입니다. 유효 범위는 다음과 같습니다. [1, 100]. Defaults to 1.

1

Returns:

Type Description
np.ndarray

np.ndarray: augmentation이 적용된 image 입니다.

Example
error, augmented_image = ImageProcessor.blur(image=image, ksize=3)
Trainer Config
{
    "_target_": "blur",
    "ksize_limit": List[int],  # ksize 최소 최대 범위
}

adjust_gamma(image, gamma=0.0)

image의 gamma를 조절하여 밝기를 변화시킵니다.

Parameters:

Name Type Description Default
image np.ndarray

augmentation을 적용할 image 입니다.

data type: uint8
channel: H x W / H x W x 1  - Gray
         H x W x 3 - RGB
         H x W x 4 - RGBA

required
gamma float

조절할 gamma value 입니다. 유효 범위는 다음과 같습니다. [-1.0, 1.0]. Defaults to 0.0.

0.0

Returns:

Type Description
np.ndarray

np.ndarray: augmentation이 적용된 image 입니다.

Example
error, augmented_image = ImageProcessor.adjust_gamma(image=image, gamma=0.5)
Trainer Config
{
    "_target_": "adjust_gamma",
    "gamma_limit": List[float],  # gamma 최소 최대 범위
}

adjust_brightness_contrast(image, brightness=0.0, contrast=0.0)

image의 밝기 (brightness), 대비 (contrast)를 변경합니다.

Parameters:

Name Type Description Default
image np.ndarray

augmentation을 적용할 image 입니다.

data type: uint8
channel: H x W / H x W x 1  - Gray
         H x W x 3 - RGB
         H x W x 4 - RGBA

required
brightness float

밝기를 담당하는 요소입니다. 유효 범위는 다음과 같습니다. [-1.00, 1.00]. Defaults to 0.0.

0.0
contrast float

대비를 담당하는 요소입니다. 유효 범위는 다음과 같습니다. [-1.00, 1.00]. Defaults to 0.0.

0.0

Returns:

Type Description
np.ndarray

np.ndarray: augmentation이 적용된 image 입니다.

Example
error, augmented_image = ImageProcessor.adjust_brightness_contrast(image=image, brightness=0.3, contrast=0.7)
Trainer Config
{
    "_target_": "adjust_brightness_contrast",
    "brightness_limit": List[float],  # brightness 최소 최대 범위
    "contrast_limit": List[float],  # contrast 최소 최대 범위
}

iso_noise(image, color_shift=0.0, intensity=0.0)

Apply camera sensor noise.

Parameters:

Name Type Description Default
image np.ndarray

augmentation을 적용할 image 입니다.

data type: uint8
channel: H x W / H x W x 1  - Gray
         H x W x 3 - RGB
         H x W x 4 - RGBA

required
color_shift float

variance range for color hue change. Measured as a fraction of 360 degree Hue angle in HLS colorspace. 유효 범위는 다음과 같습니다. [0.00, 1.00]. Defaults to 0.0.

0.0
intensity float

Multiplicative factor that control strength of color and luminace noise. 유효 범위는 다음과 같습니다. [0.00, 2.00]. Defaults to 0.0.

0.0

Returns:

Type Description
np.ndarray

np.ndarray: augmentation이 적용된 image 입니다.

Example
error, augmented_image = ImageProcessor.iso_noise(image=image, color_shift=0.2, intensity=0.2)
Trainer Config
{
    "_target_": "iso_noise",
    "color_shift_limit": List[float],  # color_shift 최소 최대 범위
    "intensity_limit": List[float],  # intensity 최소 최대 범위
}

zoom(image, ratio=1.0)

image에 zoom in/out 효과를 줍니다.

Parameters:

Name Type Description Default
image np.ndarray

augmentation을 적용할 image 입니다.

data type: uint8
channel: H x W / H x W x 1  - Gray
         H x W x 3 - RGB
         H x W x 4 - RGBA

required
ratio float

zoom in/out 할 비율입니다. 1보다 크면 zoom in을 1보다 작으면 zoom out을 합니다. 유효 범위는 다음과 같습니다. [0.01, 100.00]. Defaults to 1.0.

1.0

Returns:

Type Description
np.ndarray

np.ndarray: augmentation이 적용된 image 입니다.

Example
error, augmented_image = ImageProcessor.zoom(image=image, ratio=2.0)
Trainer Config
{
    "_target_": "zoom",
    "ratio_limit": List[float],  # ratio 최소 최대 범위
}

ratio_jitter(image, proportion=0)

image에 random하게 padding과 crop을 한 뒤, 원래 size로 resize 하는 과정을 통해 image의 가로 세로 비율을 변경합니다. NOTE: 프리뷰에서는 좌우변을 crop 혹은 padding, 위아래변을 padding 혹은 crop한 예시를 보여줍니다.

Parameters:

Name Type Description Default
image np.ndarray

augmentation을 적용할 image 입니다.

data type: uint8
channel: H x W / H x W x 1  - Gray
         H x W x 3 - RGB
         H x W x 4 - RGBA

required
proportion int

padding 혹은 crop을 할 비율(단위: 백분율)입니다. 양수일 때 crop을 음수일 때 padding을 합니다. 유효 범위는 다음과 같습니다. [-50, 50]. Defaults to 0.

0

Returns:

Type Description
np.ndarray

np.ndarray: augmentation이 적용된 image 입니다.

Example
error, augmented_image = ImageProcessor.ratio_jitter(image=image, proportion=2)
Trainer Config
{
    "_target_": "ratio_jitter",
    "proportion_limit": int,  # proportion 최대 범위
}

light_reflect(image, radius=0.0)

image에 원형 빛을 비춘 것 같은 효과를 줍니다.

Parameters:

Name Type Description Default
image np.ndarray

augmentation을 적용할 image 입니다.

data type: uint8
channel: H x W / H x W x 1  - Gray
         H x W x 3 - RGB
         H x W x 4 - RGBA

required
radius float

원형 빛의 반지름 크기 입니다. 유효 범위는 다음과 같습니다. [0.00, 1.00]. Defaults to 0.0.

0.0

Returns:

Type Description
np.ndarray

np.ndarray: augmentation이 적용된 image 입니다.

Example
error, augmented_image = ImageProcessor.light_reflect(image=image, radius=0.30)
Trainer Config
{
    "_target_": "light_reflect",
    "radius_limit": List[float],  # radius 최소 최대 범위
}

Trainer Config

Trainer에 넘겨주는 augmentation config는 List[Dict] 형태이며, 적용할 augmentation들의 파라미터(Dict)를 리스트로 모은 것입니다. 해당 리스트를 Trainer.build() config의 augmentation 섹션에 넣어주면 학습 시 augmentation이 적용됩니다.

  • Augmentation config 예시 (9가지 augmentation 모두 사용하는 경우, 파라미터는 유저가 선택한 값)

    augmentation_config = [
        {
            "_target_": "vertical_flip",
        },
        {
            "_target_": "horizontal_flip",
        },
        {
            "_target_": "rotate",
            "angle_limit": [-30, 30],
        },
        {
            "_target_": "random_rotate90",
        },
        {
            "_target_": "color_jitter",
            "brightness_limit": [0.8, 1.2],
            "contrast_limit": [0.8, 1.2],
            "saturation_limit": [0.8, 1.2],
            "hue_limit": [-0.2, 0.2],
        },
        {
            "_target_": "blur",
            "ksize_limit": [3, 7],
        },
        {
            "_target_": "adjust_gamma",
            "gamma_limit": [-0.2, 0.2],
        },
        {
            "_target_": "adjust_brightness_contrast",
            "brightness_limit": [-0.2, 0.2],
            "contrast_limit": [-0.2, 0.2],
        },
        {
            "_target_": "iso_noise",
            "color_shift_limit": [0.01, 0.05],
            "intensity_limit": [0.1, 0.5],
        },
        {
            "_target_": "zoom",
            "ratio_limit": [0.50, 2.00],
        },
        {
            "_target_": "ratio_jitter",
            "proportion_limit": [-0.10, 0.10],
        },
        {
            "_target_": "light_reflect",
            "radius_limit": [0.10, 0.50],
        },
    ]
    

  • Augmentation config 예시2 ("vertical_flip"만 사용하는 경우)

    augmentation_config = [
        {
            "_target_": "vertical_flip",
        },
    ]
    

  • Trainer build config 예시

    augmentation_config = [
        {
            "_target_": "vertical_flip",
        },
        {
            "_target_": "rotate",
            "angle_limit": [-30, 30],
        },
    ]
    
    trainer_config = {
        "model": "shallow",
        ...
        "augmentation": augmentation_config,  # augmentation section에 삽입
        ...
    }
    
    error, trainer = Trainer.build(config=trainer_config, data)