class_docstr: Solver for raw tensorflow model.
class_docstr_tok: ["Solver","for","raw","tensorflow","model","."]
docstr: The core part of evaluation.
docstr_tok: ["The","core","part","of","evaluation","."]
code: def eval_or_infer_core(
      self, model, mode
  ):  # pylint: disable=too-many-locals, too-many-branches, too-many-statements
      """The core part of evaluation."""
  
      self.do_eval = bool(mode == utils.EVAL or not self.infer_no_label)
      self.is_multi_output = bool(
          isinstance(model.preds, (tuple, list))
      )
      if self.is_multi_output:
          self.output_num = len(model.preds)
      model_path = self.get_model_path(mode)
      if model_path is None:
          logging.warning("model_path is None!")
          return
  
      with model.sess.graph.as_default():
          model.saver.restore(model.sess, save_path=model_path)
          if self.first_eval:
              model.sess.run(tf.tables_initializer())
              self.first_eval = False
          model.sess.run(model.iterator.initializer)
  
          # Evaluating loop.
          data_size = self.config["data"]["{}_data_size".format(mode)]
          num_batch_every_epoch = int(
              math.ceil(data_size / self.batch_size)
          )
  
          all_fetch_vals = []
  
          logging.info(
              "Total eval data size: {},"
              "batch num per epoch: {}".format(
                  data_size, num_batch_every_epoch
              )
          )
  
          for i in range(num_batch_every_epoch):
              if self.do_eval:
                  if self.is_multi_output:
                      fetch_ops = (
                          model.loss
                          + list(model.logits)
                          + list(model.preds)
                          + list(model.y_ground_truth)
                      )
                  else:
                      fetch_ops = [
                          model.loss,
                          model.logits,
                          model.preds,
                          model.y_ground_truth,
                      ]
              else:
                  fetch_ops = [model.logits, model.preds]
              logging.debug("fetch_ops: {}".format(fetch_ops))
              fetch_vals = model.sess.run(fetch_ops)
  
              end_id = (i + 1) * self.batch_size
  
              if data_size < end_id:
                  logging.debug(
                      "data_size: {}, end_id: {}".format(
                          data_size, end_id
                      )
                  )
                  act_end_id = self.batch_size - end_id + data_size
                  new_fetch_vals = []
                  for fetch_val in fetch_vals:
                      if np.isscalar(fetch_val):
                          new_fetch_vals.append(fetch_val)
                      else:
                          new_fetch_vals.append(fetch_val[:act_end_id])
              else:
                  new_fetch_vals = fetch_vals
  
              all_fetch_vals.append(new_fetch_vals)
  
              if (
                  i % self.print_every == 0
                  or i == num_batch_every_epoch - 1
              ):
                  logging.info(
                      "Evaluation rate of "
                      "progress: [ {:.2%} ]".format(
                          i / (num_batch_every_epoch - 1)
                      )
                  )
  
          all_fetch_nps = []
          for one_fetch_vals in zip(*all_fetch_vals):
              if (
                  len(np.shape(one_fetch_vals[0])) <= 0
              ):  # pylint: disable=len-as-condition
                  one_fetch_np = one_fetch_vals
              else:
                  one_fetch_np = np.concatenate(one_fetch_vals, axis=0)
              all_fetch_nps.append(one_fetch_np)
  
          # reshape for multi-output
          if self.is_multi_output:
              logging.debug(
                  "all_fetch_nps before reshape: {}".format(
                      len(all_fetch_nps)
                  )
              )
              new_all_fetch_nps = []
              sub_fetch_nps = []
              for one_fetch_np in all_fetch_nps:
                  sub_fetch_nps.append(one_fetch_np)
                  if len(sub_fetch_nps) == self.output_num:
                      new_all_fetch_nps.append(sub_fetch_nps)
                      sub_fetch_nps = []
  
              logging.debug(
                  "new_all_fetch_nps after reshape: {}".format(
                      len(new_all_fetch_nps)
                  )
              )
          else:
              new_all_fetch_nps = all_fetch_nps
  
          if self.do_eval:
              _, _, preds_val, y_ground_truth_val = new_all_fetch_nps
              run_metrics(
                  self.config, preds_val, y_ground_truth_val, mode
              )
  
          if mode == utils.INFER:
              if self.do_eval:
                  _, logits_val, preds_val, _ = new_all_fetch_nps
              else:
                  logits_val, preds_val = new_all_fetch_nps
  
              postproc_fn = self.postproc_fn()
              logging.info(postproc_fn)
              if isinstance(postproc_fn, list):
                  for i, one_postproc_fn in enumerate(postproc_fn):
                      predictions = {
                          "logits": logits_val[i],
                          "preds": preds_val[i],
                          "output_index": i,
                      }
                      one_postproc_fn(predictions, log_verbose=False)
              else:
                  predictions = {
                      "logits": logits_val,
                      "preds": preds_val,
                      "output_index": None,
                  }
                  postproc_fn(predictions, log_verbose=False)
  
imports: import re
  import math
  import numpy
  import delta.compat
  from absl import logging
  from delta.utils.solver.base_solver import Solver
  from delta import utils
  from delta.utils.register import registers
  from delta.utils.solver.utils.solver_utils import get_checkpoint_dir
  from delta.utils.solver.utils.solver_utils import get_ckpt_state
  from delta.utils.solver.utils.solver_utils import get_session_conf
  from delta.utils.solver.utils.solver_utils import to_saved_model
  from delta.utils.solver.utils.solver_utils import run_metrics
label_desc: Use image node_id 17 for calling the RawSolver obj's underlying member method code with example usage: obj.eval_or_infer_core(model, mode) without return types