tensorflow/models · error · ValueError

Both `image_mean` and `image_std` should be set or None at t

Error message

Both `image_mean` and `image_std` should be set or None at the same time.

What it means

Error "Both `image_mean` and `image_std` should be set or None at the same time." thrown in tensorflow/models.

Source

Thrown at official/vision/utils/object_detection/visualization_utils.py:441

    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,
          elems=images,
          fn_output_signature=tf.TensorSpec(
              shape=images.shape.as_list()[1:], dtype=tf.uint8
          ),

View on GitHub (pinned to e006f5f0d5)

Solutions

  1. Set both image_mean and image_std, or set both to None.
  2. Provide image_std when image_mean is given, and vice versa.

When it happens

Trigger: Thrown at official/vision/utils/object_detection/visualization_utils.py:441 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/d21daf0b139a14ad. Report an issue: GitHub.