code: def draw_rcnn_reg_batch_errors(pred_dict, image):
      logger.debug(
          "Show errors in batch used for training classifier regressor."
      )
      logger.debug(
          "blue => GT, green => foreground, "
          "r`regression_loss` - c`classification_loss`."
      )
  
      proposals = pred_dict["rpn_prediction"]["proposals"]
      cls_targets = pred_dict["classification_prediction"]["target"][
          "cls"
      ]
      bbox_offsets_targets = pred_dict["classification_prediction"][
          "target"
      ]["bbox_offsets"]
      bbox_offsets = pred_dict["classification_prediction"][
          "bbox_offsets"
      ]
      gt_bboxes = pred_dict["gt_bboxes"]
  
      batch_idx = np.where(cls_targets >= 0)[0]
  
      proposals = proposals[batch_idx]
      cls_targets = cls_targets[batch_idx]
      bbox_offsets_targets = bbox_offsets_targets[batch_idx]
      bbox_offsets = bbox_offsets[batch_idx]
      cross_entropy_per_proposal = pred_dict[
          "classification_prediction"
      ]["_debug"]["losses"]["cross_entropy_per_proposal"]
  
      foreground_batch_idx = np.where(cls_targets > 0)[0]
  
      proposals = proposals[foreground_batch_idx]
      cls_targets = cls_targets[foreground_batch_idx]
      bbox_offsets_targets = bbox_offsets_targets[foreground_batch_idx]
      bbox_offsets = bbox_offsets[foreground_batch_idx]
      cross_entropy_per_proposal = cross_entropy_per_proposal[
          foreground_batch_idx
      ]
      reg_loss_per_proposal = pred_dict["classification_prediction"][
          "_debug"
      ]["losses"]["reg_loss_per_proposal"]
  
      cls_targets = cls_targets - 1
  
      bbox_offsets_idx_pairs = np.stack(
          np.array(
              [
                  cls_targets * 4,
                  cls_targets * 4 + 1,
                  cls_targets * 4 + 2,
                  cls_targets * 4 + 3,
              ]
          ),
          axis=1,
      )
      bbox_offsets = np.take(
          bbox_offsets, bbox_offsets_idx_pairs.astype(np.int)
      )
  
      bboxes = decode(proposals, bbox_offsets)
  
      image_pil, draw = get_image_draw(image)
  
      for proposal, bbox, cls_target, reg_error, cls_error in zip(
          proposals,
          bboxes,
          cls_targets,
          reg_loss_per_proposal,
          cross_entropy_per_proposal,
      ):
          bbox = list(bbox.astype(int))
          proposal = list(proposal.astype(int))
  
          if cls_target > 0:
              fill = (0, 255, 0, 20)
              outline = (0, 255, 0, 100)
              proposal_fill = (255, 255, 30, 20)
              proposal_outline = (255, 255, 30, 100)
          else:
              fill = (255, 0, 0, 20)
              outline = (255, 0, 0, 100)
              proposal_fill = (255, 30, 255, 20)
              proposal_outline = (255, 30, 255, 100)
  
          draw.rectangle(bbox, fill=fill, outline=outline)
          draw.rectangle(
              proposal, fill=proposal_fill, outline=proposal_outline
          )
          draw.text(
              tuple(bbox[:2]),
              text="r{:.3f} - c{:.2f}".format(reg_error, cls_error),
              font=font,
              fill=(0, 0, 0, 150),
          )
  
          draw.line(
              [(proposal[0], proposal[1]), (bbox[0], bbox[1])],
              fill=(0, 0, 0, 170),
              width=1,
          )
          draw.line(
              [(proposal[2], proposal[1]), (bbox[2], bbox[1])],
              fill=(0, 0, 0, 170),
              width=1,
          )
          draw.line(
              [(proposal[2], proposal[3]), (bbox[2], bbox[3])],
              fill=(0, 0, 0, 170),
              width=1,
          )
          draw.line(
              [(proposal[0], proposal[3]), (bbox[0], bbox[3])],
              fill=(0, 0, 0, 170),
              width=1,
          )
  
      for gt_box in gt_bboxes:
          draw.rectangle(
              list(gt_box[:4]),
              fill=(0, 0, 255, 20),
              outline=(0, 0, 255, 100),
          )
  
      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 25 for calling a global function with example usage: draw_rcnn_reg_batch_errors(pred_dict, image) and returns: image_pil