Skip to content

Support all integer and floating point dtypes in prototype transform kernels? #6840

@pmeier

Description

@pmeier

The standard rule for dtype support for images and videos is:

  • All floating point and integer tensors are supported.
  • Floating point tensors are valid in the range [0.0, 1.0] and integer tensors in [0, torch.iinfo(dtype).max] (this is currently under review since there were a few cases, where this was not true or simply not handled. See Don't hardcode 255 unless uint8 is enforced #6825)

However we have currently two kernels that only support uint8 images or videos:

This also holds for transforms v1 so this is not a problem of the new API.

One consequence of that is that AA transforms are only supported for uint8 images

class AutoAugment(torch.nn.Module):
r"""AutoAugment data augmentation method based on
`"AutoAugment: Learning Augmentation Strategies from Data" <https://arxiv.org/pdf/1805.09501.pdf>`_.
If the image is torch Tensor, it should be of type torch.uint8, and it is expected

since both

elif op_name == "Posterize":
img = F.posterize(img, int(magnitude))

and

elif op_name == "Equalize":
img = F.equalize(img)

are used.

One possible way of mitigating this to simply have a convert_dtype(image, torch.uint8) in the beginning and converting back after computation.

That is probably needed for equalize since we recently switched away from the histogram ops of torch towards our "custom" implementation to enable batch processing (#6757). However, this relies on the fact that the input is an integer and in its current form even on uint8 due to some hardcoded constants.

For posterize I think it is fairly easy to provide the same functionality for float inputs directly without going through a dtype conversion first.

cc @vfdev-5 @datumbox @bjuncek

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions