{"record":{"id":"08e6a3a34fd81cdf","repo":"tensorflow/models","slug":"targetgather-does-not-support-labels-with-rank","errorCode":null,"errorMessage":"`TargetGather` does not support `labels` with rank larger than 3, got {}","messagePattern":"`TargetGather` does not support `labels` with rank larger than 3, got (.+?)","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"official/vision/ops/target_gather.py","lineNumber":48,"sourceCode":"      labels: An integer tensor with shape [N, dims] or [B, N, ...] representing\n        groundtruth labels.\n      match_indices: An integer tensor with shape [M] or [B, M] representing\n        match label index.\n      mask: An boolean tensor with shape [M, dims] or [B, M,...] representing\n        match labels.\n      mask_val: An integer to fill in for mask.\n\n    Returns:\n      target: An integer Tensor with shape [M] or [B, M]\n    Raises:\n      ValueError: If `labels` is higher than rank 3.\n    \"\"\"\n    if len(labels.shape) <= 2:\n      return self._gather_unbatched(labels, match_indices, mask, mask_val)\n    elif len(labels.shape) == 3:\n      return self._gather_batched(labels, match_indices, mask, mask_val)\n    else:\n      raise ValueError(\"`TargetGather` does not support `labels` with rank \"\n                       \"larger than 3, got {}\".format(len(labels.shape)))\n\n  def _gather_unbatched(self, labels, match_indices, mask, mask_val):\n    \"\"\"Gather based on unbatched labels and boxes.\"\"\"\n    num_gt_boxes = tf.shape(labels)[0]\n\n    def _assign_when_rows_empty():\n      if len(labels.shape) > 1:\n        mask_shape = [match_indices.shape[0], labels.shape[-1]]\n      else:\n        mask_shape = [match_indices.shape[0]]\n      return tf.cast(mask_val, labels.dtype) * tf.ones(\n          mask_shape, dtype=labels.dtype)\n\n    def _assign_when_rows_not_empty():\n      targets = tf.gather(labels, match_indices)\n      if mask is None:\n        return targets","sourceCodeStart":30,"sourceCodeEnd":66,"githubUrl":"https://github.com/tensorflow/models/blob/e006f5f0d534913e49c1f1dae87364039fa607e2/official/vision/ops/target_gather.py#L30-L66","documentation":"Error \"`TargetGather` does not support `labels` with rank larger than 3, got {}\" thrown in tensorflow/models.","triggerScenarios":"Thrown at official/vision/ops/target_gather.py:48 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Pass labels with rank <= 3 to TargetGather.","Reduce the labels rank (merge extra leading axes) before gathering."],"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"}