code: def _cast_squeeze_out(
      img: Tensor,
      need_cast: bool,
      need_squeeze: bool,
      out_dtype: torch.dtype,
  ) -> Tensor:
      if need_squeeze:
          img = img.squeeze(dim=0)
  
      if need_cast:
          if out_dtype in (
              torch.uint8,
              torch.int8,
              torch.int16,
              torch.int32,
              torch.int64,
          ):
              # it is better to round before cast
              img = torch.round(img)
          img = img.to(out_dtype)
  
      return img
  
imports: from typing import Any, Callable, Dict, List, Optional, Tuple, Union
  import torch
  import torchvision
  from torch import Tensor
  from torchvision.transforms.functional import InterpolationMode
label_desc: Use image node_id 23 for calling a global function with example usage: _cast_squeeze_out(img, need_cast, need_squeeze, out_dtype) and returns: img