Shortcuts

ToDtype

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

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

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.

Examples using ToDtype:

Getting started with transforms v2

Getting started with transforms v2

Transforms v2: End-to-end object detection/segmentation example

Transforms v2: End-to-end object detection/segmentation example

How to use CutMix and MixUp

How to use CutMix and MixUp

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