当前位置: 首页>>代码示例>>Python>>正文


Python evaluation._StopAfterNEvalsHook方法代码示例

本文整理汇总了Python中tensorflow.python.training.evaluation._StopAfterNEvalsHook方法的典型用法代码示例。如果您正苦于以下问题:Python evaluation._StopAfterNEvalsHook方法的具体用法?Python evaluation._StopAfterNEvalsHook怎么用?Python evaluation._StopAfterNEvalsHook使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在tensorflow.python.training.evaluation的用法示例。


在下文中一共展示了evaluation._StopAfterNEvalsHook方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: _convert_eval_steps_to_hooks

# 需要导入模块: from tensorflow.python.training import evaluation [as 别名]
# 或者: from tensorflow.python.training.evaluation import _StopAfterNEvalsHook [as 别名]
def _convert_eval_steps_to_hooks(self, steps):
    with self._ctx.with_mode(model_fn_lib.ModeKeys.EVAL) as ctx:
      if ctx.is_running_on_cpu():
        return super(TPUEstimator, self)._convert_eval_steps_to_hooks(steps)

    if steps is None:
      raise ValueError('Evaluate `steps` must be set on TPU. Cannot be `None`.')

    util_lib.check_positive_integer(steps, 'Eval steps')

    return [
        evaluation._StopAfterNEvalsHook(  # pylint: disable=protected-access
            num_evals=steps),
        _SetEvalIterationsHook(steps)
    ] 
开发者ID:ymcui,项目名称:Chinese-XLNet,代码行数:17,代码来源:tpu_estimator.py

示例2: _convert_eval_steps_to_hooks

# 需要导入模块: from tensorflow.python.training import evaluation [as 别名]
# 或者: from tensorflow.python.training.evaluation import _StopAfterNEvalsHook [as 别名]
def _convert_eval_steps_to_hooks(self, steps):
    if steps is None:
      return []

    if steps <= 0:
      raise ValueError('Must specify steps > 0, given: {}'.format(steps))
    return [evaluation._StopAfterNEvalsHook(num_evals=steps)]  # pylint: disable=protected-access 
开发者ID:cramerlab,项目名称:boxnet,代码行数:9,代码来源:estimator_v2.py

示例3: _convert_eval_steps_to_hooks

# 需要导入模块: from tensorflow.python.training import evaluation [as 别名]
# 或者: from tensorflow.python.training.evaluation import _StopAfterNEvalsHook [as 别名]
def _convert_eval_steps_to_hooks(self, steps):
    """Create hooks to run correct number of steps in evaluation.

    Args:
      steps: number of steps to run during evaluation.

    Raises:
      ValueError: if steps is less than or equal to zero.

    Returns:
      List of hooks to be passed to the estimator.
    """
    if steps is None:
      return []

    if steps <= 0:
      raise ValueError('Must specify steps > 0, given: {}'.format(steps))

    # The hooks are declared as private in evaluation.py discourage the use
    # by other libraries or open source users. This should be the only usage
    # of the estimator evaluation hooks.
    if self._eval_distribution:
      steps_per_run = getattr(self._eval_distribution.extended, 'steps_per_run',
                              1)
      if steps_per_run > 1:
        return [
            evaluation._MultiStepStopAfterNEvalsHook(  # pylint: disable=protected-access
                num_evals=steps,
                steps_per_run=steps_per_run)
        ]
    return [evaluation._StopAfterNEvalsHook(num_evals=steps)]  # pylint: disable=protected-access 
开发者ID:tensorflow,项目名称:estimator,代码行数:33,代码来源:estimator.py

示例4: evaluate

# 需要导入模块: from tensorflow.python.training import evaluation [as 别名]
# 或者: from tensorflow.python.training.evaluation import _StopAfterNEvalsHook [as 别名]
def evaluate(self, input_fn, steps=None, hooks=None, checkpoint_path=None,
               name=None):
    """Evaluates the model given evaluation data input_fn.

    For each step, calls `input_fn`, which returns one batch of data.
    Evaluates until:
    - `steps` batches are processed, or
    - `input_fn` raises an end-of-input exception (`OutOfRangeError` or
    `StopIteration`).

    Args:
      input_fn: Input function returning a tuple of:
          features - Dictionary of string feature name to `Tensor` or
            `SparseTensor`.
          labels - `Tensor` or dictionary of `Tensor` with labels.
      steps: Number of steps for which to evaluate model. If `None`, evaluates
        until `input_fn` raises an end-of-input exception.
      hooks: List of `SessionRunHook` subclass instances. Used for callbacks
        inside the evaluation call.
      checkpoint_path: Path of a specific checkpoint to evaluate. If `None`, the
        latest checkpoint in `model_dir` is used.
      name: Name of the evaluation if user needs to run multiple evaluations on
        different data sets, such as on training data vs test data. Metrics for
        different evaluations are saved in separate folders, and appear
        separately in tensorboard.

    Returns:
      A dict containing the evaluation metrics specified in `model_fn` keyed by
      name, as well as an entry `global_step` which contains the value of the
      global step for which this evaluation was performed.

    Raises:
      ValueError: If `steps <= 0`.
      ValueError: If no model has been trained, namely `model_dir`, or the
        given `checkpoint_path` is empty.
    """
    hooks = _check_hooks_type(hooks)
    if steps is not None:
      if steps <= 0:
        raise ValueError('Must specify steps > 0, given: {}'.format(steps))
      hooks.append(evaluation._StopAfterNEvalsHook(  # pylint: disable=protected-access
          num_evals=steps))

    return self._evaluate_model(
        input_fn=input_fn,
        hooks=hooks,
        checkpoint_path=checkpoint_path,
        name=name) 
开发者ID:ryfeus,项目名称:lambda-packs,代码行数:50,代码来源:estimator.py


注:本文中的tensorflow.python.training.evaluation._StopAfterNEvalsHook方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。