tf.contrib.training.stratified_sample
Stay organized with collections
Save and categorize content based on your preferences.
Stochastically creates batches based on per-class probabilities.
tf.contrib.training.stratified_sample(
tensors, labels, target_probs, batch_size, init_probs=None, enqueue_many=False,
queue_capacity=16, threads_per_queue=1, name=None
)
This method discards examples. Internally, it creates one queue to amortize
the cost of disk reads, and one queue to hold the properly-proportioned
batch.
Args |
tensors
|
List of tensors for data. All tensors are either one item or a
batch, according to enqueue_many.
|
labels
|
Tensor for label of data. Label is a single integer or a batch,
depending on enqueue_many . It is not a one-hot vector.
|
target_probs
|
Target class proportions in batch. An object whose type has a
registered Tensor conversion function.
|
batch_size
|
Size of batch to be returned.
|
init_probs
|
Class proportions in the data. An object whose type has a
registered Tensor conversion function, or None for estimating the
initial distribution.
|
enqueue_many
|
Bool. If true, interpret input tensors as having a batch
dimension.
|
queue_capacity
|
Capacity of the large queue that holds input examples.
|
threads_per_queue
|
Number of threads for the large queue that holds input
examples and for the final queue with the proper class proportions.
|
name
|
Optional prefix for ops created by this function.
|
Raises |
ValueError
|
If tensors isn't iterable.
|
ValueError
|
enqueue_many is True and labels doesn't have a batch
dimension, or if enqueue_many is False and labels isn't a scalar.
|
ValueError
|
enqueue_many is True, and batch dimension on data and labels
don't match.
|
ValueError
|
if probs don't sum to one.
|
ValueError
|
if a zero initial probability class has a nonzero target
probability.
|
TFAssertion
|
if labels aren't integers in [0, num classes).
|
Returns |
(data_batch, label_batch), where data_batch is a list of tensors of the same
length as tensors
|
Example:
Get tensor for a single data and label example.
data, label = data_provider.Get(['data', 'label'])
Get stratified batch according to per-class probabilities.
target_probs = [...distribution you want...]
[data_batch], labels = tf.contrib.training.stratified_sample(
[data], label, target_probs)
Run batch through network.
...
Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2020-10-01 UTC.
[null,null,["Last updated 2020-10-01 UTC."],[],[],null,["# tf.contrib.training.stratified_sample\n\n\u003cbr /\u003e\n\n|------------------------------------------------------------------------------------------------------------------------------------------------------|\n| [View source on GitHub](https://github.com/tensorflow/tensorflow/blob/v1.15.0/tensorflow/contrib/training/python/training/sampling_ops.py#L135-L258) |\n\nStochastically creates batches based on per-class probabilities. \n\n tf.contrib.training.stratified_sample(\n tensors, labels, target_probs, batch_size, init_probs=None, enqueue_many=False,\n queue_capacity=16, threads_per_queue=1, name=None\n )\n\nThis method discards examples. Internally, it creates one queue to amortize\nthe cost of disk reads, and one queue to hold the properly-proportioned\nbatch.\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Args ---- ||\n|---------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------|\n| `tensors` | List of tensors for data. All tensors are either one item or a batch, according to enqueue_many. |\n| `labels` | Tensor for label of data. Label is a single integer or a batch, depending on `enqueue_many`. It is not a one-hot vector. |\n| `target_probs` | Target class proportions in batch. An object whose type has a registered Tensor conversion function. |\n| `batch_size` | Size of batch to be returned. |\n| `init_probs` | Class proportions in the data. An object whose type has a registered Tensor conversion function, or `None` for estimating the initial distribution. |\n| `enqueue_many` | Bool. If true, interpret input tensors as having a batch dimension. |\n| `queue_capacity` | Capacity of the large queue that holds input examples. |\n| `threads_per_queue` | Number of threads for the large queue that holds input examples and for the final queue with the proper class proportions. |\n| `name` | Optional prefix for ops created by this function. |\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Raises ------ ||\n|---------------|----------------------------------------------------------------------------------------------------------------------------|\n| `ValueError` | If `tensors` isn't iterable. |\n| `ValueError` | `enqueue_many` is True and labels doesn't have a batch dimension, or if `enqueue_many` is False and labels isn't a scalar. |\n| `ValueError` | `enqueue_many` is True, and batch dimension on data and labels don't match. |\n| `ValueError` | if probs don't sum to one. |\n| `ValueError` | if a zero initial probability class has a nonzero target probability. |\n| `TFAssertion` | if labels aren't integers in \\[0, num classes). |\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Returns ------- ||\n|---|---|\n| (data_batch, label_batch), where data_batch is a list of tensors of the same length as `tensors` ||\n\n\u003cbr /\u003e\n\n#### Example:\n\nGet tensor for a single data and label example.\n===============================================\n\ndata, label = data_provider.Get(\\['data', 'label'\\])\n\nGet stratified batch according to per-class probabilities.\n==========================================================\n\ntarget_probs = \\[...distribution you want...\\]\n\\[data_batch\\], labels = tf.contrib.training.stratified_sample(\n\\[data\\], label, target_probs)\n\nRun batch through network.\n==========================\n\n..."]]