本文整理匯總了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)
]
示例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
示例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
示例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)