class_docstr: This is the Detection Model training class, which allows you to train object detection models
  on image datasets that are in Pascal VOC annotation format, using the YOLOv3.
docstr: 'evaluateModel()' is used to obtain the mAP metrics for your model(s). It accepts the following values:
  
  - model_path ( model file or folder), this value can be the part to your model file or the path to the folder containing all your saved model files
  - json_path ,   this is the path the the 'detection_config.json' file saved for the dataset during the training
  - iou_threshold , this value is used to set the desired 'IoU' to obtain the mAP metrics for your model(s)
  - object_threshold , this is used to set your desired minimum 'class score' to obtain the mAP metrics for your model(s)
  - nms_threshold , this is used to set your desired 'Non-maximum suppresion' to obtain the mAP metrics for your model(s)
  
  :param model_path:
  :param json_path:
  :param batch_size:
  :param iou_threshold:
  :param object_threshold:
  :param nms_threshold:
  :return: list of dictionaries, containing one dict per evaluated model.
      Each dict contains exactly the same metrics that are printed on standard output
docstr_tok: ["'evaluateModel","(",")","'","is","used","to","obtain","the","mAP","metrics","for","your","model","(","s",")",".","It","accepts","the","following","values",":","-","model_path","(","model","file","or","folder",")",",","this","value","can","be","the","part","to","your","model","file","or","the","path","to","the","folder","containing","all","your","saved","model","files","-","json_path",",","this","is","the","path","the","the","'detection_config.json","'","file","saved","for","the","dataset","during","the","training","-","iou_threshold",",","this","value","is","used","to","set","the","desired","'IoU","'","to","obtain","the","mAP","metrics","for","your","model","(","s",")","-","object_threshold",",","this","is","used","to","set","your","desired","minimum","'class","score","'","to","obtain","the","mAP","metrics","for","your","model","(","s",")","-","nms_threshold",",","this","is","used","to","set","your","desired","'Non-maximum","suppresion","'","to","obtain","the","mAP","metrics","for","your","model","(","s",")",":","param","model_path",":",":","param","json_path",":",":","param","batch_size",":",":","param","iou_threshold",":",":","param","object_threshold",":",":","param","nms_threshold",":",":","return",":","list","of","dictionaries",",","containing","one","dict","per","evaluated","model",".","Each","dict","contains","exactly","the","same","metrics","that","are","printed","on","standard","output"]
code: def evaluateModel(
      self,
      model_path,
      json_path,
      batch_size=4,
      iou_threshold=0.5,
      object_threshold=0.2,
      nms_threshold=0.45,
  ):
      """
  
      'evaluateModel()' is used to obtain the mAP metrics for your model(s). It accepts the following values:
  
      - model_path ( model file or folder), this value can be the part to your model file or the path to the folder containing all your saved model files
      - json_path ,   this is the path the the 'detection_config.json' file saved for the dataset during the training
      - iou_threshold , this value is used to set the desired 'IoU' to obtain the mAP metrics for your model(s)
      - object_threshold , this is used to set your desired minimum 'class score' to obtain the mAP metrics for your model(s)
      - nms_threshold , this is used to set your desired 'Non-maximum suppresion' to obtain the mAP metrics for your model(s)
  
      :param model_path:
      :param json_path:
      :param batch_size:
      :param iou_threshold:
      :param object_threshold:
      :param nms_threshold:
      :return: list of dictionaries, containing one dict per evaluated model.
          Each dict contains exactly the same metrics that are printed on standard output
      """
  
      self.__training_mode = False
  
      with open(json_path, "r") as json_file:
          detection_model_json = json.load(json_file)
  
      temp_anchor_array = []
      new_anchor_array = []
  
      temp_anchor_array.append(detection_model_json["anchors"][2])
      temp_anchor_array.append(detection_model_json["anchors"][1])
      temp_anchor_array.append(detection_model_json["anchors"][0])
  
      for aa in temp_anchor_array:
          for aaa in aa:
              new_anchor_array.append(aaa)
  
      self.__model_anchors = new_anchor_array
      self.__model_labels = detection_model_json["labels"]
      self.__num_objects = len(self.__model_labels)
  
      self.__train_batch_size = batch_size
      self.__train_epochs = 100
  
      print("Starting Model evaluation....")
  
      (
          _,
          valid_ints,
          labels,
          max_box_per_image,
      ) = self._create_training_instances(
          self.__train_annotations_folder,
          self.__train_images_folder,
          self.__train_cache_file,
          self.__validation_annotations_folder,
          self.__validation_images_folder,
          self.__validation_cache_file,
          self.__model_labels,
      )
  
      if len(valid_ints) == 0:
          print("Validation samples were not provided.")
          print(
              "Please, check your validation samples are correctly provided:"
          )
          print(
              "\tAnnotations: {}\n\tImages: {}".format(
                  self.__validation_annotations_folder,
                  self.__validation_images_folder,
              )
          )
  
      valid_generator = BatchGenerator(
          instances=valid_ints,
          anchors=self.__model_anchors,
          labels=labels,
          downsample=32,  # ratio between network input's size and network output's size, 32 for YOLOv3
          max_box_per_image=max_box_per_image,
          batch_size=self.__train_batch_size,
          min_net_size=self.__model_min_input_size,
          max_net_size=self.__model_max_input_size,
          shuffle=True,
          jitter=0.0,
          norm=normalize,
      )
  
      results = list()
  
      if os.path.isfile(model_path):
          # model_files must be a list containing the complete path to the files,
          # if a file is given, then the list contains just this file
          model_files = [model_path]
      elif os.path.isdir(model_path):
          # model_files must be a list containing the complete path to the files,
          # if a folder is given, then the list contains the complete path to each file on that folder
          model_files = sorted(
              [
                  os.path.join(model_path, file_name)
                  for file_name in os.listdir(model_path)
              ]
          )
          # sort the files to make sure we're always evaluating them on same order
      else:
          print(
              "model_path must be the path to a .h5 file or a directory. Found {}".format(
                  model_path
              )
          )
          return results
  
      for model_file in model_files:
          if str(model_file).endswith(".h5"):
              try:
                  infer_model = load_model(model_file)
  
                  ###############################
                  #   Run the evaluation
                  ###############################
                  # compute mAP for all the classes
                  average_precisions = evaluate(
                      infer_model,
                      valid_generator,
                      iou_threshold=iou_threshold,
                      obj_thresh=object_threshold,
                      nms_thresh=nms_threshold,
                  )
  
                  result_dict = {
                      "model_file": model_file,
                      "using_iou": iou_threshold,
                      "using_object_threshold": object_threshold,
                      "using_non_maximum_suppression": nms_threshold,
                      "average_precision": dict(),
                      "evaluation_samples": len(valid_ints),
                  }
                  # print the score
                  print("Model File: ", model_file, "\n")
                  print("Evaluation samples: ", len(valid_ints))
                  print("Using IoU: ", iou_threshold)
                  print("Using Object Threshold: ", object_threshold)
                  print(
                      "Using Non-Maximum Suppression: ", nms_threshold
                  )
  
                  for (
                      label,
                      average_precision,
                  ) in average_precisions.items():
                      print(
                          labels[label]
                          + ": {:.4f}".format(average_precision)
                      )
                      result_dict["average_precision"][
                          labels[label]
                      ] = average_precision
  
                  print(
                      "mAP: {:.4f}".format(
                          sum(average_precisions.values())
                          / len(average_precisions)
                      )
                  )
                  result_dict["map"] = sum(
                      average_precisions.values()
                  ) / len(average_precisions)
                  print("===============================")
  
                  results.append(result_dict)
              except Exception as e:
                  print(
                      "skipping the evaluation of {} because following exception occurred: {}".format(
                          model_file, e
                      )
                  )
                  continue
          else:
              print(
                  "skipping the evaluation of {} since it's not a .h5 file".format(
                      model_file
                  )
              )
  
      return results
  
imports: import os
  import re
  import numpy
  import json
  from imageai.Detection.Custom.voc import parse_voc_annotation
  from imageai.Detection.YOLO.yolov3 import yolov3_main, yolov3_train, dummy_loss
  from imageai.Detection.Custom.generator import BatchGenerator
  from imageai.Detection.Custom.utils.utils import normalize, evaluate, makedirs
  from tensorflow.keras.callbacks import ReduceLROnPlateau
  from tensorflow.keras.optimizers import Adam
  from imageai.Detection.Custom.callbacks import CustomModelCheckpoint
  from imageai.Detection.Custom.utils.multi_gpu_model import multi_gpu_model
  from imageai.Detection.Custom.gen_anchors import generateAnchors
  import tensorflow
  from tensorflow.keras.models import load_model
  from tensorflow.keras import Input
  from tensorflow.keras.callbacks import TensorBoard
  import tensorflow.keras.backend
  import cv2
label_desc: Use image node_id 7 for calling the DetectionModelTrainer obj's underlying member method code with example usage: obj.evaluateModel(model_path, json_path, batch_size, iou_threshold, object_threshold, nms_threshold) and returns: results, results