code: def _get_detections(
      generator,
      model,
      score_threshold=0.05,
      max_detections=100,
      save_path=None,
  ):
      """Get the detections from the model using the generator.
  
      The result is a list of lists such that the size is:
          all_detections[num_images][num_classes] = detections[num_detections, 4 + num_classes]
  
      # Arguments
          generator       : The generator used to run images through the model.
          model           : The model to run on the images.
          score_threshold : The score confidence threshold to use.
          max_detections  : The maximum number of detections to use per image.
          save_path       : The path to save the images with visualized detections to.
      # Returns
          A list of lists containing the detections for each image in the generator.
      """
      all_detections = [
          [
              None
              for i in range(generator.num_classes())
              if generator.has_label(i)
          ]
          for j in range(generator.size())
      ]
      all_inferences = [None for i in range(generator.size())]
  
      for i in progressbar.progressbar(
          range(generator.size()), prefix="Running network: "
      ):
          raw_image = generator.load_image(i)
          image, scale = generator.resize_image(raw_image.copy())
          image = generator.preprocess_image(image)
  
          if keras.backend.image_data_format() == "channels_first":
              image = image.transpose((2, 0, 1))
  
          # run network
          start = time.time()
          boxes, scores, labels = model.predict_on_batch(
              np.expand_dims(image, axis=0)
          )[:3]
          inference_time = time.time() - start
  
          # correct boxes for image scale
          boxes /= scale
  
          # select indices which have a score above the threshold
          indices = np.where(scores[0, :] > score_threshold)[0]
  
          # select those scores
          scores = scores[0][indices]
  
          # find the order with which to sort the scores
          scores_sort = np.argsort(-scores)[:max_detections]
  
          # select detections
          image_boxes = boxes[0, indices[scores_sort], :]
          image_scores = scores[scores_sort]
          image_labels = labels[0, indices[scores_sort]]
          image_detections = np.concatenate(
              [
                  image_boxes,
                  np.expand_dims(image_scores, axis=1),
                  np.expand_dims(image_labels, axis=1),
              ],
              axis=1,
          )
  
          if save_path is not None:
              draw_annotations(
                  raw_image,
                  generator.load_annotations(i),
                  label_to_name=generator.label_to_name,
              )
              draw_detections(
                  raw_image,
                  image_boxes,
                  image_scores,
                  image_labels,
                  label_to_name=generator.label_to_name,
                  score_threshold=score_threshold,
              )
  
              cv2.imwrite(
                  os.path.join(save_path, "{}.png".format(i)), raw_image
              )
  
          # copy detections to all_detections
          for label in range(generator.num_classes()):
              if not generator.has_label(label):
                  continue
  
              all_detections[i][label] = image_detections[
                  image_detections[:, -1] == label, :-1
              ]
  
          all_inferences[i] = inference_time
  
      return all_detections, all_inferences
  
file_path: ImageAI/imageai_tf_deprecated/Detection/keras_retinanet/utils/eval.py
imports: from .anchors import compute_overlap
  from .visualization import draw_detections, draw_annotations
  from tensorflow import keras
  import numpy
  import os
  import time
  import cv2
  import progressbar
label_desc: Use image node_id 2 for calling a global function with example usage: _get_detections(generator, model, score_threshold, max_detections, save_path) and returns: all_detections,  all_inferences