Skip to content

Dtype and scale conversion in V2 #7756

Closed
@NicolasHug

Description

@NicolasHug

Our UX for converting Dtype and scales is bad and error-prone in V2.

In #7743 we have a sample with an Image and a Mask. We need to:

  • convert the image from uint8 to float and convert its scale from 0-255 to 0-1
  • convert the mask from uint8 to int64, without converting its scale

The only way I found to do that right now is:

            dtype= {
                (datapoints.Image if backend == "datapoint" else torch.Tensor): None,
                datapoints.Mask: torch.int64,
            }
            transforms += [T.ToDtype(dtype=dtype)]
            transforms += [T.ConvertDtype(dtype=torch.float)]

We should at the very least:

  • Clearly distinguish between ConvertDtype and ToDtype. It should be absolutely clear that ConvertDtype also scales the values. ConvertDtypeAndScale() is a decent candidate. Any new name is probably an improvement on the status quo.
  • Not error when (datapoints.Image if backend == "datapoint" else torch.Tensor): None, isn't passed. If I'm not converting a type, I shouldn't have to pass it as input.

Ideally I think we can get rid of ConvertDtype and just add a scale parameter to ToDtype():

  • scale=False means no scaling happens
  • scale=True means all transformed inputs are scaled into the range specified by their dtype
  • scale=Image means only Image instances are scaled
  • scale=(Image, Mask) means only Images and Masks instances are scaled.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions