tensorflow/models · error · ValueError
encoded_boxes.shape[-1] is {:d}, but must be 4.
Error message
encoded_boxes.shape[-1] is {:d}, but must be 4. What it means
Error "encoded_boxes.shape[-1] is {:d}, but must be 4." thrown in tensorflow/models.
Source
Thrown at official/vision/ops/box_ops.py:408
return encoded_boxes
def decode_boxes(encoded_boxes, anchors, weights=None):
"""Decodes boxes.
Args:
encoded_boxes: a tensor whose last dimension is 4 representing the
coordinates of encoded boxes in dy, dx, dh, dw in order.
anchors: a tensor whose shape is the same as, or `broadcastable` to `boxes`,
representing the coordinates of anchors in ymin, xmin, ymax, xmax order.
weights: None or a list of four float numbers used to scale coordinates.
Returns:
decoded_boxes: a tensor whose shape is the same as `boxes` representing the
decoded box targets.
"""
if encoded_boxes.shape[-1] != 4:
raise ValueError(
'encoded_boxes.shape[-1] is {:d}, but must be 4.'
.format(encoded_boxes.shape[-1]))
with tf.name_scope('decode_boxes'):
encoded_boxes = tf.cast(encoded_boxes, dtype=anchors.dtype)
dy, dx, dh, dw = tf.split(encoded_boxes, 4, -1)
if weights:
dy /= weights[0]
dx /= weights[1]
dh /= weights[2]
dw /= weights[3]
dh = tf.math.minimum(dh, BBOX_XFORM_CLIP)
dw = tf.math.minimum(dw, BBOX_XFORM_CLIP)
anchor_ymin, anchor_xmin, anchor_ymax, anchor_xmax = tf.split(
anchors, 4, -1)
anchor_h = anchor_ymax - anchor_ymin
anchor_w = anchor_xmax - anchor_xminView on GitHub (pinned to e006f5f0d5)
Solutions
- Pass encoded_boxes whose last dimension is 4.
- Check the box encoding so each encoded box has exactly 4 values.
When it happens
Trigger: Thrown at official/vision/ops/box_ops.py:408 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/577fa761e658afe0.
Report an issue: GitHub.