class_docstr: Custom evaluator.
class_docstr_tok: ["Custom","evaluator","."]
docstr: Evaluate over validation iterator.
docstr_tok: ["Evaluate","over","validation","iterator","."]
code: def evaluate(self):
      """Evaluate over validation iterator."""
      iterator = self._iterators["main"]
  
      if self.eval_hook:
          self.eval_hook(self)
  
      if hasattr(iterator, "reset"):
          iterator.reset()
          it = iterator
      else:
          it = copy.copy(iterator)
  
      summary = chainer.reporter.DictSummary()
  
      self.model.eval()
      with torch.no_grad():
          for batch in it:
              if isinstance(batch, tuple):
                  x = tuple(arr.to(self.device) for arr in batch)
              else:
                  x = batch
                  for key in x.keys():
                      x[key] = x[key].to(self.device)
              observation = {}
              with chainer.reporter.report_scope(observation):
                  # convert to torch tensor
                  if isinstance(x, tuple):
                      self.model(*x)
                  else:
                      self.model(**x)
              summary.add(observation)
      self.model.train()
  
      return summary.compute_mean()
  
imports: import copy
  import json
  import logging
  import math
  import os
  import time
  import chainer
  import kaldiio
  import numpy
  import torch
  from chainer import training
  from chainer.training import extensions
  from espnet.asr.asr_utils import get_model_conf, snapshot_object, torch_load, torch_resume, torch_snapshot
  from espnet.asr.pytorch_backend.asr_init import load_trained_modules
  from espnet.nets.pytorch_backend.nets_utils import pad_list
  from espnet.nets.tts_interface import TTSInterface
  from espnet.utils.dataset import ChainerDataLoader, TransformDataset
  from espnet.utils.deterministic_utils import set_deterministic_pytorch
  from espnet.utils.dynamic_import import dynamic_import
  from espnet.utils.io_utils import LoadInputsAndTargets
  from espnet.utils.training.batchfy import make_batchset
  from espnet.utils.training.evaluator import BaseEvaluator
  from espnet.utils.training.iterators import ShufflingEnabler
  from espnet.utils.training.tensorboard_logger import TensorboardLogger
  from espnet.utils.training.train_utils import check_early_stop, set_early_stop
label_desc: Use image node_id 2 for calling the CustomEvaluator obj's underlying member method code with example usage: obj.evaluate() and returns: summary