tensorflow/models · error · ValueError
For raw image feature, height, width and num_channels fields
Error message
For raw image feature, height, width and num_channels fields are required.
What it means
Error "For raw image feature, height, width and num_channels fields are required." thrown in tensorflow/models.
Source
Thrown at official/vision/data/tf_example_builder.py:128
>>> example_builder.add_encoded_image_feature(
image_bytes, feature_prefix='depth')
Args:
encoded_image: Encoded image string.
image_format: Image format string.
height: Number of rows.
width: Number of columns.
num_channels: Number of channels.
image_source_id: Unique string ID to identify the image.
feature_prefix: Feature prefix for image features.
label: the label or a list of labels for the image.
Returns:
The builder object for subsequent method calls.
"""
if image_format == 'RAW':
if not (height and width and num_channels):
raise ValueError('For raw image feature, height, width and '
'num_channels fields are required.')
if not all((height, width, num_channels, image_format)):
(height, width, num_channels, image_format) = (
image_utils.decode_image_metadata(encoded_image))
else:
image_format = image_utils.validate_image_format(image_format)
feature_key = tf_example_feature_key.EncodedImageFeatureKey(feature_prefix)
# If source ID is not provided, we use hashed encoded image as the source
# ID. Note that we only keep 24 bits to be consistent with the Model Garden
# requirement, which will transform the source ID into float32.
if not image_source_id:
hashed_image = int(hashlib.blake2s(encoded_image).hexdigest(), 16)
image_source_id = _to_bytes(str(hashed_image % ((1 << 24) + 1)))
if label is not None:
self.add_ints_feature(feature_key.label, label)View on GitHub (pinned to e006f5f0d5)
When it happens
Trigger: Thrown at official/vision/data/tf_example_builder.py:128 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/3f48ed80ff353222.
Report an issue: GitHub.