{"record":{"id":"13a6bb57bf29e6fe","repo":"tensorflow/models","slug":"len-stddev-must-match-the-number-of-channels","errorCode":null,"errorMessage":"len(stddev) must match the number of channels","messagePattern":"len\\(stddev\\) must match the number of channels","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"official/legacy/image_classification/preprocessing.py","lineNumber":109,"sourceCode":"  Args:\n    image_bytes: a tensor of size [height, width, C].\n    stddev: a C-vector of values to divide from each channel.\n    num_channels: number of color channels in the image that will be distorted.\n    dtype: the dtype to convert the images to. Set to `None` to skip conversion.\n\n  Returns:\n    the centered image.\n\n  Raises:\n    ValueError: If the rank of `image` is unknown, if `image` has a rank other\n      than three or if the number of channels in `image` doesn't match the\n      number of values in `stddev`.\n  \"\"\"\n  if image_bytes.get_shape().ndims != 3:\n    raise ValueError('Input must be of size [height, width, C>0]')\n\n  if len(stddev) != num_channels:\n    raise ValueError('len(stddev) must match the number of channels')\n\n  # We have a 1-D tensor of stddev; convert to 3-D.\n  # Note(b/130245863): we explicitly call `broadcast` instead of simply\n  # expanding dimensions for better performance.\n  stddev = tf.broadcast_to(stddev, tf.shape(image_bytes))\n  if dtype is not None:\n    stddev = tf.cast(stddev, dtype=dtype)\n\n  return image_bytes / stddev\n\n\ndef normalize_images(features: tf.Tensor,\n                     mean_rgb: Tuple[float, ...] = MEAN_RGB,\n                     stddev_rgb: Tuple[float, ...] = STDDEV_RGB,\n                     num_channels: int = 3,\n                     dtype: tf.dtypes.DType = tf.float32,\n                     data_format: Text = 'channels_last') -> tf.Tensor:\n  \"\"\"Normalizes the input image channels with the given mean and stddev.","sourceCodeStart":91,"sourceCodeEnd":127,"githubUrl":"https://github.com/tensorflow/models/blob/e006f5f0d534913e49c1f1dae87364039fa607e2/official/legacy/image_classification/preprocessing.py#L91-L127","documentation":"Error \"len(stddev) must match the number of channels\" thrown in tensorflow/models.","triggerScenarios":"Thrown at official/legacy/image_classification/preprocessing.py:109 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":[],"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"}