|View source on GitHub|
Implements the standard functionality of AbstractEvaluator APIs.
orbit.StandardEvaluator( eval_dataset, options: Optional[
orbit.StandardEvaluatorOptions] = None )
This class structures evaluation roughly as follows:
state = eval_begin() for _ in range(num_steps): step_outputs = eval_step(eval_iterator) state = eval_reduce(state, step_outputs) return eval_end(state)
eval_end are always done in eager
eval_step may be compiled with
tf.function as determined by
options passed to
eval_reduce is in eager mode if
StandardEvaluatorOptions, but in graph mode if
This class does not support completely evaluating multiple different datasets
(i.e., where every example of each dataset should be processed, as opposed to
running for a fixed number of evaluation steps). A custom
is recommended in this case.
||The current evaluation dataset.|
||Returns the name of this module as passed or determined in the ctor.|
||Sequence of non-trainable variables owned by this module and its submodules.|
Sequence of all sub-modules.
Submodules are modules which are properties of this module, or found as properties of modules which are properties of this module (and so on).
||Sequence of trainable variables owned by this module and its submodules.|
||Sequence of variables owned by this module and its submodules.|
create_eval_loop_fn( has_state: bool )
Creates an eval loop from the current step function and options.
||If the step function has state, state will be kept in the loop.|
|The eval loop function, i.e. wrapper of multiple eval steps.|
eval_begin() -> Any
Called once at the beginning of the evaluation.
This method is always called in eager mode, and is a good place to reset metrics that accumulate values over the course of evaluation.
Note that this method is called before dataset iterator creation.
A value to pass as the
eval_end( *args ) -> Optional[runner.Output]
Called at the end of the evaluation.
Called once at the end of evaluation.
This method is always called in eager mode, and is a good place to get
metric results. The value returned from this function will be returned as-is
evaluate method implementation provided by
The outputs from
The function may return a dictionary of
eval_reduce( state: Optional[Any] = None, step_outputs: Optional[runner.Output] = None ) -> Any
A function to perform per-step reduction on the evaluation outputs.
This is useful for passing state throughout evaluation, especially in cases
where maintaining or accumulating state is hard to accomplish using
tf.metrics.Metric or other
tf.Variable-based approaches. For instance,
it can be used to easily accumulate all per-example losses from the full
evaluation for subsequent processing in
||A state being maintained throughout the evaluation.|
||Outputs from the current evaluation step.|
An output which is passed as the
eval_step( iterator ) -> Any
Implements one step of evaluation.
What a "step" consists of is up to the implementer. When using distribution
strategies, the call to this method takes place in the "cross-replica
context" for generality, to allow e.g. multiple iterator dequeues and calls
Note that if
use_tf_function=True, all the code inside
be compatible with
tf.function tracing (and in particular, any state
self should be avoided). In some cases, non-
tf.function compatible code can be moved to
eval_loop_end, which always execute eagerly.
An output which is passed as
evaluate( num_steps: tf.Tensor ) -> Optional[runner.Output]
num_steps steps of evaluation.
The number of evaluation steps to run. When this is -1,
evaluation proceeds until a call to
The output of
with_name_scope( method )
Decorator to automatically enter the module name scope.
def __call__(self, x):
if not hasattr(self, 'w'):
self.w = tf.Variable(tf.random.normal([x.shape, 3]))
return tf.matmul(x, self.w)
Using the above module would produce
names included the module name:
mod = MyModule()
<tf.Tensor: shape=(1, 3), dtype=float32, numpy=..., dtype=float32)>
<tf.Variable 'my_module/Variable:0' shape=(2, 3) dtype=float32,
||The method to wrap.|
|The original method wrapped such that it enters the module's name scope.|