code: def draw_rcnn_cls_batch_errors(
      pred_dict,
      image,
      foreground=True,
      background=True,
      worst=True,
      n=10,
  ):
      logger.debug(
          "Show the {} classification errors in batch "
          "used for training classifier.".format(
              "worst" if worst else "best"
          )
      )
      logger.debug("blue => GT, green => foreground, red => background")
  
      proposals = pred_dict["rpn_prediction"]["proposals"]
      cls_targets = pred_dict["classification_prediction"]["target"][
          "cls"
      ]
      bbox_offsets_targets = pred_dict["classification_prediction"][
          "target"
      ]["bbox_offsets"]
      gt_bboxes = pred_dict["gt_bboxes"]
      batch_idx = np.where(cls_targets != -1)[0]
  
      proposals = proposals[batch_idx]
      cls_targets = cls_targets[batch_idx]
      bbox_offsets_targets = bbox_offsets_targets[batch_idx]
  
      # Cross entropy per proposal already has >= 0 target
      # batches (not ignored proposals)
      cross_entropy_per_proposal = pred_dict[
          "classification_prediction"
      ]["_debug"]["losses"]["cross_entropy_per_proposal"]
  
      if worst:
          selected_idx = cross_entropy_per_proposal.argsort()[::-1][:n]
      else:
          selected_idx = cross_entropy_per_proposal.argsort()[:n]
  
      cross_entropy_per_proposal = cross_entropy_per_proposal[
          selected_idx
      ]
      proposals = proposals[selected_idx]
      cls_targets = cls_targets[selected_idx]
      bbox_offsets_targets = bbox_offsets_targets[selected_idx]
  
      bboxes = decode(proposals, bbox_offsets_targets)
  
      image_pil, draw = get_image_draw(image)
  
      for bbox, cls_target, error in zip(
          bboxes, cls_targets, cross_entropy_per_proposal
      ):
          bbox = list(bbox.astype(int))
          if cls_target > 0:
              fill = (0, 255, 0, 20)
              outline = (0, 255, 0, 100)
          else:
              fill = (255, 0, 0, 20)
              outline = (255, 0, 0, 100)
  
          draw.rectangle(bbox, fill=fill, outline=outline)
          draw.text(
              tuple(bbox[:2]),
              text="{:.2f}".format(error),
              font=font,
              fill=fill,
          )
  
      for gt_box in gt_bboxes:
          draw.rectangle(
              list(gt_box[:4]),
              fill=(0, 0, 255, 20),
              outline=(0, 0, 255, 100),
          )
          # draw.text(tuple(gt_box[:2]), text=str(gt_box[4]),
          #       font=font, fill=(0, 0, 255, 255))
  
      return image_pil
  
imports: import io
  import numpy
  import os
  import logging
  import PIL.Image
  import PIL.ImageDraw
  import PIL.ImageFont
  import tensorflow
  from .bbox_overlap import bbox_overlap
  from .bbox_transform import decode
  from base64 import b64encode
  from sys import stdout
label_desc: Use image node_id 24 for calling a global function with example usage: draw_rcnn_cls_batch_errors(pred_dict, image, foreground, background, worst, n) and returns: image_pil