tensorflow/models · error · ValueError

The last dimension of predicted boxes should be divisible by

Error message

The last dimension of predicted boxes should be divisible by 4.

What it means

Error "The last dimension of predicted boxes should be divisible by 4." thrown in tensorflow/models.

Source

Thrown at official/vision/modeling/layers/detection_generator.py:841

  Returns:
    A (dummy) tuple of (boxes, scores, classess, num_detections).

  Raises:
    ValueError: If the last dimension of predicted boxes is not divisible by 4,
      or the last dimension of predicted scores is not divisible by number of
      anchors per location.
  """
  scores, boxes, anchors = [], [], []
  levels = list(raw_scores.keys())
  min_level = int(min(levels))
  max_level = int(max(levels))
  batch_size = tf.shape(raw_scores[str(min_level)])[0]

  num_anchors_per_locations_times_4 = (
      raw_boxes[str(min_level)].get_shape().as_list()[-1]
  )
  if num_anchors_per_locations_times_4 % 4 != 0:
    raise ValueError(
        'The last dimension of predicted boxes should be divisible by 4.'
    )

  num_anchors_per_locations = num_anchors_per_locations_times_4 // 4
  num_classes_times_anchors_per_location = (
      raw_scores[str(min_level)].get_shape().as_list()[-1]
  )
  if num_classes_times_anchors_per_location % num_anchors_per_locations != 0:
    raise ValueError(
        'The last dimension of predicted scores should be divisible by'
        f' {num_anchors_per_locations}.'
    )
  num_classes = (
      num_classes_times_anchors_per_location // num_anchors_per_locations
  )
  config.update({'num_classes': num_classes})

  for i in range(min_level, max_level + 1):

View on GitHub (pinned to e006f5f0d5)

Solutions

  1. Make the last dimension of the predicted boxes divisible by 4.
  2. Fix the box prediction head so it outputs 4 coordinates per box (times number of classes if per-class).

When it happens

Trigger: Thrown at official/vision/modeling/layers/detection_generator.py:841 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/26881d214716a60e. Report an issue: GitHub.