class_docstr: VisionData is the base data object of deepcheck vision used as input to checks and suites.
  
  Parameters
  ----------
  batch_loader :
      A batch_loader which load a batch of data in an iterative manner. Batch loader batch output must be a
      dictionary in BatchOutputFormat format. The batch loader must provide SHUFFLED batches.
  task_type : str
      The task type of the data. can be one of the following: 'classification', 'semantic_segmentation',
      'object_detection', 'other'. For 'other', only image related checks (such as ImagePropertyOutliers) will be run.
  label_map : Dict[int, str], optional
      A dictionary mapping class ids to their names.
  dataset_name: str, optional
      Name of the dataset to use in the displays instead of "Train" or "Test".
  reshuffle_data: bool, default=True
      If True we will attempt to shuffle the batch loader. Only set this to False if the data is already shuffled.
class_docstr_tok: ["VisionData","is","the","base","data","object","of","deepcheck","vision","used","as","input","to","checks","and","suites",".","Parameters","--","--","--","--","--","batch_loader",":","A","batch_loader","which","load","a","batch","of","data","in","an","iterative","manner",".","Batch","loader","batch","output","must","be","a","dictionary","in","BatchOutputFormat","format",".","The","batch","loader","must","provide","SHUFFLED","batches",".","task_type",":","str","The","task","type","of","the","data",".","can","be","one","of","the","following",":","'classification","'",",","'semantic_segmentation","'",",","'object_detection","'",",","'other","'",".","For","'other","'",",","only","image","related","checks","(","such","as","ImagePropertyOutliers",")","will","be","run",".","label_map",":","Dict","[","int",",","str","]",",","optional","A","dictionary","mapping","class","ids","to","their","names",".","dataset_name",":","str",",","optional","Name","of","the","dataset","to","use","in","the","displays","instead","of","``","Train","''","or","``","Test","''",".","reshuffle_data",":","bool",",","default=True","If","True","we","will","attempt","to","shuffle","the","batch","loader",".","Only","set","this","to","False","if","the","data","is","already","shuffled","."]
docstr: Show data from a single batch of this VisionData. Works only inside a notebook.
  
  Parameters
  ----------
  num_images_to_display: int, default = 5
      Number of images to show. Does not show more images than the size of single batch
  show_in_window: bool, default = False
      Whether to open the head display in a new python window. requires pyqt5, pyqtwebengine libraries.
