code: def to_tensor(pic) -> Tensor:
      """Convert a ``PIL Image`` or ``numpy.ndarray`` to tensor.
      This function does not support torchscript.
  
      See :class:`~torchvision.transforms.ToTensor` for more details.
  
      Args:
          pic (PIL Image or numpy.ndarray): Image to be converted to tensor.
  
      Returns:
          Tensor: Converted image.
      """
      if not torch.jit.is_scripting() and not torch.jit.is_tracing():
          _log_api_usage_once(to_tensor)
      if not (F_pil._is_pil_image(pic) or _is_numpy(pic)):
          raise TypeError(
              f"pic should be PIL Image or ndarray. Got {type(pic)}"
          )
  
      if _is_numpy(pic) and not _is_numpy_image(pic):
          raise ValueError(
              f"pic should be 2/3 dimensional. Got {pic.ndim} dimensions."
          )
  
      default_float_dtype = torch.get_default_dtype()
  
      if isinstance(pic, np.ndarray):
          # handle numpy array
          if pic.ndim == 2:
              pic = pic[:, :, None]
  
          img = torch.from_numpy(pic.transpose((2, 0, 1))).contiguous()
          # backward compatibility
          if isinstance(img, torch.ByteTensor):
              return img.to(dtype=default_float_dtype).div(255)
          else:
              return img
  
      if accimage is not None and isinstance(pic, accimage.Image):
          nppic = np.zeros(
              [pic.channels, pic.height, pic.width], dtype=np.float32
          )
          pic.copyto(nppic)
          return torch.from_numpy(nppic).to(dtype=default_float_dtype)
  
      # handle PIL Image
      mode_to_nptype = {
          "I": np.int32,
          "I;16" if sys.byteorder == "little" else "I;16B": np.int16,
          "F": np.float32,
      }
      img = torch.from_numpy(
          np.array(
              pic, mode_to_nptype.get(pic.mode, np.uint8), copy=True
          )
      )
  
      if pic.mode == "1":
          img = 255 * img
      img = img.view(
          pic.size[1], pic.size[0], F_pil.get_image_num_channels(pic)
      )
      # put it from HWC to CHW format
      img = img.permute((2, 0, 1)).contiguous()
      if isinstance(img, torch.ByteTensor):
          return img.to(dtype=default_float_dtype).div(255)
      else:
          return img
  
imports: import math
  import numbers
  import sys
  import warnings
  from enum import Enum
  from typing import Any, List, Optional, Tuple, Union
  import numpy
  import torch
  from PIL import Image
  from torch import Tensor
  from ..utils import _log_api_usage_once
  from .None import _functional_pil, _functional_tensor
label_desc: Use image node_id 7 for calling a global function with example usage: to_tensor(pic) and returns: torch, img, img, img, img