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
CallableIterableType
- composer.algorithms.utils.augmentation_common.image_as_type(image, typ)[source]#
- Converts between
torch.Tensorand PIL.Image.Imageimage representations
- Parameters
image โ a single image represented as a
PIL.Image.Imageor a rank 2 or rank 3torch.TensorinHWorCHWformat. 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.Imageortorch.Tensor
- Returns
A copy of ``image`` with type ``typ``
- Raises
TypeError โ if
typis not one oftorch.TensororPIL.Image.ImageValueError โ if
imagecannot 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.Imageobjects to otherPIL.Image.Imageobjects.imgs โ a
PIL.Image.Imageor atorch.TensorinHW,CHWorNCHWformat.
- Returns
The result of applying ``f_pil`` to each image in ``imgs``, converted
back to the same type and (if applicable)