docstr_tok: ["Show","data","from","a","single","batch","of","this","VisionData",".","Works","only","inside","a","notebook",".","Parameters","--","--","--","--","--","num_images_to_display",":","int",",","default","=","5","Number","of","images","to","show",".","Does","not","show","more","images","than","the","size","of","single","batch","show_in_window",":","bool",",","default","=","False","Whether","to","open","the","head","display","in","a","new","python","window",".","requires","pyqt5",",","pyqtwebengine","libraries","."]
code: def head(
      self, num_images_to_display: int = 5, show_in_window: bool = False
  ):
      """Show data from a single batch of this VisionData. Works only inside a notebook.
  
      Parameters
      ----------
      num_images_to_display: int, default = 5
          Number of images to show. Does not show more images than the size of single batch
      show_in_window: bool, default = False
          Whether to open the head display in a new python window. requires pyqt5, pyqtwebengine libraries.
      """
      if not (is_notebook() or is_sphinx()) and show_in_window is False:
          print(
              "head function outside a notebook must use `show_in_window = True`",
              file=sys.stderr,
          )
          return
      if not isinstance(num_images_to_display, int):
          print(
              "num_images_to_display must be an integer",
              file=sys.stderr,
          )
          return
      if num_images_to_display < 1:
          print(
              "num_images_to_display can't be smaller than 1",
              file=sys.stderr,
          )
          return
  
      image_size = (300, 300)
      images = []
      headers_row = []
      rows = [[] for _ in range(num_images_to_display)]
      color_dict = None
      batch = BatchWrapper(
          next(iter(self._batch_loader)),
          self.task_type,
          self.number_of_images_cached,
      )
  
      if self.task_type == TaskType.SEMANTIC_SEGMENTATION:
          # Creating a colors dict to be shared for all images
          num_classes = 0
          if self.has_predictions:
              num_classes = batch.numpy_predictions[0].shape[0]
          elif self.has_labels:
              num_classes = max(
                  np.max(label)
                  for label in batch.numpy_labels[
                      :num_images_to_display
                  ]
              )
  
          color_dict = random_color_dict(num_classes)
  
      if self.has_image_identifiers:
          headers_row.append("<h4>Identifier</h4>")
          for index, image_id in enumerate(
              batch.numpy_image_identifiers[:num_images_to_display]
          ):
              rows[index].append(
                  f'<p style="overflow-wrap: anywhere;font-size:2em;">{image_id}</p>'
              )
  
      if self.has_images:
          headers_row.append("<h4>Images</h4>")
          images = batch.numpy_images[:num_images_to_display]
          for index, image in enumerate(images):
              rows[index].append(
                  prepare_thumbnail(image, size=image_size)
              )
  
      if self.has_labels:
          headers_row.append("<h4>Labels</h4>")
          labels = batch.numpy_labels[:num_images_to_display]
          for index, label in enumerate(labels):
              if self.task_type == TaskType.OBJECT_DETECTION:
                  label_image = draw_bboxes(
                      images[index],
                      label,
                      self.label_map,
                      copy_image=False,
                      border_width=5,
                  )
                  rows[index].append(
                      prepare_thumbnail(label_image, size=image_size)
                  )
              elif self.task_type == TaskType.SEMANTIC_SEGMENTATION:
                  label_image = draw_masks(
                      images[index],
                      label,
                      copy_image=False,
                      color=color_dict,
                  )
                  rows[index].append(
                      prepare_thumbnail(label_image, size=image_size)
                  )
              else:
                  rows[index].append(
                      f'<p style="overflow-wrap: anywhere;font-size:2em;">'
                      f"{self.label_map[label]}</p>"
                  )
  
      if self.has_predictions:
          headers_row.append("<h4>Predictions</h4>")
          predictions = batch.numpy_predictions[:num_images_to_display]
          for index, prediction in enumerate(predictions):
              if self.task_type == TaskType.OBJECT_DETECTION:
                  pred_image = draw_bboxes(
                      images[index],
                      prediction,
                      self.label_map,
                      copy_image=False,
                      color="blue",
                      border_width=5,
                      bbox_notation=DEFAULT_PREDICTION_FORMAT,
                  )
                  rows[index].append(
                      prepare_thumbnail(pred_image, size=image_size)
                  )
              elif self.task_type == TaskType.SEMANTIC_SEGMENTATION:
                  # Convert C,H,W to single mask with all classes of shape H,W
                  prediction = np.argmax(prediction, axis=0)
                  pred_image = draw_masks(
                      images[index],
                      prediction,
                      copy_image=False,
                      color=color_dict,
                  )
                  rows[index].append(
                      prepare_thumbnail(pred_image, size=image_size)
                  )
              else:
                  prediction = np.argmax(prediction)
                  rows[index].append(
                      f'<p style="overflow-wrap: anywhere;font-size:2em;">'
                      f"{self.label_map[prediction]}</p>"
                  )
  
      html = '<div style="display:flex; flex-direction: column; gap: 10px;">'
  
      for row in [headers_row] + rows:
          inner = [
              f'<div style="place-self: center;">{i}</div>' for i in row
          ]
          html += f"""
                  <div style="display: grid; grid-auto-columns: minmax(0, 1fr); grid-auto-flow: column; gap:10px;">
                      {"".join(inner)}
                  </div>
              """
      html += "</div>"
  
      result = HtmlDisplayableResult(html)
      if show_in_window:
          result.show_in_window()
      else:
          return result
  
imports: import sys
  import typing
  from collections import defaultdict
  import numpy
  from typing_extensions import Literal
  from deepchecks.core.errors import DeepchecksValueError, ValidationError
  from deepchecks.core.serialization.html_display import HtmlDisplayableResult
  from deepchecks.utils.ipython import is_notebook, is_sphinx
  from deepchecks.vision.utils.detection_formatters import DEFAULT_PREDICTION_FORMAT
  from deepchecks.vision.utils.image_functions import draw_bboxes, draw_masks, prepare_thumbnail, random_color_dict
  from deepchecks.vision.vision_data import TaskType
  from deepchecks.vision.vision_data.batch_wrapper import BatchWrapper
  from deepchecks.vision.vision_data.format_validators import validate_additional_data_format, validate_embeddings_format, validate_image_identifiers_format, validate_images_format, validate_labels_format, validate_predictions_format
  from deepchecks.vision.vision_data.utils import BatchOutputFormat, LabelMap, get_class_ids_from_numpy_labels, get_class_ids_from_numpy_preds, shuffle_loader
label_desc: Use image node_id 20 for calling the VisionData obj's underlying member method code with example usage: obj.head(num_images_to_display, show_in_window) and returns: result