tensorflow/models · error · ValueError

positive_fraction should be in range [0,1]. Received: %s.

Error message

positive_fraction should be in range [0,1]. Received: %s.

What it means

Error "positive_fraction should be in range [0,1]. Received: %s." thrown in tensorflow/models.

Source

Thrown at official/vision/ops/sampling_ops.py:134

                      tf.stack(indices_shape + params_shape[1:]))


class BalancedPositiveNegativeSampler:
  """Subsamples minibatches to a desired balance of positives and negatives."""

  def __init__(self, positive_fraction=0.5, is_static=False):
    """Constructs a minibatch sampler.

    Args:
      positive_fraction: desired fraction of positive examples (scalar in [0,1])
        in the batch.
      is_static: If True, uses an implementation with static shape guarantees.

    Raises:
      ValueError: if positive_fraction < 0, or positive_fraction > 1
    """
    if positive_fraction < 0 or positive_fraction > 1:
      raise ValueError('positive_fraction should be in range [0,1]. '
                       'Received: %s.' % positive_fraction)
    self._positive_fraction = positive_fraction
    self._is_static = is_static

  @staticmethod
  def subsample_indicator(indicator, num_samples):
    """Subsample indicator vector.

    Given a boolean indicator vector with M elements set to `True`, the function
    assigns all but `num_samples` of these previously `True` elements to
    `False`. If `num_samples` is greater than M, the original indicator vector
    is returned.

    Args:
      indicator: a 1-dimensional boolean tensor indicating which elements
        are allowed to be sampled and which are not.
      num_samples: int32 scalar tensor

View on GitHub (pinned to e006f5f0d5)

Solutions

  1. Set positive_fraction to a value within [0, 1].
  2. Fix the sampler config; typical values are around 0.5.

When it happens

Trigger: Thrown at official/vision/ops/sampling_ops.py:134 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/b5dbe6c289c8c31a. Report an issue: GitHub.