class documentation
class LatencyDynamicBatcher(BaseDynamicBatcher): (source)
Constructor: LatencyDynamicBatcher(iterable, target_latency, init_batch_size, min_batch_size, ...)
Class for iterating over the elements of an iterable with a dynamic batch size to achieve a desired latency.
The batch sizes emitted when iterating over this object are dynamically scaled such that the latency between next() calls is as close as possible to a specified target latency.
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.LatencyDynamicBatcher( elements, target_latency=0.1, max_batch_beta=2.0 ) for batch in batcher: print("batch size: %d" % len(batch)) batcher = fou.LatencyDynamicBatcher( elements, target_latency=0.1, max_batch_beta=2.0, progress=True, ) with batcher: for batch in batcher: print("batch size: %d" % len(batch))
Parameters | |
iterable | an 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 | the target latency between next() calls, in seconds |
init | the initial batch size to use |
min | the minimum allowed batch size |
max | an optional maximum allowed batch size |
max | an optional lower/upper bound on the ratio between successive batch sizes |
return | whether to return each batch as a
fiftyone.core.view.DatasetView . Only applicable when the
iterable is a fiftyone.core.collections.SampleCollection |
progress | whether 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 |
total | the length of iterable. Only applicable when progress=True. If not provided, it is computed via len(iterable), if possible |
Method | __init__ |
Undocumented |
Method | _get |
Get backpressure measurement for current batch. |
Instance Variable | _last |
Undocumented |
Inherited from BaseDynamicBatcher
:
Instance Variable | target |
Undocumented |
Method | _compute |
Return next batch size. Concrete classes must implement. |
Instance Variable | _last |
Undocumented |
Inherited from Batcher
(via BaseDynamicBatcher
):
Method | __enter__ |
Undocumented |
Method | __exit__ |
Undocumented |
Method | __iter__ |
Undocumented |
Method | __next__ |
Undocumented |
Method | apply |
Apply backpressure needed to rightsize the next batch. |
Class Variable | manual |
Undocumented |
Instance Variable | iterable |
Undocumented |
Instance Variable | _in |
Undocumented |
Instance Variable | _iter |
Undocumented |
Instance Variable | _last |
Undocumented |
Instance Variable | _manually |
Undocumented |
Instance Variable | _num |
Undocumented |
Instance Variable | _pb |
Undocumented |
Instance Variable | _render |
Undocumented |