{"record":{"id":"26881d214716a60e","repo":"tensorflow/models","slug":"the-last-dimension-of-predicted-boxes-should-be-di","errorCode":null,"errorMessage":"The last dimension of predicted boxes should be divisible by 4.","messagePattern":"The last dimension of predicted boxes should be divisible by 4\\.","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"official/vision/modeling/layers/detection_generator.py","lineNumber":841,"sourceCode":"  Returns:\n    A (dummy) tuple of (boxes, scores, classess, num_detections).\n\n  Raises:\n    ValueError: If the last dimension of predicted boxes is not divisible by 4,\n      or the last dimension of predicted scores is not divisible by number of\n      anchors per location.\n  \"\"\"\n  scores, boxes, anchors = [], [], []\n  levels = list(raw_scores.keys())\n  min_level = int(min(levels))\n  max_level = int(max(levels))\n  batch_size = tf.shape(raw_scores[str(min_level)])[0]\n\n  num_anchors_per_locations_times_4 = (\n      raw_boxes[str(min_level)].get_shape().as_list()[-1]\n  )\n  if num_anchors_per_locations_times_4 % 4 != 0:\n    raise ValueError(\n        'The last dimension of predicted boxes should be divisible by 4.'\n    )\n\n  num_anchors_per_locations = num_anchors_per_locations_times_4 // 4\n  num_classes_times_anchors_per_location = (\n      raw_scores[str(min_level)].get_shape().as_list()[-1]\n  )\n  if num_classes_times_anchors_per_location % num_anchors_per_locations != 0:\n    raise ValueError(\n        'The last dimension of predicted scores should be divisible by'\n        f' {num_anchors_per_locations}.'\n    )\n  num_classes = (\n      num_classes_times_anchors_per_location // num_anchors_per_locations\n  )\n  config.update({'num_classes': num_classes})\n\n  for i in range(min_level, max_level + 1):","sourceCodeStart":823,"sourceCodeEnd":859,"githubUrl":"https://github.com/tensorflow/models/blob/e006f5f0d534913e49c1f1dae87364039fa607e2/official/vision/modeling/layers/detection_generator.py#L823-L859","documentation":"Raised in _generate_detections_tflite when the predicted boxes' last dimension is not divisible by 4; each anchor contributes exactly 4 coordinates.","triggerScenarios":"Thrown at official/vision/modeling/layers/detection_generator.py:841 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Make the last dimension of the predicted boxes divisible by 4.","Fix the box prediction head so it outputs 4 coordinates per box (times number of classes if per-class)."],"exampleFix":null,"handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"e006f5f0d534913e49c1f1dae87364039fa607e2","analyzedAt":"2026-08-24T14:09:15.576Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}