tensorflow/models · error · ValueError
labels must be 1 dimensional, got a tensor of shape %s
Error message
labels must be 1 dimensional, got a tensor of shape %s
What it means
Error "labels must be 1 dimensional, got a tensor of shape %s" thrown in tensorflow/models.
Source
Thrown at official/vision/utils/object_detection/balanced_positive_negative_sampler.py:238
batch_size: desired batch size. If None, keeps all positive samples and
randomly selects negative samples so that the positive sample fraction
matches self._positive_fraction. It cannot be None if is_static is True.
labels: boolean tensor of shape [N] denoting positive(=True) and negative
(=False) examples.
scope: name scope.
Returns:
sampled_idx_indicator: boolean tensor of shape [N], True for entries which
are sampled.
Raises:
ValueError: if labels and indicator are not 1D boolean tensors.
"""
if len(indicator.get_shape().as_list()) != 1:
raise ValueError('indicator must be 1 dimensional, got a tensor of '
'shape %s' % indicator.get_shape())
if len(labels.get_shape().as_list()) != 1:
raise ValueError('labels must be 1 dimensional, got a tensor of '
'shape %s' % labels.get_shape())
if labels.dtype != tf.bool:
raise ValueError('labels should be of type bool. Received: %s' %
labels.dtype)
if indicator.dtype != tf.bool:
raise ValueError('indicator should be of type bool. Received: %s' %
indicator.dtype)
scope = scope or 'BalancedPositiveNegativeSampler'
with tf.name_scope(scope):
if self._is_static:
return self._static_subsample(indicator, batch_size, labels)
else:
# Only sample from indicated samples
negative_idx = tf.logical_not(labels)
positive_idx = tf.logical_and(labels, indicator)
negative_idx = tf.logical_and(negative_idx, indicator)
View on GitHub (pinned to e006f5f0d5)
Solutions
- Pass a 1-D labels tensor (shape [num_boxes]).
- Flatten or reshape the labels tensor to rank 1.
When it happens
Trigger: Thrown at official/vision/utils/object_detection/balanced_positive_negative_sampler.py:238 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/ea451f6ee68af41f.
Report an issue: GitHub.