code: def mask2ndarray(mask):
      """Convert Mask to ndarray..
  
      Args:
          mask (:obj:`BitmapMasks` or :obj:`PolygonMasks` or
          torch.Tensor or np.ndarray): The mask to be converted.
  
      Returns:
          np.ndarray: Ndarray mask of shape (n, h, w) that has been converted
      """
      if isinstance(mask, (BitmapMasks, PolygonMasks)):
          mask = mask.to_ndarray()
      elif isinstance(mask, torch.Tensor):
          mask = mask.detach().cpu().numpy()
      elif not isinstance(mask, np.ndarray):
          raise TypeError(f"Unsupported {type(mask)} data type")
      return mask
  
imports: from functools import partial
  from typing import List, Optional, Sequence, Tuple, Union
  import numpy
  import torch
  from mmengine.structures import InstanceData
  from mmengine.utils import digit_version
  from six.moves import map, zip
  from torch import Tensor
  from torch.autograd import Function
  from torch.nn import functional
  from mmdet.structures import SampleList
  from mmdet.structures.bbox import BaseBoxes, get_box_type, stack_boxes
  from mmdet.structures.mask import BitmapMasks, PolygonMasks
  from mmdet.utils import OptInstanceList
label_desc: Use image node_id 6 for calling a global function with example usage: mask2ndarray(mask) and returns: mask