tensorflow native image augmantation
Project description
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 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}},
]
Augmentations
pixel
image | mask | |
---|---|---|
original | ||
random_solarize | ||
random_solarize_add | ||
random_color | ||
random_contrast | ||
random_brightness | ||
random_posterize | ||
random_invert | ||
random_equalize | ||
random_sharpness | ||
random_autocontrast | ||
random_hsv_in_yiq | ||
random_gaussian_filter2d | ||
random_mean_filter2d | ||
random_median_filter2d | ||
random_cutout | ||
random_gray | ||
random_hue | ||
random_saturation | ||
random_gamma | ||
random_jpeg_quality | ||
random_gaussian_noise | ||
random_speckle_noise |
geometory
image | mask | |
---|---|---|
original | ||
random_flip_left_right | ||
random_flip_up_down | ||
random_resized_crop | ||
random_rotate | ||
random_translate_x | ||
random_translate_y | ||
random_shear_x | ||
random_shear_y | ||
random_zoom | ||
random_grid_shuffle | ||
random_affine | ||
random_elastic_deform | ||
random_sparse_warp | ||
random_crop |
blend
- mixup
- cutmix
compose
- apply_one
- apply_n
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distributions
No source distribution files available for this release.See tutorial on generating distribution archives.
Built Distribution
imgaugtf-1.0.0-py3-none-any.whl
(24.0 kB
view details)
File details
Details for the file imgaugtf-1.0.0-py3-none-any.whl
.
File metadata
- Download URL: imgaugtf-1.0.0-py3-none-any.whl
- Upload date:
- Size: 24.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.8.0 pkginfo/1.8.3 readme-renderer/34.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.9 tqdm/4.64.0 importlib-metadata/4.8.3 keyring/23.4.1 rfc3986/1.5.0 colorama/0.4.5 CPython/3.6.9
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 43033dc79289787bc321f2fd02ac33132226a95a351b5779c0e75f0150a811b5 |
|
MD5 | 96cb24467a12ba9185573e46b775bd47 |
|
BLAKE2b-256 | 4db8d1af4be32554f8171a73d3b1a8c626029f1a463e2dd27278dccbef4ee794 |