|View source on GitHub|
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.
class BalancedPositiveNegativeSampler: Subsamples minibatches to a desired balance of positives and negatives.
combined_static_and_dynamic_shape(...): Returns a list containing static and dynamic values for the dimensions.
indices_to_dense_vector(...): Creates dense vector with indices set to specific value and rest to zeros.
matmul_gather_on_zeroth_axis(...): Matrix multiplication based implementation of tf.gather on zeroth axis.