code: def invert(img: Tensor) -> Tensor:
      """Invert the colors of an RGB/grayscale image.
  
      Args:
          img (PIL Image or Tensor): Image to have its colors inverted.
              If img is torch Tensor, it is expected to be in [..., 1 or 3, H, W] format,
              where ... means it can have an arbitrary number of leading dimensions.
              If img is PIL Image, it is expected to be in mode "L" or "RGB".
  
      Returns:
          PIL Image or Tensor: Color inverted image.
      """
      if not torch.jit.is_scripting() and not torch.jit.is_tracing():
          _log_api_usage_once(invert)
      if not isinstance(img, torch.Tensor):
          return F_pil.invert(img)
  
      return F_t.invert(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 36 for calling a global function with example usage: invert(img) and returns: F_t, F_pil