tensorflow/models · error · ValueError
`image_mean` and `image_std` should be the same type.
Error message
`image_mean` and `image_std` should be the same type.
What it means
Error "`image_mean` and `image_std` should be the same type." thrown in tensorflow/models.
Source
Thrown at official/vision/utils/object_detection/visualization_utils.py:437
for i in range(1, num_classes + 1):
category_index[i] = {'id': i, 'name': str(i)}
def _denormalize_images(images: tf.Tensor) -> tf.Tensor:
if image_mean is None and image_std is None:
images *= tf.constant(
preprocess_ops.STDDEV_RGB, shape=[1, 1, 3], dtype=images.dtype
)
images += tf.constant(
preprocess_ops.MEAN_RGB, shape=[1, 1, 3], dtype=images.dtype
)
elif image_mean is not None and image_std is not None:
if isinstance(image_mean, float) and isinstance(image_std, float):
images = images * image_std + image_mean
elif isinstance(image_mean, list) and isinstance(image_std, list):
images *= tf.constant(image_std, shape=[1, 1, 3], dtype=images.dtype)
images += tf.constant(image_mean, shape=[1, 1, 3], dtype=images.dtype)
else:
raise ValueError(
'`image_mean` and `image_std` should be the same type.'
)
else:
raise ValueError(
'Both `image_mean` and `image_std` should be set or None at the same '
'time.'
)
return tf.cast(images, dtype=tf.uint8)
if images.shape[3] > 3:
images = images[:, :, :, 0:3]
elif images.shape[3] == 1:
images = tf.image.grayscale_to_rgb(images)
images = tf.nest.map_structure(
tf.identity,
tf.map_fn(
_denormalize_images,View on GitHub (pinned to e006f5f0d5)
Solutions
- Make image_mean and image_std the same type (both lists or both floats).
- Convert one of them so their types match.
When it happens
Trigger: Thrown at official/vision/utils/object_detection/visualization_utils.py:437 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/fedca8934478c618.
Report an issue: GitHub.