tensorflow/models · error · ValueError

labels should be of type bool. Received: %s

Error message

labels should be of type bool. Received: %s

What it means

Error "labels should be of type bool. Received: %s" thrown in tensorflow/models.

Source

Thrown at official/vision/utils/object_detection/balanced_positive_negative_sampler.py:241

      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)

        # Sample positive and negative samples separately
        if batch_size is None:
          max_num_pos = tf.reduce_sum(

View on GitHub (pinned to e006f5f0d5)

Solutions

  1. Cast labels to tf.bool before sampling.
  2. Compare labels against a threshold to produce a boolean tensor.

When it happens

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