tensorflow/models · error · ValueError

Expected the last dimension of `bbox` has size == 4, but the

Error message

Expected the last dimension of `bbox` has size == 4, but the shape of `bbox` was: %s

What it means

Error "Expected the last dimension of `bbox` has size == 4, but the shape of `bbox` was: %s" thrown in tensorflow/models.

Source

Thrown at official/vision/ops/spatial_transform_ops.py:620

      numbers of channel dimensions.
    bbox: A tensor in shape (batch_size, 4), representing the absolute
      coordinates (ymin, xmin, ymax, xmax) for each bounding box.
    output_size: The size of the output images in (output_h, output_w).

  Returns:
    A tensor in shape (batch_size, output_h, output_w, ...). The result has the
    same dtype as the input if it's float32, float16, bfloat16, otherwise the
    result is float32.
  """
  images_shape = images.get_shape().as_list()
  images_rank = len(images_shape)
  if images_rank < 3:
    raise ValueError(
        'Expected the input images (batch_size, height, width, ...) '
        'has rank >= 3, was: %s' % images_shape)
  bbox_shape = bbox.get_shape().as_list()
  if bbox_shape[-1] != 4:
    raise ValueError(
        'Expected the last dimension of `bbox` has size == 4, but the shape '
        'of `bbox` was: %s' % bbox_shape)

  rank_range = list(range(images_rank))
  extra_dims = images_shape[3:]
  extra_dims_perm = rank_range[3:]
  extra_dims_product = 1
  for d in extra_dims:
    extra_dims_product *= d

  input_h = tf.cast(tf.shape(images)[1], tf.float32)
  input_w = tf.cast(tf.shape(images)[2], tf.float32)
  output_h = output_size[0]
  output_w = output_size[1]

  bbox = tf.cast(bbox, tf.float32)
  # (batch_size, 1)
  bbox_ymin = bbox[:, 0:1]

View on GitHub (pinned to e006f5f0d5)

Solutions

  1. Pass bbox with last dimension of size 4 ([y1, x1, y2, x2]).
  2. Fix the bbox tensor shape before calling this op.

When it happens

Trigger: Thrown at official/vision/ops/spatial_transform_ops.py:620 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/ded888f4d2edcf68. Report an issue: GitHub.