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
      """The core part of evaluation."""
      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.
          total_loss = 0.0
          data_size = self.config["data"]["{}_data_size".format(mode)]
          num_batch_every_epoch = int(
              math.ceil(data_size / self.batch_size)
          )
  
          y_ground_truth = []
          y_preds = []
  
          for i in range(num_batch_every_epoch):
              if mode == utils.EVAL:
                  (
                      loss_val,
                      batch_preds,
                      batch_y_ground_truth,
                  ) = model.sess.run(
                      [model.loss, model.preds, model.y_ground_truth]
                  )
              elif not self.infer_no_label:
                  batch_preds, batch_y_ground_truth = model.sess.run(
                      [model.preds, model.y_ground_truth]
                  )
              else:
                  batch_preds = model.sess.run([model.preds])
                  batch_preds = batch_preds[0]
  
              if mode == utils.EVAL:
                  total_loss += loss_val
                  y_preds.append([preds for preds in batch_preds])
              else:
                  end_id = (i + 1) * self.batch_size
  
                  if data_size < end_id:
                      act_end_id = self.batch_size - end_id + data_size
                      batch_preds = batch_preds[:act_end_id]
                      if not self.infer_no_label:
                          batch_y_ground_truth = batch_y_ground_truth[
                              :act_end_id
                          ]
                  y_preds.extend([preds for preds in batch_preds])
  
                  if not self.infer_no_label:
                      y_ground_truth.extend(
                          [
                              ground_truth
                              for ground_truth in batch_y_ground_truth
                          ]
                      )
  
              if i % 10 == 0 or i == num_batch_every_epoch - 1:
                  logging.info(
                      "Evaluation rate of "
                      "progress: [ {:.2%} ]".format(
                          i / (num_batch_every_epoch - 1)
                      )
                  )
  
          if mode == utils.EVAL:
              logging.info(
                  "Evaluation Average Loss: {:.6}".format(
                      total_loss / len(y_preds)
                  )
              )
  
          else:
              predictions = {"preds": y_preds}
              self.postproc_fn()(predictions, log_verbose=False)
  
              if not self.infer_no_label:
                  metcs = metrics.get_metrics(
                      config=self.config,
                      y_pred=y_preds,
                      y_true=y_ground_truth,
                  )
                  logging.info("Evaluation on %s:" % mode)
                  # add sort function to make sequence of metrics identical.
                  for key in sorted(metcs.keys()):
                      logging.info(key + ":" + str(metcs[key]))
  
file_path: delta/delta/utils/solver/raw_seq2seq_solver.py
imports: import math
  import numpy
  import delta.compat
  from absl import logging
  from delta import utils
  from delta.utils import metrics
  from delta.utils.register import registers
  from delta.utils.solver.raw_solver import RawSolver
label_desc: Use image node_id 5 for calling the RawS2SSolver obj's underlying member method code with example usage: obj.eval_or_infer_core(model, mode) without return types