Table of Contents
Shortcuts

# ToDtype

class torchvision.transforms.v2.ToDtype(dtype: Union[dtype, Dict[Union[Type, str], Optional[dtype]]], scale: bool = False)

  [BETA] Converts the input to a specific dtype, optionally scaling the values for images or videos.

  Note

  The ToDtype transform is in Beta stage, and while we do not expect disruptive breaking changes, some APIs may slightly change according to user feedback. Please submit any feedback you may have in this issue: https://github.com/pytorch/vision/issues/6753.

  Note

  `ToDtype(dtype, scale=True)` is the recommended replacement for `ConvertImageDtype(dtype)`.

  Parameters:

    - dtype (`torch.dtype` or dict of `TVTensor` -> `torch.dtype`) – The dtype to convert to. If a `torch.dtype` is passed, e.g. `torch.float32`, only images and videos will be converted to that dtype: this is for compatibility with `ConvertImageDtype`. A dict can be passed to specify per-tv_tensor conversions, e.g. `dtype={tv_tensors.Image: torch.float32, tv_tensors.Mask: torch.int64, "others":None}`. The “others” key can be used as a catch-all for any other tv_tensor type, and `None` means no conversion.

    - scale (bool, optional) – Whether to scale the values for images or videos. See Dtype and expected value range. Default: `False`.

## Docs

Access comprehensive developer documentation for PyTorch

View Docs

## Tutorials

Get in-depth tutorials for beginners and advanced developers

View Tutorials

## Resources

Find development resources and get your questions answered

View Resources

To analyze traffic and optimize your experience, we serve cookies on this site. By clicking or navigating, you agree to allow our usage of cookies. As the current maintainers of this site, Facebook’s Cookies Policy applies. Learn more, including about available controls: Cookies Policy.