{"record":{"id":"d2f3ab04b4ddb877","repo":"tensorflow/models","slug":"the-last-dimension-of-predicted-scores-should-be-d","errorCode":null,"errorMessage":"The last dimension of predicted scores should be divisible by {num_anchors_per_locations}.","messagePattern":"The last dimension of predicted scores should be divisible by (.+?)\\.","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"official/vision/modeling/layers/detection_generator.py","lineNumber":850,"sourceCode":"  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):\n    scores.append(tf.reshape(raw_scores[str(i)], [batch_size, -1, num_classes]))\n    boxes.append(tf.reshape(raw_boxes[str(i)], [batch_size, -1, 4]))\n    anchors.append(tf.reshape(anchor_boxes[str(i)], [-1, 4]))\n  scores = tf.sigmoid(tf.concat(scores, 1))\n  boxes = tf.concat(boxes, 1)\n  anchors = tf.concat(anchors, 0)\n\n  ycenter_a = (anchors[..., 0] + anchors[..., 2]) / 2\n  xcenter_a = (anchors[..., 1] + anchors[..., 3]) / 2","sourceCodeStart":832,"sourceCodeEnd":868,"githubUrl":"https://github.com/tensorflow/models/blob/e006f5f0d534913e49c1f1dae87364039fa607e2/official/vision/modeling/layers/detection_generator.py#L832-L868","documentation":"Error \"The last dimension of predicted scores should be divisible by {num_anchors_per_locations}.\" thrown in tensorflow/models.","triggerScenarios":"Thrown at official/vision/modeling/layers/detection_generator.py:850 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Make the last dimension of the predicted scores divisible by num_anchors_per_locations.","Check the score prediction head and anchor configuration so scores align with anchors per location."],"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"}