code: def draw_rpn_bbox_pred_with_target(pred_dict, image, worst=True):
      if worst:
          draw_desc = "worst"
      else:
          draw_desc = "best"
  
      logger.debug(
          "Display prediction vs original for "
          "{} performer or batch.".format(draw_desc)
      )
      logger.debug(
          "green = anchor, magenta = prediction, "
          "red = anchor * target (should be GT)"
      )
      target = pred_dict["rpn_prediction"]["rpn_cls_target"]
      target = target.reshape([-1, 1])
      # Get anchors with positive label.
      positive_indices = np.nonzero(np.squeeze(target) > 0)[0]
      random_indices = np.random.choice(
          np.arange(len(positive_indices)), 5
      )
  
      loss_per_anchor = pred_dict["rpn_prediction"][
          "reg_loss_per_anchor"
      ]
  
      # Get only n random to avoid overloading image.
      positive_indices = positive_indices[random_indices]
      loss_per_anchor = loss_per_anchor[random_indices]
      target = target[positive_indices]
  
      bbox_pred = pred_dict["rpn_prediction"]["rpn_bbox_pred"]
      bbox_pred = bbox_pred.reshape([-1, 4])
      bbox_pred = bbox_pred[positive_indices]
  
      bbox_target = pred_dict["rpn_prediction"]["rpn_bbox_target"]
      bbox_target = bbox_target.reshape([-1, 4])
      bbox_target = bbox_target[positive_indices]
  
      all_anchors = pred_dict["all_anchors"]
      all_anchors = all_anchors[positive_indices]
  
      if worst:
          loss_idx = loss_per_anchor.argmax()
      else:
          loss_idx = loss_per_anchor.argmin()
  
      loss = loss_per_anchor[loss_idx]
      anchor = all_anchors[loss_idx]
      bbox_pred = bbox_pred[loss_idx]
      bbox_target = bbox_target[loss_idx]
  
      bbox = decode(np.array([anchor]), np.array([bbox_pred]))[0]
      gt_box = decode(np.array([anchor]), np.array([bbox_target]))[0]
  
      image_pil, draw = get_image_draw(image)
  
      anchor = list(anchor)
      bbox = list(bbox)
      gt_box = list(gt_box)
      draw.rectangle(
          anchor, fill=(0, 255, 0, 20), outline=(0, 255, 0, 100)
      )
      draw.rectangle(
          bbox, fill=(255, 0, 255, 20), outline=(255, 0, 255, 100)
      )
      draw.rectangle(
          gt_box, fill=(255, 0, 0, 20), outline=(255, 0, 0, 100)
      )
  
      logger.debug("Loss is {}".format(loss))
      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 22 for calling a global function with example usage: draw_rpn_bbox_pred_with_target(pred_dict, image, worst) and returns: image_pil