{"record":{"id":"7360df1d5d6421f6","repo":"tensorflow/models","slug":"boxes-should-have-either-1-class-or-same-as-scores","errorCode":null,"errorMessage":"Boxes should have either 1 class or same as scores.","messagePattern":"Boxes should have either 1 class or same as scores\\.","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"official/vision/modeling/layers/detection_generator.py","lineNumber":645,"sourceCode":"      between [0, 1].\n    nms_classes: An `int` tf.Tensor of shape [batch_size, max_num_detections]\n      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.","sourceCodeStart":627,"sourceCodeEnd":663,"githubUrl":"https://github.com/tensorflow/models/blob/e006f5f0d534913e49c1f1dae87364039fa607e2/official/vision/modeling/layers/detection_generator.py#L627-L663","documentation":"Error \"Boxes should have either 1 class or same as scores.\" thrown in tensorflow/models.","triggerScenarios":"Thrown at official/vision/modeling/layers/detection_generator.py:645 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Make boxes have either a single class dimension or the same number of classes as scores along the class axis.","Broadcast or tile single-class boxes to match the number of classes in scores."],"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"}