{"record":{"id":"c232942de9f8b321","repo":"tensorflow/models","slug":"anchors-must-be-rank-2-or-3-got","errorCode":null,"errorMessage":"`anchors` must be rank 2 or 3, got {}","messagePattern":"`anchors` must be rank 2 or 3, got (.+?)","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"official/vision/ops/iou_similarity.py","lineNumber":144,"sourceCode":"    Input shape:\n      boxes_1: [N, 4], or [B, N, 4]\n      boxes_2: [M, 4], or [B, M, 4]\n      boxes_1_masks: [N, 1], or [B, N, 1]\n      boxes_2_masks: [M, 1], or [B, M, 1]\n\n    Output shape:\n      [M, N], or [B, M, N]\n    \"\"\"\n    boxes_1 = tf.cast(boxes_1, tf.float32)\n    boxes_2 = tf.cast(boxes_2, tf.float32)\n\n    boxes_1_rank = len(boxes_1.shape)\n    boxes_2_rank = len(boxes_2.shape)\n    if boxes_1_rank < 2 or boxes_1_rank > 3:\n      raise ValueError(\n          '`groudtruth_boxes` must be rank 2 or 3, got {}'.format(boxes_1_rank))\n    if boxes_2_rank < 2 or boxes_2_rank > 3:\n      raise ValueError(\n          '`anchors` must be rank 2 or 3, got {}'.format(boxes_2_rank))\n    if boxes_1_rank < boxes_2_rank:\n      raise ValueError('`groundtruth_boxes` is unbatched while `anchors` is '\n                       'batched is not a valid use case, got groundtruth_box '\n                       'rank {}, and anchors rank {}'.format(\n                           boxes_1_rank, boxes_2_rank))\n\n    result = iou(boxes_1, boxes_2)\n    if boxes_1_masks is None and boxes_2_masks is None:\n      return result\n    background_mask = None\n    mask_val_t = tf.cast(self.mask_val, result.dtype) * tf.ones_like(result)\n    perm = [1, 0] if boxes_2_rank == 2 else [0, 2, 1]\n    if boxes_1_masks is not None and boxes_2_masks is not None:\n      background_mask = tf.logical_or(boxes_1_masks,\n                                      tf.transpose(boxes_2_masks, perm))\n    elif boxes_1_masks is not None:\n      background_mask = boxes_1_masks","sourceCodeStart":126,"sourceCodeEnd":162,"githubUrl":"https://github.com/tensorflow/models/blob/e006f5f0d534913e49c1f1dae87364039fa607e2/official/vision/ops/iou_similarity.py#L126-L162","documentation":"Error \"`anchors` must be rank 2 or 3, got {}\" thrown in tensorflow/models.","triggerScenarios":"Thrown at official/vision/ops/iou_similarity.py:144 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Pass anchors as a rank-2 [num_anchors, 4] or rank-3 [batch, num_anchors, 4] tensor.","Add the batch dimension or squeeze extra dimensions to reach rank 2 or 3."],"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"}