code: def draw_sample(
      sample,
      class_map: Optional[ClassMap] = None,
      denormalize_fn: Optional[callable] = None,
      display_label: bool = True,
      display_bbox: bool = True,
      display_score: bool = True,
      display_mask: bool = True,
      display_keypoints: bool = True,
      font_path: Optional[os.PathLike] = DEFAULT_FONT_PATH,
      font_size: Union[int, float] = None,
      label_color: Union[
          np.array, list, tuple, str
      ] = "#C4C4C4",  # Mild Gray
      label_border_color: Union[
          np.array, list, tuple, str
      ] = "#020303",  # Black,
      label_thin_border: bool = True,
      label_pad_width_factor: float = 0.02,
      label_pad_height_factor: float = 0.005,
      mask_blend: float = 0.5,
      mask_border_thickness: int = 7,
      color_map: Optional[dict] = None,  # label -> color mapping
      prettify: bool = True,
      prettify_func: Callable = str.capitalize,
      return_as_pil_img=False,
      # Args for plotting specific labels
      exclude_labels: List[str] = [],
      include_only: List[str] = None,
      multiple_classification_spacing_factor: float = 1.05,
      dynamic_font_size_div_factor: float = 20.0,
      include_classification_task_names: bool = True,
      include_instances_task_names: bool = False,
      force_mask_file_reload: bool = False,
  ) -> Union[np.ndarray, PIL.Image.Image]:
      """
      Selected kwargs:
  
      * label_color: A <collection> of RGB values or a hex code string that defines
                     the color of all the plotted labels
      * label_border_color: Color of the border around the label
      * label_thin_border: Apply a thin border around the label. If false, applies
                           a thick border. If None, applies no border
      * label_pad_width_factor: Amount of padding to apply relative to the image's width.
                                Applies padding to bbox coords if padding bbox
                                labels else to the top-left of the image for classif labels
      * mask_blend: Degree of transparency of the mask. 1 = opaque, 0 = transparent
      * mask_border_thickness: Degree of thickness of the mask. Must be an odd number
      * color_map: An optional dictionary that maps the label => color-value
      * prettify: Format labels based on `prettify_func`
      * prettify_func: A string -> string processing function
      * return_as_pil_image: If true, returns the sample as a PIL image, else np.array
      * exclude_labels: (Optional) List of labels that you'd like to exclude from being plotted
      * include_only: (Optional) List of labels that must be exclusively plotted. Takes
                      precedence over `exclude_labels` (?)
      """
      img = np.asarray(sample.img).copy()  # HACK
      num_classification_plotted = 0
      # Dynamic font size based on image height
      if font_size is None:
          font_size = (
              sample.img_size.height / dynamic_font_size_div_factor
          )
  
      if denormalize_fn is not None:
          img = denormalize_fn(img)
  
      # HACK to visualize segmentation mask
      for task, composite in sample.task_composites.items():
          if task == "segmentation":
              cm = rand_cmap(
                  sample.segmentation.class_map.num_classes,
                  verbose=False,
              )
              if composite.mask_array is None:
                  if isinstance(composite.masks[0], RLE):
                      masks = [
                          mask.to_mask(img.shape[1], img.shape[0]).data
                          for mask in composite.masks
                      ]
                  elif isinstance(composite.masks[0], EncodedRLEs):
                      masks = (
                          composite.masks[0]
                          .to_mask(img.shape[0], img.shape[1])
                          .data
                      )
                  elif isinstance(composite.masks[0], MaskArray):
                      mask = composite.masks[0]
                  else:
                      raise ValueError(
                          "Mask has to be of they RLE, EncodedRLEs or MaskArray."
                      )
              else:
                  mask = composite.mask_array
              return draw_segmentation_mask(
                  img, mask, cm, display_mask=display_mask
              )
  
          # Should break if no ClassMap found in composite.
          #  Should be as the only composite without ClassMap should be
          #  `sample.common`. This is a foundational assumption? #NOTE
          class_map = getattr(composite, "class_map", None)
  
          if composite.get_component_by_type(
              ClassificationLabelsRecordComponent
          ):
              x = 0
              y = (
                  font_size
                  * num_classification_plotted
                  * multiple_classification_spacing_factor
              )
              num_classification_plotted += 1
          else:
              x, y = None, None
  
          # HACK
          if hasattr(composite, "masks"):
              if composite.mask_array is None:
                  if isinstance(composite.masks[0], RLE):
                      masks = [
                          mask.to_mask(img.shape[1], img.shape[0]).data
                          for mask in composite.masks
                      ]
                  elif isinstance(composite.masks[0], MaskFile):
                      if force_mask_file_reload:
                          logger.warning(
                              "Re-creating masks from files, might results in mismatches if transformations were applied"
                          )
                          masks = [
                              mask.to_mask(img.shape[1], img.shape[0])
                              for mask in composite.masks
                          ]
                      else:
                          logger.warning(
                              "Masks are of type MaskFile but will not be loaded to avoid mismatch with transformed data. Set force_mask_file_reload to True to force mask loading"
                          )
                          masks = []
                  elif isinstance(composite.masks[0], EncodedRLEs):
                      masks = (
                          composite.masks[0]
                          .to_mask(img.shape[0], img.shape[1])
                          .data
                      )
                  elif isinstance(composite.masks[0], MaskArray):
                      mask = composite.masks[0]
                  else:
                      raise ValueError(
                          "Mask has to be of they RLE, EncodedRLEs or MaskArray."
                      )
              else:
                  masks = composite.mask_array
          else:
              masks = []
  
          for (
              label,
              bbox,
              mask,
              keypoints,
              score,
          ) in itertools.zip_longest(
              getattr(composite, "labels", []),  # list of strings
              getattr(composite, "bboxes", []),
              masks,
              getattr(composite, "keypoints", []),
              getattr(composite, "scores", []),
          ):
              # random color by default
              color = (np.random.random(3) * 0.6 + 0.4) * 255
  
              # logic for plotting specific labels only
              # `include_only` > `exclude_labels`
              if not label == []:
                  # label_str = (
                  #     class_map.get_by_name(label) if class_map is not None else ""
                  # )
                  if include_only is not None:
                      if not label in include_only:
                          continue
                  elif label in exclude_labels:
                      continue
  
              # if color-map is given and `labels` are predicted
              # then set color accordingly
              if color_map is not None:
                  color = as_rgb_tuple(color_map[label])
                  color = np.array(color).astype(np.float)
              if display_mask and mask is not None:
                  img = draw_mask(
                      img=img,
                      mask=mask,
                      color=color,
                      blend=mask_blend,
                      border_thickness=mask_border_thickness,
                  )
              if display_bbox and bbox is not None:
                  img = draw_bbox(img=img, bbox=bbox, color=color)
              if display_keypoints and keypoints is not None:
                  img = draw_keypoints(
                      img=img, kps=keypoints, color=color
                  )
              if display_label and label is not None:
                  prefix = ""
                  if include_classification_task_names:
                      if composite.get_component_by_type(
                          ClassificationLabelsRecordComponent
                      ):
                          prefix = prettify_func(task) + ": "
                  if include_instances_task_names:
                      if composite.get_component_by_type(
                          InstancesLabelsRecordComponent
                      ):
                          prefix = prettify_func(task) + ": "
  
                  img = draw_label(
                      img=img,
                      label=label,
                      score=score if display_score else None,
                      bbox=bbox,
                      mask=mask,
                      class_map=class_map,
                      color=label_color,
                      border_color=label_border_color,
                      pad_width_factor=label_pad_width_factor,
                      pad_height_factor=label_pad_height_factor,
                      thin_border=label_thin_border,
                      font_size=font_size,
                      font=font_path,
                      prettify=prettify,
                      prettify_func=prettify_func,
                      return_as_pil_img=False,  # should this always be False??
                      prefix=prefix,
                      x=x,
                      y=y,
                  )
      if return_as_pil_img:
          # may or may not be a PIL Image based on `display_label`
          return (
              img
              if isinstance(img, PIL.Image.Image)
              else PIL.Image.fromarray(img)
          )
      else:
          # will be a `np.ndarray` by default so no need for casting
          return img
  
file_path: icevision/icevision/visualize/draw_data.py
imports: from icevision.imports import *
  from icevision.data import *
  from icevision.core import *
  from icevision.visualize.utils import *
  from matplotlib.colors import LinearSegmentedColormap
  from PIL import Image, ImageFont, ImageDraw
  import PIL
label_desc: Use image node_id 1 for calling a global function with example usage: draw_sample(sample, class_map, denormalize_fn, display_label, display_bbox, display_score, display_mask, display_keypoints, font_path, font_size, label_color, label_border_color, label_thin_border, label_pad_width_factor, label_pad_height_factor, mask_blend, mask_border_thickness, color_map, prettify, prettify_func, return_as_pil_img, exclude_labels, include_only, multiple_classification_spacing_factor, dynamic_font_size_div_factor, include_classification_task_names, include_instances_task_names, force_mask_file_reload) and returns: unknown, img, draw_segmentation_mask