Skip to main content

TTAugment

GitHub Python Contributions welcome Downloads

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.

  1. Mirror : Crop an image to crop_to_dimension and mirror pixels to match the size of window_dimension
  2. CropScale : Crop an image to crop_to_dimension and rescale the image to match the size of window_dimension
  3. NoAugment : Keep the input unchanged
  4. Crop : Crop an image to crop_to_dimension
  5. Rot : Rotate an Image
  6. FlipHorizontal
  7. 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()

Metadata

Release files for ttAugment 0.4.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for ttAugment 0.4.1
File Size Uploaded
ttAugment-0.4.1.tar.gz 7.4 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for ttAugment 0.4.1
File Interpreter ABI Platform
ttAugment-0.4.1-py3-none-any.whl Python 3 none any Details

Total release size: 15.9 kB

Release files / ttAugment-0.4.1.tar.gz

Download URL ttAugment-0.4.1.tar.gz
Size 7.4 kB
Tags Source
SHA-256 checksum
How to use checksums
e60436f57e33f044f1fa47234e225e76543662439c5393311a4cd33bde832205
BLAKE2b-256 checksum
How to use checksums
a92c08eb87a01f63e0cc73ac2ff4b7b069a06270edd4c9dc4f15ad4cac30c68b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.1 CPython/3.9.14

Release files / ttAugment-0.4.1-py3-none-any.whl

Download URL ttAugment-0.4.1-py3-none-any.whl
Size 8.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
7cb8d6e5d7d8864aee844f7fb942a32c9d77dcad1022a6eee3f6e80b0cee92c4
BLAKE2b-256 checksum
How to use checksums
6f9986e715d7853da56ce6ef58c9eae082974720bb2760999030af0aaaab45bd
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.1 CPython/3.9.14

Release history Release notifications | RSS feed

This release

0.4.1 This release

2 release files

0.3.4

1 release file

0.3.3

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page