Test Time Augmentations
Project description
TTAugment
Perform Augmentation during Inference and aggregate the results of all the applied augmentation to create a final output
Installation
pip install ttAugment
Supported Augmentation
Library supports all color, blur and contrast transformation provided by imgaug along with custom Geometric Transformation.
- Mirror : Crop an image to
crop_to_dimension
and mirror pixels to match the size ofwindow_dimension
- CropScale : Crop an image to
crop_to_dimension
and rescale the image to match the size ofwindow_dimension
- NoAugment : Keep the input unchanged
- Crop : Crop an image to
crop_to_dimension
- Rot : Rotate an Image
- FlipHorizontal
- FlipVertical
Usage
How to use when test image is much larger than what the model requires, Don't worry the library has it covered, it will generate fragments according to the specified dimension, so the inference can be performed while applying augmentation.
- window_size: Break the image into smaller images of said size
- output_dimension: It must be greater the input image in order for the fragments to be restored back on the image.
import numpy as np
from tt_augment.augment import generate_seg_augmenters
transformation_to_apply = [
{"name": "Mirror", "crop_to_dimension": (256, 256)},
{"name": "CropScale", "crop_to_dimension": (256, 256)},
]
for i in range(0, 10):
image = np.random.rand(512, 512, 3) * 255
image = np.expand_dims(image, 0)
# Load augmentation object for the image, this includes to break the image in smaller fragments.
tta = generate_seg_augmenters(
image=image,
window_size=(384, 384),
output_dimension=(1, 512, 512, 3),
transformation_to_apply=transformation_to_apply,
)
# Iterate over transformation_to_apply
for iterator, transformation in enumerate(tta):
# Iterate over individual fragments
for augmented_fragment in transformation.transform_fragment():
# ---> transformed_fragment.shape = (1, 384, 384, 3)
# Inference steps for augmented fragment
# 1. perform image normalization
# ---> normalised_image = image_normalization(augmented_fragment)
# 2. perform model prediction
# ---> prediction = model.predict(normalised_image)
# 3. convert prediction to numpy with shape [batch, h, w, channel]
# 4. place the prediction fragment on its position in the original image
# ---> transformation.restore_fragment(prediction)
transformation.restore_fragment(augmented_fragment)
# Aggregate the result for the input image over all applied augmentations
tta.merge()
output = tta.tta_output()
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 Distribution
ttAugment-0.4.1.tar.gz
(7.4 kB
view details)
Built Distribution
File details
Details for the file ttAugment-0.4.1.tar.gz
.
File metadata
- Download URL: ttAugment-0.4.1.tar.gz
- Upload date:
- Size: 7.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.9.14
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | e60436f57e33f044f1fa47234e225e76543662439c5393311a4cd33bde832205 |
|
MD5 | 040536cfd68328e5b76c97dde1210331 |
|
BLAKE2b-256 | a92c08eb87a01f63e0cc73ac2ff4b7b069a06270edd4c9dc4f15ad4cac30c68b |
File details
Details for the file ttAugment-0.4.1-py3-none-any.whl
.
File metadata
- Download URL: ttAugment-0.4.1-py3-none-any.whl
- Upload date:
- Size: 8.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.9.14
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7cb8d6e5d7d8864aee844f7fb942a32c9d77dcad1022a6eee3f6e80b0cee92c4 |
|
MD5 | 0e1e0d3a2aaf72d9fd0b4f5ed9854b5e |
|
BLAKE2b-256 | 6f9986e715d7853da56ce6ef58c9eae082974720bb2760999030af0aaaab45bd |