tensorflow/models · error · ValueError
The output of the given metric must either be a `tf.Tensor`
Error message
The output of the given metric must either be a `tf.Tensor` or a `dict[str, tf.Tensor]`, but got unsupported output: {metric_result}. What it means
Error "The output of the given metric must either be a `tf.Tensor` or a `dict[str, tf.Tensor]`, but got unsupported output: {metric_result}." thrown in tensorflow/models.
Source
Thrown at official/recommendation/uplift/metrics/sliced_metric.py:190
slice_results = [metric.result() for metric in self._sliced_metrics]
if isinstance(metric_result, tf.Tensor):
results = {metric_name: metric_result}
slice_names = (f"{metric_name}/{name}" for name in self._slice_names)
results.update(zip(slice_names, slice_results))
return results
if isinstance(metric_result, dict) and all(
isinstance(result, tf.Tensor) for result in metric_result.values()
):
results = {**metric_result}
for slice_name, slice_result in zip(self._slice_names, slice_results):
result_names, result_values = zip(*slice_result.items())
slice_names = [f"{name}/{slice_name}" for name in result_names]
results.update(zip(slice_names, result_values))
return results
raise ValueError(
"The output of the given metric must either be a `tf.Tensor` or "
"a `dict[str, tf.Tensor]`, but got unsupported output: "
f"{metric_result}."
)
def reset_state(self):
self._metric.reset_state()
for metric in self._sliced_metrics:
metric.reset_state()
def get_config(self):
return {
"name": self.name,
"metric": tf_keras.metrics.serialize(self._metric),
"slicing_spec": dict(zip(self._slice_names, self._slicing_values)),
"slicing_feature_dtype": self._slicing_feature_dtype.name,
}
View on GitHub (pinned to e006f5f0d5)
When it happens
Trigger: Thrown at official/recommendation/uplift/metrics/sliced_metric.py:190 when the library encounters an invalid state.
Common situations: See trigger scenarios.
AI-assisted analysis of tensorflow/models@e006f5f0d5 (2026-08-24).
Data as JSON: /api/errors/76cede0501ebdc82.
Report an issue: GitHub.