base.py 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. """Base classes and functions used by all/most augmenters.
  2. This module is planned to contain :class:`imgaug.augmenters.meta.Augmenter`
  3. in the future.
  4. Added in 0.4.0.
  5. """
  6. import imgaug as ia
  7. class SuspiciousMultiImageShapeWarning(UserWarning):
  8. """Warning multi-image inputs that look like a single image."""
  9. class SuspiciousSingleImageShapeWarning(UserWarning):
  10. """Warning for single-image inputs that look like multiple images."""
  11. def _warn_on_suspicious_multi_image_shapes(images):
  12. if images is None:
  13. return
  14. # check if it looks like (H, W, C) instead of (N, H, W)
  15. if ia.is_np_array(images):
  16. if images.ndim == 3 and images.shape[-1] in [1, 3]:
  17. ia.warn(
  18. "You provided a numpy array of shape %s as a "
  19. "multi-image augmentation input, which was interpreted as "
  20. "(N, H, W). The last dimension however has value 1 or "
  21. "3, which indicates that you provided a single image "
  22. "with shape (H, W, C) instead. If that is the case, "
  23. "you should use e.g. augmenter(image=<your input>) or "
  24. "augment_image(<your input>) -- note the singular 'image' "
  25. "instead of 'imageS'. Otherwise your single input image "
  26. "will be interpreted as multiple images of shape (H, W) "
  27. "during augmentation." % (images.shape,),
  28. category=SuspiciousMultiImageShapeWarning)
  29. def _warn_on_suspicious_single_image_shape(image):
  30. if image is None:
  31. return
  32. # Check if it looks like (N, H, W) instead of (H, W, C).
  33. # We don't react to (1, 1, C) though, mostly because that is used in many
  34. # unittests.
  35. if image.ndim == 3 and image.shape[-1] >= 32 and image.shape[0:2] != (1, 1):
  36. ia.warn(
  37. "You provided a numpy array of shape %s as a "
  38. "single-image augmentation input, which was interpreted as "
  39. "(H, W, C). The last dimension however has a size of >=32, "
  40. "which indicates that you provided a multi-image array "
  41. "with shape (N, H, W) instead. If that is the case, "
  42. "you should use e.g. augmenter(imageS=<your input>) or "
  43. "augment_imageS(<your input>). Otherwise your multi-image "
  44. "input will be interpreted as a single image during "
  45. "augmentation." % (image.shape,),
  46. category=SuspiciousSingleImageShapeWarning)