tensorflow/models · error · ValueError

Boxes shape ({boxes.shape}) last dimension must be 4 to repr

Error message

Boxes shape ({boxes.shape}) last dimension must be 4 to represent [y1, x1, y2, x2] boxes coordinates

What it means

Error "Boxes shape ({boxes.shape}) last dimension must be 4 to represent [y1, x1, y2, x2] boxes coordinates" thrown in tensorflow/models.

Source

Thrown at official/vision/modeling/layers/edgetpu.py:293

  Args:
    boxes: A 2-D+ float `Tensor` of shape `[...batch_dims, num_boxes, 4]`.
    scores: A 1-D+ float `Tensor` of shape `[...batch_dims, num_boxes]`
      representing a single score corresponding to each box (each row of boxes).
    output_size: A scalar integer `Tensor` representing the maximum number of
      boxes to be selected by non-max suppression.
    iou_threshold: A 0-D float tensor representing the threshold for deciding
      whether boxes overlap too much with respect to IOU.
    refinements: A number of extra refinement steps to make result closer to
      original sequencial NMS.

  Returns:
    A 1-D+ integer `Tensor` of shape `[...batch_dims, output_size]` representing
    the selected indices from the boxes tensor and `-1` values for the padding.
  """
  boxes_size = boxes.shape[-2]
  if boxes.shape[-1] != 4:
    raise ValueError(f'Boxes shape ({boxes.shape}) last dimension must be 4 '
                     'to represent [y1, x1, y2, x2] boxes coordinates')
  if scores.shape != boxes.shape[:-1]:
    raise ValueError(f'Boxes shape ({boxes.shape}) and scores shape '
                     f'({scores.shape}) do not match.')
  order = tf.constant(np.arange(boxes_size), dtype=scores.dtype)
  relative_order = _tensor_sum_vectors(order, -order)
  relative_scores = _tensor_sum_vectors(scores, -scores)
  similar = tf.cast(
      _greater(
          _tensor_product_iou(boxes) -
          tf.constant(iou_threshold, dtype=boxes.dtype)), scores.dtype)
  worse = _greater(relative_scores)
  same_later = _and(_same(relative_scores), _greater(relative_order))
  similar_worse_or_same_later = _and(similar, _or(worse, same_later))
  for _ in range(refinements):
    similar_worse_or_same_later = _refine_nms_graph_to_original_algorithm(
        similar_worse_or_same_later)
  prunable = _reduce_or(similar_worse_or_same_later, axis=-1)

View on GitHub (pinned to e006f5f0d5)

Solutions

  1. Pass boxes with last dimension 4, representing [y1, x1, y2, x2].
  2. Fix the box tensor shape; remove any extra trailing dimensions or decode boxes correctly first.

When it happens

Trigger: Thrown at official/vision/modeling/layers/edgetpu.py:293 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/a2c48996d3c0436e. Report an issue: GitHub.