Skip to content

hirune924/imgaug-tf

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

imgaug-tf

An image augmentation library for tensorflow. This library is implemented in TF native and has been tested to work with TPU.

Installation

!pip install -U imgaugtf

or for nightly version

!pip install -U git+https://github.com/hirune924/imgaug-tf

Required packages:

  • tensorflow (2.6.3 or higher recommended)
  • tensorflow_addons (0.14.0 or higher recommended)
  • tensorflow_probability (0.14.1 or higher recommended)

Quick Start

imgaugtf is implemented to work simply with tf.data. Example of use single transform.

import imgaugtf

image = imgaugtf.random_solarize_add(image, addition=30, prob=0.5)

You can also apply transform for a mask as same as a image.

import imgaugtf

image = imgaugtf.seg.random_solarize_add(image, mask, addition=30, prob=0.5)

You can also randomly select n of multiple transformations to apply, as shown below. You can use mixup or cutmix on batched images.

import imgaugtf

def augmentation(example):
    example['image'] = imgaugtf.random_resized_crop(example['image'], size=[256, 256], prob=1.0)
    example['image'] = imgaugtf.apply_n(example['image'], functions=imgaugtf.OPERATORS, num_ops=2, prob=1.0)
    return example

def batch_augmentation(example, num_class=120):
    image = example['image']
    label = tf.one_hot(example['label'], num_class)
    
    image, label = imgaugtf.cutmix(image, label)
    return image, label

result = next(iter(dataset.map(augmentation).batch(15).map(batch_augmentation)))

for i in range(10):
    plt.imshow(result[0][i])
    plt.show()

functions is list of dict like this example. dict has keys of 'func' and 'option'. you can customize it you like.

[
    {"func": imgaugtf.random_cutout, "option": {"num_holes": 8, "hole_size": 20, "replace": 0}},
    {"func": imgaugtf.random_solarize, "option": {"threshold": 128}},
    {"func": imgaugtf.random_solarize_add, "option": {"addition": 30, "threshold": 128}},
]

Examples

Augmentations

pixel

image mask
original original original
random_solarize random_solarize original
random_solarize_add random_solarize_add original
random_color random_color original
random_contrast random_contrast original
random_brightness random_brightness original
random_posterize random_posterize original
random_invert random_invert original
random_equalize random_equalize original
random_sharpness random_sharpness original
random_autocontrast random_autocontrast original
random_hsv_in_yiq random_hsv_in_yiq original
random_gaussian_filter2d random_gaussian_filter2d original
random_mean_filter2d random_mean_filter2d original
random_median_filter2d random_median_filter2d original
random_cutout random_cutout original
random_gray random_gray original
random_hue random_hue original
random_saturation random_saturation original
random_gamma random_gamma original
random_jpeg_quality random_jpeg_quality original
random_gaussian_noise random_gaussian_noise original
random_speckle_noise random_speckle_noise original

geometory

image mask
original original original
random_flip_left_right random_flip_left_right random_flip_left_right
random_flip_up_down random_flip_up_down random_flip_up_down
random_resized_crop random_resized_crop random_resized_crop
random_rotate random_rotate random_rotate
random_translate_x random_translate_x random_translate_x
random_translate_y random_translate_y random_translate_y
random_shear_x random_shear_x random_shear_x
random_shear_y random_shear_y random_shear_y
random_zoom random_zoom random_zoom
random_grid_shuffle random_grid_shuffle random_grid_shuffle
random_affine random_affine random_affine
random_elastic_deform random_elastic_deform random_affine
random_sparse_warp random_sparse_warp random_sparse_warp
random_crop random_crop random_crop

blend

  • mixup
  • cutmix

compose

  • apply_one
  • apply_n

About

An image augmentation library for tensorflow.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages