tensorflow/models · error · ValueError

The number of anchors inferred from encoded_boxes and anchor

Error message

The number of anchors inferred from encoded_boxes and anchors are inconsistent: shape[1] of encoded_boxes %s should be equal to the number of anchors: %s.

What it means

Error "The number of anchors inferred from encoded_boxes and anchors are inconsistent: shape[1] of encoded_boxes %s should be equal to the number of anchors: %s." thrown in tensorflow/models.

Source

Thrown at official/vision/utils/object_detection/box_coder.py:139

  Args:
    encoded_boxes: a float32 tensor of shape [batch_size, num_anchors,
      code_size] representing the location of the objects.
    box_coder: a BoxCoder object.
    anchors: a BoxList of anchors used to encode `encoded_boxes`.

  Returns:
    decoded_boxes: a float32 tensor of shape [batch_size, num_anchors,
      coder_size] representing the corners of the objects in the order
      of [y_min, x_min, y_max, x_max].

  Raises:
    ValueError: if batch sizes of the inputs are inconsistent, or if
    the number of anchors inferred from encoded_boxes and anchors are
    inconsistent.
  """
  encoded_boxes.get_shape().assert_has_rank(3)
  if encoded_boxes.get_shape()[1].value != anchors.num_boxes_static():
    raise ValueError(
        'The number of anchors inferred from encoded_boxes'
        ' and anchors are inconsistent: shape[1] of encoded_boxes'
        ' %s should be equal to the number of anchors: %s.' %
        (encoded_boxes.get_shape()[1].value, anchors.num_boxes_static()))

  decoded_boxes = tf.stack([
      box_coder.decode(boxes, anchors).get()
      for boxes in tf.unstack(encoded_boxes)
  ])
  return decoded_boxes

View on GitHub (pinned to e006f5f0d5)

Solutions

  1. Make encoded_boxes shape[1] equal the number of anchors.
  2. Encode boxes against the same anchors you pass to the decoder.

When it happens

Trigger: Thrown at official/vision/utils/object_detection/box_coder.py:139 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/54c59c33a98dd41d. Report an issue: GitHub.