Skip to content

ToDtype() also scales tensorsΒ #9033

@hyperkai

Description

@hyperkai

πŸ› Describe the bug

The doc of ToDtype() says that scale parameter is whether to scale the values for images or videos as shown below:

Parameters:

But ToDtype() also scales tensors as shown below:

from torchvision.transforms.v2 import ToDtype
import torch

td = ToDtype(dtype=torch.float32, scale=True)

td(torch.tensor([[0, 1, 2]], dtype=torch.int64))
# tensor([[0.0000e+00, 1.0842e-19, 2.1684e-19]])

td(torch.tensor([[0, 1, 2]], dtype=torch.int32))
# tensor([[0.0000e+00, 4.6566e-10, 9.3132e-10]])

td = ToDtype(dtype=torch.complex64, scale=True)

td(torch.tensor([[0., 1., 2.]], dtype=torch.float32))
td(torch.tensor([[0., 1., 2.]], dtype=torch.float64))
# tensor([[0.0000+0.j, 1.9990+0.j, 3.9980+0.j]])

Versions

import torchvision

torchvision.__version__ # '0.20.1'

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