code: def draw_rpn_cls_loss(
      pred_dict, image, foreground=True, topn=10, worst=True
  ):
      """
      For each bounding box labeled object. We want to display the softmax score.
  
      We display the anchors, and not the adjusted bounding boxes.
      """
      loss = pred_dict["rpn_prediction"]["cross_entropy_per_anchor"]
      type_str = "foreground" if foreground else "background"
      logger.debug(
          "RPN classification loss (anchors, with the softmax score) "
          "(mean softmax loss (all): {})".format(loss.mean())
      )
      logger.debug("Showing {} only".format(type_str))
      logger.debug(
          "{} {} performers".format("Worst" if worst else "Best", topn)
      )
      prob = pred_dict["rpn_prediction"]["rpn_cls_prob"]
      prob = prob.reshape([-1, 2])[:, 1]
      target = pred_dict["rpn_prediction"]["rpn_cls_target"]
      anchors = pred_dict["all_anchors"]
      gt_bboxes = pred_dict["gt_bboxes"]
  
      non_ignored_indices = target >= 0
      target = target[non_ignored_indices]
      prob = prob[non_ignored_indices]
      anchors = anchors[non_ignored_indices]
  
      # Get anchors with positive label.
      if foreground:
          positive_indices = np.nonzero(target > 0)[0]
      else:
          positive_indices = np.nonzero(target == 0)[0]
  
      loss = loss[positive_indices]
      prob = prob[positive_indices]
      anchors = anchors[positive_indices]
  
      logger.debug("Mean loss for {}: {}".format(type_str, loss.mean()))
  
      sorted_idx = loss.argsort()
      if worst:
          sorted_idx = sorted_idx[::-1]
  
      sorted_idx = sorted_idx[:topn]
  
      loss = loss[sorted_idx]
      prob = prob[sorted_idx]
      anchors = anchors[sorted_idx]
  
      logger.debug(
          "Mean loss for displayed {}: {}".format(type_str, loss.mean())
      )
  
      image_pil, draw = get_image_draw(image)
  
      for anchor_prob, anchor, anchor_loss in zip(prob, anchors, loss):
          anchor = list(anchor)
          draw.rectangle(
              anchor, fill=(0, 255, 0, 20), outline=(0, 255, 0, 100)
          )
          draw.text(
              tuple([anchor[0], anchor[1]]),
              text="{:.2f}".format(anchor_loss),
              font=font,
              fill=(0, 0, 0, 255),
          )
  
      for gt_box in gt_bboxes:
          draw.rectangle(
              list(gt_box[:4]),
              fill=(0, 0, 255, 60),
              outline=(0, 0, 255, 150),
          )
  
      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 17 for calling a global function with example usage: draw_rpn_cls_loss(pred_dict, image, foreground, topn, worst) and returns: image_pil