zero.Stream.epochs¶
- Stream.epochs(max_epoch, epoch_size=None, progress_bar_config={})[source]¶
Iterate over data epochs.
A shortcut for what is probably the most popular form of a training loop in Deep Learning (plus a progress bar):
for epoch in stream.epochs(max_epoch, epoch_size): for batch in epoch: ... # is equivalent to: while stream.epoch < max_epoch: stream.increment_epoch() for batch in stream.data(epoch_size): ...
- Parameters
max_epoch (Union[int, float]) – defines the number of epochs. The loop keeps running while
self.epoch < max_epoch. Iffloat, must befloat('inf')ormath.inf.epoch_size (Optional[Union[int, float]]) – the number of data items in one epoch (is forwarded to
Stream.data).progress_bar_config (Optional[Dict[str, Any]]) – if not
None(the default value is{}!), a progress bar for iterations will be displayed and the argument will be interpreted as key-word arguments for tqdm. The following key-word arguments will be automatically added if not presented inprogress_bar_config:initial,total(if can be inferred from the arguments and/or fromStream.loader). If [ipywidgets](https://ipywidgets.readthedocs.io) is installed and the program is running in JupyterLab (Jupyter Notebook), then the pretty widget is used instead of the text-based one.
- Returns
Iterator over iterators over data from
Stream.loader.- Raises
AssertionError – if
max_epochis a finite float or nan.- Return type
Iterator[Iterator[Any]]
Examples
stream = Stream(range(3)) for epoch in stream.epochs(2): for x in epoch: print(x) print('-')
0 1 2 - 0 1 2 -
stream = Stream(range(3)) for epoch in stream.epochs(3, 2): for x in epoch: print(x) print('-')
0 1 - 2 0 - 1 2 -