class documentation

Class for iterating over the elements of an iterable with a dynamic batch size to achieve a desired content size.

The batch sizes emitted when iterating over this object are dynamically scaled such that the total content size of the batch is as close as possible to a specified target size.

This batcher does not require backpressure feedback because it calculates the total size of the iterable object before batching.

This class is often used in conjunction with a ProgressBar to keep the user appraised on the status of a long-running task.

Example usage:

import fiftyone.core.utils as fou

elements = range(int(1e7))

batcher = fou.ContentSizeBatcher(
    elements,
    target_size=2**20,
    progress=True
)

with batcher:
    for batch in batcher:
        print("batch size: %d" % len(batch))
Parameters
iterablean iterable to batch over. If None, the result of next() will be a batch size instead of a batch, and is an infinite iterator
target_sizethe target batch BSON content size, in bytes
transform_fna transform function to apply to each item
size_calc_fna function that calculates the size of each item. This is applied after transform_fn if both are provided
progresswhether to render a progress bar tracking the consumption of the batches (True/False), use the default value fiftyone.config.show_progress_bars (None), or a progress callback function to invoke instead
totalthe length of iterable. Only applicable when progress=True. If not provided, it is computed via len(iterable), if possible
Method __init__ Undocumented
Method __iter__ Undocumented
Method __next__ Undocumented
Method set_encoding_ratio Undocumented
Instance Variable max_batch_size Undocumented
Instance Variable size_calc_fn Undocumented
Instance Variable target_size Undocumented
Instance Variable _encoding_ratio Undocumented
Instance Variable _last_batch_content_size Undocumented
Instance Variable _last_batch_size Undocumented
Instance Variable _next_element Undocumented

Inherited from Batcher:

Method __enter__ Undocumented
Method __exit__ Undocumented
Instance Variable iterable Undocumented
Instance Variable return_views Undocumented
Instance Variable _in_context Undocumented
Instance Variable _iter Undocumented
Instance Variable _last_offset Undocumented
Instance Variable _num_samples Undocumented
Instance Variable _pb Undocumented
Instance Variable _render_progress Undocumented
def __init__(self, iterable, target_size=2 ** 20, max_batch_size=None, transform_fn=None, size_calc_fn=None, progress=False, total=None): (source)

Undocumented

def __iter__(self): (source)

Undocumented

def __next__(self): (source)

Undocumented

def set_encoding_ratio(self, encoded_batch_size): (source)

Undocumented

max_batch_size = (source)

Undocumented

size_calc_fn: None = (source)

Undocumented

target_size: 1048576 = (source)

Undocumented

_encoding_ratio = (source)

Undocumented

_last_batch_content_size = (source)

Undocumented

_last_batch_size = (source)
_next_element = (source)

Undocumented