Skip to main content

Test Time Augmentations

Project description

TTAugment

GitHub Python Contributions welcome

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

Parameters

How to use when test image is much bigger than what my models needs as input, Don't worry the library has it covered it will generate fragments according to the specified dimension, so you can run inference on the desired dimension, and get the output as per the original test image.

  • image_dimension - What is the size of my input image

      image_dimension=(2, 1500, 1500, 3) 
    
  • transformer - list of augmentations to perform transform_dimension - specifies what dimension is the network expecting the input to be in, if less than image_dimension, the library will generate smaller fragment of size transform_dimension for inference and apply transformation over it

      transformers=[
      {
          "name": "CLAHE",
          "transform_dimension": (2, 1000, 1000, 3),
      },
      ],
    
    • Dealing with parameters during Scaling transformation, two transformation perform scaling on the test images For Scaling transformation transform_dimension and network_dimension are mandatory parameters

        transformers=[
        {
        "name": "Mirror",
        "transform_dimension": (2, 800, 800, 3),
        "network_dimension": (2, 1000, 1000, 3)
        },
        
        {
        "name": "CropScale",
        "transform_dimension": (2, 800, 800, 3),
        "network_dimension": (2, 1000, 1000, 3)
        }
        ],
      

      The network_dimension parameter informs the library to override the network input and crop the image to transform_dimension and rescale it to network_dimension to get it as per network requirement

      And again the library will merge all the fragments to form the final output of image_dimension

    • For using Rot - Rotate add "param": angle as an additional argument

If the test image has the same dimension to what the network expects, in that case just remove the transform_dimension param.

Inference

Define tta object
tta = Segmentation.populate_color(
        image_dimension=(2, 1500, 1500, 3),
         transformers=transformers) # transfromer as defined in parameters
Calling the generator

Input image is required to be a 4d numpy array of shape (batch, height, width, channels)

for image list(loop over all the images): 
    for transformation in tta.run():
        # Apply forward transfromation
        forward_image = tta.forward(transformation, image=image)

        # Apply normalization
        # Convert input to framework specific type
        # Perform inference
        inferred_image = model.predict(forward_image)

        # make sure to convert the inferred_image to 4d numpy array [batch, height, width, classes]
        reversed_image = tta.reverse(transformation, inferred_image)

        # Add the reversed image to transformation
        tta.update(transformation, reversed_image)
    
    # Access the output
    output = tta.transformations.output

Project details


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.3.4.tar.gz (7.4 kB view details)

Uploaded Source

File details

Details for the file ttAugment-0.3.4.tar.gz.

File metadata

  • Download URL: ttAugment-0.3.4.tar.gz
  • Upload date:
  • Size: 7.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/49.6.0.post20200814 requests-toolbelt/0.9.1 tqdm/4.50.2 CPython/3.7.7

File hashes

Hashes for ttAugment-0.3.4.tar.gz
Algorithm Hash digest
SHA256 7bf41086d5ad488d278579cb03b27b8178b3ad0cc907e23766205f710fd0ed2c
MD5 3ac3e6bd6b61ca2b10a5961ba02af482
BLAKE2b-256 96159796b22077d2b2a3d7cc807735cb622036befca8df6146452417282d3856

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page