{"record":{"id":"d226c902f2a053c0","repo":"tensorflow/models","slug":"positive-fraction-should-be-in-range-0-1-receiv-d226c9","errorCode":null,"errorMessage":"positive_fraction should be in range [0,1]. Received: %s.","messagePattern":"positive_fraction should be in range \\[0,1\\]\\. Received: (.+?)\\.","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"official/vision/utils/object_detection/balanced_positive_negative_sampler.py","lineNumber":55,"sourceCode":"from official.vision.utils.object_detection import ops\n\n\nclass BalancedPositiveNegativeSampler(minibatch_sampler.MinibatchSampler):\n  \"\"\"Subsamples minibatches to a desired balance of positives and negatives.\"\"\"\n\n  def __init__(self, positive_fraction=0.5, is_static=False):\n    \"\"\"Constructs a minibatch sampler.\n\n    Args:\n      positive_fraction: desired fraction of positive examples (scalar in [0,1])\n        in the batch.\n      is_static: If True, uses an implementation with static shape guarantees.\n\n    Raises:\n      ValueError: if positive_fraction < 0, or positive_fraction > 1\n    \"\"\"\n    if positive_fraction < 0 or positive_fraction > 1:\n      raise ValueError('positive_fraction should be in range [0,1]. '\n                       'Received: %s.' % positive_fraction)\n    self._positive_fraction = positive_fraction\n    self._is_static = is_static\n\n  def _get_num_pos_neg_samples(self, sorted_indices_tensor, sample_size):\n    \"\"\"Counts the number of positives and negatives numbers to be sampled.\n\n    Args:\n      sorted_indices_tensor: A sorted int32 tensor of shape [N] which contains\n        the signed indices of the examples where the sign is based on the label\n        value. The examples that cannot be sampled are set to 0. It samples\n        at most sample_size*positive_fraction positive examples and remaining\n        from negative examples.\n      sample_size: Size of subsamples.\n\n    Returns:\n      A tuple containing the number of positive and negative labels in the\n      subsample.","sourceCodeStart":37,"sourceCodeEnd":73,"githubUrl":"https://github.com/tensorflow/models/blob/e006f5f0d534913e49c1f1dae87364039fa607e2/official/vision/utils/object_detection/balanced_positive_negative_sampler.py#L37-L73","documentation":"Error \"positive_fraction should be in range [0,1]. Received: %s.\" thrown in tensorflow/models.","triggerScenarios":"Thrown at official/vision/utils/object_detection/balanced_positive_negative_sampler.py:55 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Set positive_fraction to a value within [0, 1].","Fix the sampler config; typical values are around 0.5."],"exampleFix":null,"handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"e006f5f0d534913e49c1f1dae87364039fa607e2","analyzedAt":"2026-08-24T14:09:15.576Z","schemaVersion":2},"datasetVersion":"2026-08-24T17:17:21.512Z"}