class_docstr: 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)``.
  
  Args:
      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 :class:`~torchvision.transforms.v2.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 :ref:`range_and_dtype`.
          Default: ``False``.
class_docstr_tok: ["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",")","``",".","Args",":","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",":","class",":","`","~torchvision.transforms.v2.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",":","ref",":","`","range_and_dtype","`",".","Default",":","``","False","``","."]
code: def __init__(
      self,
      dtype: Union[
          torch.dtype, Dict[Union[Type, str], Optional[torch.dtype]]
      ],
      scale: bool = False,
  ) -> None:
      super().__init__()
  
      if not isinstance(dtype, (dict, torch.dtype)):
          raise ValueError(
              f"dtype must be a dict or a torch.dtype, got {type(dtype)} instead"
          )
  
      if (
          isinstance(dtype, dict)
          and torch.Tensor in dtype
          and any(
              cls in dtype
              for cls in [tv_tensors.Image, tv_tensors.Video]
          )
      ):
          warnings.warn(
              "Got `dtype` values for `torch.Tensor` and either `tv_tensors.Image` or `tv_tensors.Video`. "
              "Note that a plain `torch.Tensor` will *not* be transformed by this (or any other transformation) "
              "in case a `tv_tensors.Image` or `tv_tensors.Video` is present in the input."
          )
      self.dtype = dtype
      self.scale = scale
  
imports: import warnings
  from typing import Any, Callable, cast, Dict, List, Optional, Sequence, Type, Union
  import PIL.Image
  import torch
  from torch.utils._pytree import tree_flatten, tree_unflatten
  from torchvision import transforms, tv_tensors
  from torchvision.transforms.v2 import functional, Transform
  from ._utils import _parse_labels_getter, _setup_number_or_seq, _setup_size, get_bounding_boxes, has_any, is_pure_tensor
label_desc: Use image node_id 1 to create a new ToDtype object from inherited base classes: Transform with example: obj = ToDtype(dtype, scale)