code: def eval(
      dataset_split,
      config_files,
      watch,
      from_global_step,
      override_params,
      files_per_class,
      max_detections,
  ):
      """Evaluate models using dataset."""
  
      # If the config file is empty, our config will be the base_config for the
      # default model.
      try:
          config = get_config(
              config_files, override_params=override_params
          )
      except KeyError:
          raise KeyError(
              "model.type should be set on the custom config."
          )
  
      if not config.train.job_dir:
          raise KeyError("`job_dir` should be set.")
      if not config.train.run_name:
          raise KeyError("`run_name` should be set.")
  
      # `run_dir` is where the actual checkpoint and logs are located.
      run_dir = os.path.join(
          config.train.job_dir, config.train.run_name
      )
  
      # Only activate debug for if needed for debug visualization mode.
      if not config.train.debug:
          config.train.debug = config.eval.image_vis == "debug"
  
      if config.train.debug or config.train.tf_debug:
          tf.logging.set_verbosity(tf.logging.DEBUG)
      else:
          tf.logging.set_verbosity(tf.logging.INFO)
  
      # Build the dataset tensors, overriding the default dataset split.
      config.dataset.split = dataset_split
  
      # Disable data augmentation.
      config.dataset.data_augmentation = []
  
      # Attempt to get class names, if available.
      classes_file = os.path.join(config.dataset.dir, "classes.json")
      if tf.gfile.Exists(classes_file):
          class_labels = json.load(tf.gfile.GFile(classes_file))
      else:
          class_labels = None
  
      if config.model.type == "fasterrcnn":
          # Override max detections with specified value.
          if config.model.network.with_rcnn:
              config.model.rcnn.proposals.total_max_detections = (
                  max_detections
              )
          else:
              config.model.rpn.proposals.post_nms_top_n = max_detections
  
          # Also overwrite `min_prob_threshold` in order to use all detections.
          config.model.rcnn.proposals.min_prob_threshold = 0.0
      elif config.model.type == "ssd":
          config.model.proposals.total_max_detections = max_detections
          config.model.proposals.min_prob_threshold = 0.0
      else:
          raise ValueError(
              "Model type '{}' not supported".format(config.model.type)
          )
  
      # Only a single run over the dataset to calculate metrics.
      config.train.num_epochs = 1
  
      # Seed setup.
      if config.train.seed:
          tf.set_random_seed(config.train.seed)
  
      # Set pretrained as not training.
      config.model.base_network.trainable = False
  
      model_class = get_model(config.model.type)
      model = model_class(config)
      dataset_class = get_dataset(config.dataset.type)
      dataset = dataset_class(config)
      train_dataset = dataset()
  
      train_image = train_dataset["image"]
      train_objects = train_dataset["bboxes"]
      train_filename = train_dataset["filename"]
  
      # Build the graph of the model to evaluate, retrieving required
      # intermediate tensors.
      prediction_dict = model(train_image, train_objects)
  
      if config.model.type == "ssd" or config.model.network.with_rcnn:
          pred = prediction_dict["classification_prediction"]
          pred_objects = pred["objects"]
          pred_objects_classes = pred["labels"]
          pred_objects_scores = pred["probs"]
      else:
          # Force the num_classes to 1.
          config.model.network.num_classes = 1
  
          pred = prediction_dict["rpn_prediction"]
          pred_objects = pred["proposals"]
          pred_objects_scores = pred["scores"]
          # When using only RPN all classes are 0.
          pred_objects_classes = tf.zeros(
              (tf.shape(pred_objects_scores)[0],), dtype=tf.int32
          )
  
      # Retrieve *all* the losses from the model and calculate their streaming
      # means, so we get the loss over the whole dataset.
      batch_losses = model.loss(prediction_dict, return_all=True)
      losses = {}
      for loss_name, loss_tensor in batch_losses.items():
          loss_mean, _ = tf.metrics.mean(
              loss_tensor,
              name=loss_name,
              metrics_collections="metrics",
              updates_collections="metric_ops",
          )
          full_loss_name = "{}_losses/{}".format(
              dataset_split, loss_name
          )
          losses[full_loss_name] = loss_mean
  
      metric_ops = tf.get_collection("metric_ops")
  
      init_op = tf.group(
          tf.global_variables_initializer(),
          tf.local_variables_initializer(),
      )
  
      # Using a global saver instead of the one for the model.
      saver = tf.train.Saver(sharded=True, allow_empty=True)
  
      # Aggregate the required ops to evaluate into a dict.
      ops = {
          "init_op": init_op,
          "metric_ops": metric_ops,
          "pred_objects": pred_objects,
          "pred_objects_classes": pred_objects_classes,
          "pred_objects_scores": pred_objects_scores,
          "train_objects": train_objects,
          "losses": losses,
          "prediction_dict": prediction_dict,
          "filename": train_filename,
          "train_image": train_image,
      }
  
      metrics_scope = "{}_metrics".format(dataset_split)
  
      # Use global writer for all checkpoints. We don't want to write different
      # files for each checkpoint.
      writer = tf.summary.FileWriter(run_dir)
  
      files_to_visualize = {}
  
      last_global_step = from_global_step
      while True:
          # Get the checkpoint files to evaluate.
          try:
              checkpoints = get_checkpoints(
                  run_dir, last_global_step, last_only=not watch
              )
          except ValueError as e:
              if not watch:
                  tf.logging.error("Missing checkpoint.")
                  raise e
  
              tf.logging.warning(
                  "Missing checkpoint; Checking again in a moment"
              )
              time.sleep(5)
              continue
  
          for checkpoint in checkpoints:
              # Always returned in order, so it's safe to assign directly.
              tf.logging.info(
                  "Evaluating global_step {} using checkpoint '{}'".format(
                      checkpoint["global_step"], checkpoint["file"]
                  )
              )
              try:
                  start = time.time()
                  evaluate_once(
                      config,
                      writer,
                      saver,
                      ops,
                      checkpoint,
                      class_labels=class_labels,
                      metrics_scope=metrics_scope,
                      image_vis=config.eval.image_vis,
                      files_per_class=files_per_class,
                      files_to_visualize=files_to_visualize,
                  )
                  last_global_step = checkpoint["global_step"]
                  tf.logging.info(
                      "Evaluated in {:.2f}s".format(time.time() - start)
                  )
              except tf.errors.NotFoundError:
                  # The checkpoint is not ready yet. It was written in the
                  # checkpoints file, but it still hasn't been completely saved.
                  tf.logging.info(
                      "Checkpoint {} is not ready yet. "
                      "Checking again in a moment.".format(
                          checkpoint["file"]
                      )
                  )
                  time.sleep(5)
                  continue
  
          # If no watching was requested, finish the execution.
          if not watch:
              return
  
          # Sleep for a moment and check for new checkpoints.
          tf.logging.info(
              "All checkpoints evaluated; sleeping for a moment"
          )
          time.sleep(5)
  
file_path: luminoth/luminoth/eval.py
imports: import click
  import json
  import numpy
  import os
  import tensorflow
  import time
  from luminoth.datasets import get_dataset
  from luminoth.models import get_model
  from luminoth.utils.bbox_overlap import bbox_overlap
  from luminoth.utils.config import get_config
  from luminoth.utils.image_vis import image_vis_summaries
label_desc: Use image node_id 1 for calling a global function with example usage: eval(dataset_split, config_files, watch, from_global_step, override_params, files_per_class, max_detections) without return types