composer.algorithms.utils.augmentation_common#
composer.algorithms.utils.augmentation_common
Functions
Cast a value to a type. |
|
Converts between |
|
Lifts a function that requires pillow images to also work on tensors. |
Classes
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 3torch.Tensor
inHW
orCHW
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 callimage_as_type(image, torch.Tensor)
without additional error and type checking.typ โ type of the copied image. Must be
PIL.Image.Image
ortorch.Tensor
- Returns
A copy of ``image`` with type ``typ``
- Raises
TypeError โ if
typ
is not one oftorch.Tensor
orPIL.Image.Image
ValueError โ if
image
cannot be converted to thetyp
, such as when requesting conversion of a rank 4 tensor toPIL.Image.Image
.
- Converts between
- 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
f_pil โ a callable that takes maps
PIL.Image.Image
objects to otherPIL.Image.Image
objects.imgs โ a
PIL.Image.Image
or atorch.Tensor
inHW
,CHW
orNCHW
format.
- Returns
The result of applying ``f_pil`` to each image in ``imgs``, converted
back to the same type and (if applicable)