<br />

|---|
| [![](https://www.tensorflow.org/images/GitHub-Mark-32px.png) View source on GitHub](https://github.com/tensorflow/models/blob/v2.20.0/official/vision/ops/sampling_ops.py) |

Class to subsample minibatches by balancing positives and negatives.

Subsamples minibatches based on a pre-specified positive fraction in range
\[0,1\]. The class presumes there are many more negatives than positive examples:
if the desired batch_size cannot be achieved with the pre-specified positive
fraction, it fills the rest with negative examples. If this is not sufficient
for obtaining the desired batch_size, it returns fewer examples.

The main function to call is Subsample(self, indicator, labels). For convenience
one can also call SubsampleWeights(self, weights, labels) which is defined in
the minibatch_sampler base class.

When is_static is True, it implements a method that guarantees static shapes.
It also ensures the length of output of the subsample is always batch_size, even
when number of examples set to True in indicator is less than batch_size.

This is originally implemented in TensorFlow Object Detection API.

## Classes

[`class BalancedPositiveNegativeSampler`](https://www.tensorflow.org/api_docs/python/tfm/vision/sampling_ops/BalancedPositiveNegativeSampler): Subsamples minibatches to a desired balance of positives and negatives.

## Functions

[`combined_static_and_dynamic_shape(...)`](https://www.tensorflow.org/api_docs/python/tfm/vision/sampling_ops/combined_static_and_dynamic_shape): Returns a list containing static and dynamic values for the dimensions.

[`indices_to_dense_vector(...)`](https://www.tensorflow.org/api_docs/python/tfm/vision/sampling_ops/indices_to_dense_vector): Creates dense vector with indices set to specific value and rest to zeros.

[`matmul_gather_on_zeroth_axis(...)`](https://www.tensorflow.org/api_docs/python/tfm/vision/sampling_ops/matmul_gather_on_zeroth_axis): Matrix multiplication based implementation of tf.gather on zeroth axis.