tensorflow/models · error · ValueError

indicator must be 1 dimensional, got a tensor of shape %s

Error message

indicator must be 1 dimensional, got a tensor of shape %s

What it means

Error "indicator 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:235

    Args:
      indicator: boolean tensor of shape [N] whose True entries can be sampled.
      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)

View on GitHub (pinned to e006f5f0d5)

Solutions

  1. Pass a 1-D indicator tensor (shape [num_boxes]).
  2. Flatten or reshape the indicator tensor to rank 1.

When it happens

Trigger: Thrown at official/vision/utils/object_detection/balanced_positive_negative_sampler.py:235 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/ca8bbef7d36c2410. Report an issue: GitHub.