composer.algorithms.utils.augmentation_common#

composer.algorithms.utils.augmentation_common

Functions

cast

Cast a value to a type.

image_as_type

Converts between torch.Tensor and

map_pillow_function

Lifts a function that requires pillow images to also work on tensors.

Classes

Image

This class represents an image object.

TypeVar

Type variable.

Attributes

  • Callable

  • Iterable

  • Type

composer.algorithms.utils.augmentation_common.image_as_type(image, typ)[source]#
Converts between torch.Tensor and

PIL.Image.Image image representations

Parameters
  • image โ€“ a single image represented as a PIL.Image.Image or a rank 2 or rank 3 torch.Tensor in HW or CHW format. A rank 4 or higher tensor can also be provided as long as no type conversion is needed; in this case, the input tensor will be returned. This case is allowed so that functions that natively operate on batch tensors can safely call image_as_type(image, torch.Tensor) without additional error and type checking.

  • typ โ€“ type of the copied image. Must be PIL.Image.Image or torch.Tensor

Returns

A copy of ``image`` with type ``typ``

Raises
composer.algorithms.utils.augmentation_common.map_pillow_function(f_pil, imgs)[source]#

Lifts a function that requires pillow images to also work on tensors.

Parameters
Returns
  • The result of applying ``f_pil`` to each image in ``imgs``, converted

  • back to the same type and (if applicable)