code: def main(args=None):
      # parse arguments
      if args is None:
          args = sys.argv[1:]
      args = parse_args(args)
  
      # make sure tensorflow is the minimum required version
      check_tf_version()
  
      # optionally choose specific GPU
      if args.gpu:
          setup_gpu(args.gpu)
  
      # make save path if it doesn't exist
      if args.save_path is not None and not os.path.exists(
          args.save_path
      ):
          os.makedirs(args.save_path)
  
      # optionally load config parameters
      if args.config:
          args.config = read_config_file(args.config)
  
      # create the generator
      backbone = models.backbone(args.backbone)
      generator = create_generator(args, backbone.preprocess_image)
  
      # optionally load anchor parameters
      anchor_params = None
      pyramid_levels = None
      if args.config and "anchor_parameters" in args.config:
          anchor_params = parse_anchor_parameters(args.config)
      if args.config and "pyramid_levels" in args.config:
          pyramid_levels = parse_pyramid_levels(args.config)
  
      # load the model
      print("Loading model, this may take a second...")
      model = models.load_model(args.model, backbone_name=args.backbone)
      generator.compute_shapes = make_shapes_callback(model)
  
      # optionally convert the model
      if args.convert_model:
          model = models.convert_model(
              model,
              anchor_params=anchor_params,
              pyramid_levels=pyramid_levels,
          )
  
      # print model summary
      # print(model.summary())
  
      # start evaluation
      if args.dataset_type == "coco":
          from ..utils.coco_eval import evaluate_coco
  
          evaluate_coco(generator, model, args.score_threshold)
      else:
          average_precisions, inference_time = evaluate(
              generator,
              model,
              iou_threshold=args.iou_threshold,
              score_threshold=args.score_threshold,
              max_detections=args.max_detections,
              save_path=args.save_path,
          )
  
          # print evaluation
          total_instances = []
          precisions = []
          for label, (
              average_precision,
              num_annotations,
          ) in average_precisions.items():
              print(
                  "{:.0f} instances of class".format(num_annotations),
                  generator.label_to_name(label),
                  "with average precision: {:.4f}".format(
                      average_precision
                  ),
              )
              total_instances.append(num_annotations)
              precisions.append(average_precision)
  
          if sum(total_instances) == 0:
              print("No test instances found.")
              return
  
          print(
              "Inference time for {:.0f} images: {:.4f}".format(
                  generator.size(), inference_time
              )
          )
  
          print(
              "mAP using the weighted average of precisions among classes: {:.4f}".format(
                  sum(
                      [
                          a * b
                          for a, b in zip(total_instances, precisions)
                      ]
                  )
                  / sum(total_instances)
              )
          )
          print(
              "mAP: {:.4f}".format(
                  sum(precisions) / sum(x > 0 for x in total_instances)
              )
          )
  
file_path: ImageAI/imageai_tf_deprecated/Detection/keras_retinanet/bin/evaluate.py
imports: import argparse
  import os
  import sys
  from ..None import models
  from ..preprocessing.csv_generator import CSVGenerator
  from ..preprocessing.pascal_voc import PascalVocGenerator
  from ..utils.anchors import make_shapes_callback
  from ..utils.config import read_config_file, parse_anchor_parameters, parse_pyramid_levels
  from ..utils.eval import evaluate
  from ..utils.gpu import setup_gpu
  from ..utils.tf_version import check_tf_version
label_desc: Use image node_id 3 for calling a global function with example usage: main(args) without return types