code: def image_to_tensor(
      image: np.ndarray, dummy_channels_dim=True
  ) -> torch.Tensor:
      """
      Convert numpy image (RGB, BGR, Grayscale, SAR, Mask image, etc.) to tensor
  
      Args:
          image: A numpy array of [H,W,C] shape
          dummy_channels_dim: If True, and image has [H,W] shape adds dummy channel, so that
              output tensor has shape [1, H, W]
  
      See also:
          rgb_image_from_tensor - To convert tensor image back to RGB with denormalization
          mask_from_tensor
  
      Returns:
          Torch tensor of [C,H,W] or [H,W] shape (dummy_channels_dim=False).
      """
      if len(image.shape) not in {2, 3}:
          raise ValueError(
              f"Image must have shape [H,W] or [H,W,C]. Got image with shape {image.shape}"
          )
  
      if len(image.shape) == 2:
          if dummy_channels_dim:
              image = np.expand_dims(image, 0)
      else:
          # HWC -> CHW
          image = np.moveaxis(image, -1, 0)
      image = np.require(image, requirements="C")
      image = torch.from_numpy(image)
      return image
  
imports: import collections
  import dataclasses
  import functools
  import warnings
  import logging
  from typing import Optional, Sequence, Union, Dict, List, Any, Iterable, Callable
  import numpy
  import torch
  from torch import nn, Tensor
  from torch.utils.data import Dataset, ConcatDataset
  from torch.utils.data.dataloader import default_collate
  from .support import pytorch_toolbelt_deprecated
label_desc: Use image node_id 15 for calling a global function with example usage: image_to_tensor(image, dummy_channels_dim) and returns: image