code: def draw_batch_proposals(
      pred_dict, image, display="proposal", top_k=None, draw_all=True
  ):
      tf.logging.debug(
          "Batch proposals (background or foreground) "
          "(score is classification, blue = foreground, "
          "red = background, green = GT)"
      )
      tf.logging.debug(
          "This only displays the images on the batch (256). "
          "The number displayed is the classification score "
          "(green is > 0.5, red <= 0.5)"
      )
      tf.logging.debug(
          "{} are displayed".format(
              "Anchors" if display == "anchor" else "Final proposals"
          )
      )
      scores = pred_dict["rpn_prediction"]["rpn_cls_prob"]
      scores = scores[:, 1]
      bbox_pred = pred_dict["rpn_prediction"]["rpn_bbox_pred"]
      targets = pred_dict["rpn_prediction"]["rpn_cls_target"]
      max_overlaps = pred_dict["rpn_prediction"]["rpn_max_overlap"]
      all_anchors = pred_dict["all_anchors"]
      gt_bboxes = pred_dict["gt_bboxes"]
  
      batch_idx = targets >= 0
      scores = scores[batch_idx]
      bbox_pred = bbox_pred[batch_idx]
      max_overlaps = max_overlaps[batch_idx]
      all_anchors = all_anchors[batch_idx]
      targets = targets[batch_idx]
  
      if top_k:
          top_scores_idx = np.argsort(scores)[::-1][:top_k]
          scores = scores[top_scores_idx]
          bbox_pred = bbox_pred[top_scores_idx]
          max_overlaps = max_overlaps[top_scores_idx]
          all_anchors = all_anchors[top_scores_idx]
          targets = targets[top_scores_idx]
  
      if not draw_all:
          # Only batch foreground.
          foreground_idx = targets > 0
          scores = scores[foreground_idx]
          bbox_pred = bbox_pred[foreground_idx]
          max_overlaps = max_overlaps[foreground_idx]
          all_anchors = all_anchors[foreground_idx]
          targets = targets[foreground_idx]
  
      bboxes = decode(all_anchors, bbox_pred)
  
      image_pil, draw = get_image_draw(image)
  
      for score, proposal, target, max_overlap, anchor in zip(
          scores, bboxes, targets, max_overlaps, all_anchors
      ):
          if (proposal[2] - proposal[0] <= 0) or (
              proposal[3] - proposal[1] <= 0
          ):
              logger.debug(
                  "Ignoring proposal for target {} "
                  "because of negative area => {}".format(
                      target, proposal
                  )
              )
              continue
  
          if target == 1:
              fill = (0, 0, 255, 30)
              if score > 0.8:
                  font_fill = (0, 0, 255, 160)
              else:
                  font_fill = (0, 255, 255, 180)
          else:
              fill = (255, 0, 0, 5)
              if score > 0.8:
                  font_fill = (255, 0, 255, 160)
              else:
                  font_fill = (255, 0, 0, 100)
  
          if score > 0.5:
              outline_fill = (0, 0, 255, 50)
          else:
              outline_fill = (255, 0, 0, 50)
  
          if np.abs(score - 1.0) < 0.05:
              font_txt = "1"
          else:
              font_txt = "{:.2f}".format(score)[1:]
  
          if display == "anchor":
              box = list(anchor)
          else:
              box = list(proposal)
  
          draw.rectangle(box, fill=fill, outline=outline_fill)
          x, y = box[:2]
          x = max(x, 0)
          y = max(y, 0)
  
          score = float(score)
          draw.text(
              tuple([x, y]), text=font_txt, font=font, fill=font_fill
          )
  
      for gt_box in gt_bboxes:
          box = list(gt_box[:4])
          draw.rectangle(
              box, fill=(0, 255, 0, 60), outline=(0, 255, 0, 70)
          )
  
      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 15 for calling a global function with example usage: draw_batch_proposals(pred_dict, image, display, top_k, draw_all) and returns: image_pil