code: def draw_ssd_top_k_anchors_per_gt(pred_dict, image, top_k=5):
      """Generates the top_k anchors for each gt_bbox according to iou"""
      image_pil, draw = get_image_draw(image)
      anchors = pred_dict["all_anchors"]
      gt_bboxes = pred_dict["gt_bboxes"]
      overlaps = bbox_overlap(anchors, gt_bboxes[:, :4])
  
      # We iterate over the columns (gt_boxes) of overlaps, thats why we transpose
      for overlaps_per_gt_box, gt_box in zip(overlaps.T, gt_bboxes):
          # Draw gt box
          draw.rectangle(
              list(gt_box[:4]),
              fill=(0, 0, 255, 60),
              outline=(0, 0, 255, 150),
          )
  
          if top_k < len(overlaps):
              # Get indices of the top_k anchors
              partition_edge = top_k * -1
              top_k_anchors_idx = np.argpartition(
                  overlaps_per_gt_box, partition_edge
              )[partition_edge:]
  
              # Get top_k anchors
              top_k_anchors = anchors[top_k_anchors_idx]
  
              # Get the iou for the top_k anchors
              top_k_overlaps = overlaps_per_gt_box[top_k_anchors_idx]
          else:
              top_k_anchors = anchors
              top_k_overlaps = overlaps_per_gt_box
  
          # Draw best k anchors with regards to overlap (iou)
          for anchor, iou in zip(top_k_anchors, top_k_overlaps):
              # TODO: We should get the iou tresholds from the configfile
              iou_treshold = 0.5
              rectangle_outline = (
                  (0, 255, 0, 100)
                  if iou > iou_treshold
                  else (255, 0, 0, 100)
              )
              draw.rectangle(
                  list(anchor),
                  fill=(0, 0, 0, 0),
                  outline=rectangle_outline,
              )
              x, y = anchor[:2]
              x = max(x, 0)
              y = max(y, 0)
              text_fill = (
                  (30, 30, 30, 100)
                  if iou > iou_treshold
                  else (255, 0, 0, 100)
              )
              draw.text(
                  tuple([x, y]),
                  text=str(iou)[:4],
                  font=font,
                  fill=text_fill,
              )
      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 34 for calling a global function with example usage: draw_ssd_top_k_anchors_per_gt(pred_dict, image, top_k) and returns: image_pil