{"record":{"id":"d21daf0b139a14ad","repo":"tensorflow/models","slug":"both-image-mean-and-image-std-should-be-set-or","errorCode":null,"errorMessage":"Both `image_mean` and `image_std` should be set or None at the same time.","messagePattern":"Both `image_mean` and `image_std` should be set or None at the same time\\.","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"official/vision/utils/object_detection/visualization_utils.py","lineNumber":441,"sourceCode":"    if image_mean is None and image_std is None:\n      images *= tf.constant(\n          preprocess_ops.STDDEV_RGB, shape=[1, 1, 3], dtype=images.dtype\n      )\n      images += tf.constant(\n          preprocess_ops.MEAN_RGB, shape=[1, 1, 3], dtype=images.dtype\n      )\n    elif image_mean is not None and image_std is not None:\n      if isinstance(image_mean, float) and isinstance(image_std, float):\n        images = images * image_std + image_mean\n      elif isinstance(image_mean, list) and isinstance(image_std, list):\n        images *= tf.constant(image_std, shape=[1, 1, 3], dtype=images.dtype)\n        images += tf.constant(image_mean, shape=[1, 1, 3], dtype=images.dtype)\n      else:\n        raise ValueError(\n            '`image_mean` and `image_std` should be the same type.'\n        )\n    else:\n      raise ValueError(\n          'Both `image_mean` and `image_std` should be set or None at the same '\n          'time.'\n      )\n    return tf.cast(images, dtype=tf.uint8)\n\n  if images.shape[3] > 3:\n    images = images[:, :, :, 0:3]\n  elif images.shape[3] == 1:\n    images = tf.image.grayscale_to_rgb(images)\n\n  images = tf.nest.map_structure(\n      tf.identity,\n      tf.map_fn(\n          _denormalize_images,\n          elems=images,\n          fn_output_signature=tf.TensorSpec(\n              shape=images.shape.as_list()[1:], dtype=tf.uint8\n          ),","sourceCodeStart":423,"sourceCodeEnd":459,"githubUrl":"https://github.com/tensorflow/models/blob/e006f5f0d534913e49c1f1dae87364039fa607e2/official/vision/utils/object_detection/visualization_utils.py#L423-L459","documentation":"Error \"Both `image_mean` and `image_std` should be set or None at the same time.\" thrown in tensorflow/models.","triggerScenarios":"Thrown at official/vision/utils/object_detection/visualization_utils.py:441 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Set both image_mean and image_std, or set both to None.","Provide image_std when image_mean is given, and vice versa."],"exampleFix":null,"handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"e006f5f0d534913e49c1f1dae87364039fa607e2","analyzedAt":"2026-08-24T14:09:15.576Z","schemaVersion":2},"datasetVersion":"2026-08-24T17:17:21.512Z"}