项目作者: fuzailpalnak

项目描述 :
Test Time Augmentation for Deep Learning Inference
高级语言: Python
项目地址: git://github.com/fuzailpalnak/ttAugment.git
创建时间: 2020-08-15T12:08:55Z
项目社区:https://github.com/fuzailpalnak/ttAugment

开源协议:MIT License

下载


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

  1. 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.
  1. import numpy as np
  2. from tt_augment.augment import generate_seg_augmenters
  3. transformation_to_apply = [
  4. {"name": "Mirror", "crop_to_dimension": (256, 256)},
  5. {"name": "CropScale", "crop_to_dimension": (256, 256)},
  6. ]
  7. for i in range(0, 10):
  8. image = np.random.rand(512, 512, 3) * 255
  9. image = np.expand_dims(image, 0)
  10. # Load augmentation object for the image, this includes to break the image in smaller fragments.
  11. tta = generate_seg_augmenters(
  12. image=image,
  13. window_size=(384, 384),
  14. output_dimension=(1, 512, 512, 3),
  15. transformation_to_apply=transformation_to_apply,
  16. )
  17. # Iterate over transformation_to_apply
  18. for iterator, transformation in enumerate(tta):
  19. # Iterate over individual fragments
  20. for augmented_fragment in transformation.transform_fragment():
  21. # ---> transformed_fragment.shape = (1, 384, 384, 3)
  22. # Inference steps for augmented fragment
  23. # 1. perform image normalization
  24. # ---> normalised_image = image_normalization(augmented_fragment)
  25. # 2. perform model prediction
  26. # ---> prediction = model.predict(normalised_image)
  27. # 3. convert prediction to numpy with shape [batch, h, w, channel]
  28. # 4. place the prediction fragment on its position in the original image
  29. # ---> transformation.restore_fragment(prediction)
  30. transformation.restore_fragment(augmented_fragment)
  31. # Aggregate the result for the input image over all applied augmentations
  32. tta.merge()
  33. output = tta.tta_output()

Example Implementation

Library used for Predicting Building footprint