tensorflow/models · error · ValueError
`TargetGather` does not support `labels` with rank larger th
Error message
`TargetGather` does not support `labels` with rank larger than 3, got {} What it means
Error "`TargetGather` does not support `labels` with rank larger than 3, got {}" thrown in tensorflow/models.
Source
Thrown at official/vision/ops/target_gather.py:48
labels: An integer tensor with shape [N, dims] or [B, N, ...] representing
groundtruth labels.
match_indices: An integer tensor with shape [M] or [B, M] representing
match label index.
mask: An boolean tensor with shape [M, dims] or [B, M,...] representing
match labels.
mask_val: An integer to fill in for mask.
Returns:
target: An integer Tensor with shape [M] or [B, M]
Raises:
ValueError: If `labels` is higher than rank 3.
"""
if len(labels.shape) <= 2:
return self._gather_unbatched(labels, match_indices, mask, mask_val)
elif len(labels.shape) == 3:
return self._gather_batched(labels, match_indices, mask, mask_val)
else:
raise ValueError("`TargetGather` does not support `labels` with rank "
"larger than 3, got {}".format(len(labels.shape)))
def _gather_unbatched(self, labels, match_indices, mask, mask_val):
"""Gather based on unbatched labels and boxes."""
num_gt_boxes = tf.shape(labels)[0]
def _assign_when_rows_empty():
if len(labels.shape) > 1:
mask_shape = [match_indices.shape[0], labels.shape[-1]]
else:
mask_shape = [match_indices.shape[0]]
return tf.cast(mask_val, labels.dtype) * tf.ones(
mask_shape, dtype=labels.dtype)
def _assign_when_rows_not_empty():
targets = tf.gather(labels, match_indices)
if mask is None:
return targetsView on GitHub (pinned to e006f5f0d5)
Solutions
- Pass labels with rank <= 3 to TargetGather.
- Reduce the labels rank (merge extra leading axes) before gathering.
When it happens
Trigger: Thrown at official/vision/ops/target_gather.py:48 when the library encounters an invalid state.
Common situations: See trigger scenarios.
AI-assisted analysis of tensorflow/models@e006f5f0d5 (2026-08-24).
Data as JSON: /api/errors/08e6a3a34fd81cdf.
Report an issue: GitHub.