MCPcopy Create free account
hub / github.com/DeepRec-AI/DeepRec / test_on_batch

Method test_on_batch

tensorflow/python/keras/engine/training.py:1026–1112  ·  view source on GitHub ↗

Test the model on a single batch of samples. Arguments: x: Input data. It could be: - A Numpy array (or array-like), or a list of arrays (in case the model has multiple inputs). - A TensorFlow tensor, or a list of tensors (in case the model ha

(self, x, y=None, sample_weight=None, reset_metrics=True)

Source from the content-addressed store, hash-verified

1024 return outputs
1025
1026 def test_on_batch(self, x, y=None, sample_weight=None, reset_metrics=True):
1027 """Test the model on a single batch of samples.
1028
1029 Arguments:
1030 x: Input data. It could be:
1031 - A Numpy array (or array-like), or a list of arrays
1032 (in case the model has multiple inputs).
1033 - A TensorFlow tensor, or a list of tensors
1034 (in case the model has multiple inputs).
1035 - A dict mapping input names to the corresponding array/tensors,
1036 if the model has named inputs.
1037 - A `tf.data` dataset.
1038 y: Target data. Like the input data `x`,
1039 it could be either Numpy array(s) or TensorFlow tensor(s).
1040 It should be consistent with `x` (you cannot have Numpy inputs and
1041 tensor targets, or inversely). If `x` is a dataset `y` should
1042 not be specified (since targets will be obtained from the iterator).
1043 sample_weight: Optional array of the same length as x, containing
1044 weights to apply to the model's loss for each sample.
1045 In the case of temporal data, you can pass a 2D array
1046 with shape (samples, sequence_length),
1047 to apply a different weight to every timestep of every sample.
1048 In this case you should make sure to specify
1049 sample_weight_mode="temporal" in compile(). This argument is not
1050 supported when `x` is a dataset.
1051 reset_metrics: If `True`, the metrics returned will be only for this
1052 batch. If `False`, the metrics will be statefully accumulated across
1053 batches.
1054
1055 Returns:
1056 Scalar test loss (if the model has a single output and no metrics)
1057 or list of scalars (if the model has multiple outputs
1058 and/or metrics). The attribute `model.metrics_names` will give you
1059 the display labels for the scalar outputs.
1060
1061 Raises:
1062 ValueError: In case of invalid user-provided arguments.
1063 """
1064 self._assert_compile_was_called()
1065 self._check_call_args('test_on_batch')
1066 if self._experimental_run_tf_function:
1067 outputs = training_v2_utils.test_on_batch(
1068 self, x, y=y, sample_weight=sample_weight,
1069 reset_metrics=reset_metrics)
1070 outputs = (outputs['total_loss'] + outputs['output_losses'] +
1071 outputs['metrics'])
1072 outputs = [
1073 training_v2_utils._non_none_constant_value(v) for v in outputs] # pylint: disable=protected-access
1074 if len(outputs) == 1:
1075 outputs = outputs[0]
1076 return outputs
1077
1078 if (self._distribution_strategy and
1079 distribution_strategy_context.in_cross_replica_context()):
1080 raise NotImplementedError('`test_on_batch` is not supported for models '
1081 'distributed with tf.distribute.Strategy.')
1082 # Validate and standardize user data.
1083 x, y, sample_weights = self._standardize_user_data(

Calls 8

_check_call_argsMethod · 0.95
_make_test_functionMethod · 0.95
reset_metricsMethod · 0.95
as_listMethod · 0.45
test_functionMethod · 0.45

Tested by

no test coverage detected