tensorflow/models · error · ValueError
Number of locations is different.
Error message
Number of locations is different.
What it means
Error "Number of locations is different." thrown in tensorflow/models.
Source
Thrown at official/vision/modeling/layers/detection_generator.py:647
representing classes for detected boxes.
valid_detections: An `int` tf.Tensor of shape [batch_size] only the top
`valid_detections` boxes are valid detections.
Raises:
ValueError if inputs shapes are not valid.
"""
one = tf.constant(1, dtype=scores.dtype)
with tf.name_scope('generate_detections'):
batch_size, num_box_classes, box_locations, sides = (
boxes.get_shape().as_list()
)
if batch_size is None:
batch_size = tf.shape(boxes)[0]
_, num_classes, locations = scores.get_shape().as_list()
if num_box_classes != 1 and num_box_classes != num_classes:
raise ValueError('Boxes should have either 1 class or same as scores.')
if locations != box_locations:
raise ValueError('Number of locations is different.')
if sides != 4:
raise ValueError('Number of sides is incorrect.')
# Selects pre_nms_score_threshold scores before NMS.
boxes, scores = box_ops.filter_boxes_by_scores(
boxes, scores, min_score_threshold=pre_nms_score_threshold
)
# EdgeTPU-friendly class-wise NMS, -1 for invalid.
indices = edgetpu.non_max_suppression_padded(
boxes,
scores,
max_num_detections,
iou_threshold=nms_iou_threshold,
refinements=refinements,
)
# Gather NMS-ed boxes and scores.
safe_indices = tf.nn.relu(indices) # 0 for invalid
invalid_detections = safe_indices - indices # 1 for invalid, 0 for validView on GitHub (pinned to e006f5f0d5)
Solutions
- Ensure boxes and scores have the same number of locations (anchors) along the location axis.
- Regenerate boxes/scores from the same anchors so their shapes agree.
When it happens
Trigger: Thrown at official/vision/modeling/layers/detection_generator.py:647 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/03b4592bfaae50ba.
Report an issue: GitHub.