{"record":{"id":"03b4592bfaae50ba","repo":"tensorflow/models","slug":"number-of-locations-is-different","errorCode":null,"errorMessage":"Number of locations is different.","messagePattern":"Number of locations is different\\.","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"official/vision/modeling/layers/detection_generator.py","lineNumber":647,"sourceCode":"      representing classes for detected boxes.\n    valid_detections: An `int` tf.Tensor of shape [batch_size] only the top\n      `valid_detections` boxes are valid detections.\n\n  Raises:\n    ValueError if inputs shapes are not valid.\n  \"\"\"\n  one = tf.constant(1, dtype=scores.dtype)\n  with tf.name_scope('generate_detections'):\n    batch_size, num_box_classes, box_locations, sides = (\n        boxes.get_shape().as_list()\n    )\n    if batch_size is None:\n      batch_size = tf.shape(boxes)[0]\n    _, num_classes, locations = scores.get_shape().as_list()\n    if num_box_classes != 1 and num_box_classes != num_classes:\n      raise ValueError('Boxes should have either 1 class or same as scores.')\n    if locations != box_locations:\n      raise ValueError('Number of locations is different.')\n    if sides != 4:\n      raise ValueError('Number of sides is incorrect.')\n    # Selects pre_nms_score_threshold scores before NMS.\n    boxes, scores = box_ops.filter_boxes_by_scores(\n        boxes, scores, min_score_threshold=pre_nms_score_threshold\n    )\n\n    # EdgeTPU-friendly class-wise NMS, -1 for invalid.\n    indices = edgetpu.non_max_suppression_padded(\n        boxes,\n        scores,\n        max_num_detections,\n        iou_threshold=nms_iou_threshold,\n        refinements=refinements,\n    )\n    # Gather NMS-ed boxes and scores.\n    safe_indices = tf.nn.relu(indices)  # 0 for invalid\n    invalid_detections = safe_indices - indices  # 1 for invalid, 0 for valid","sourceCodeStart":629,"sourceCodeEnd":665,"githubUrl":"https://github.com/tensorflow/models/blob/e006f5f0d534913e49c1f1dae87364039fa607e2/official/vision/modeling/layers/detection_generator.py#L629-L665","documentation":"Error \"Number of locations is different.\" thrown in tensorflow/models.","triggerScenarios":"Thrown at official/vision/modeling/layers/detection_generator.py:647 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","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."],"exampleFix":null,"handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"e006f5f0d534913e49c1f1dae87364039fa607e2","analyzedAt":"2026-08-24T14:09:15.576Z","schemaVersion":2},"datasetVersion":"2026-08-24T17:17:21.512Z"}