zero.stream.Stream.epochs¶
-
Stream.
epochs
(n_epochs, epoch_size=None, progress_bar=True)[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(n_epochs, epoch_size): for x in epoch: ... # is equivalent to: while stream.epoch < n_epochs: stream.increment_epoch() for x in stream.data(epoch_size): ...
- Parameters
n_epochs (Union[int, float]) – the number of epochs. If
float
, must bemath.inf
.epoch_size (Optional[Union[int, float]]) – the number of data items in one epoch (is forwarded to
Stream.data
)progress_bar (bool) – show the progress bar for iterations. The initial value is set to
Stream.iteration
. See also the note below.
- Returns
Iterator over iterators over data from
Stream.loader
.- Raises
AssertionError – if
n_epochs
iffloat
, but notmath.inf
.- Return type
Iterator[Iterator[Any]]
Note
If
progress_bar
is True, the progress bar is updated on yielding every item which means that the progress bar should be interpreted as “what iteration is in progress” instead of “how many iterations are done”. The percentage will be displayed only if the total number of planned iterations can be inferred from the arguments and/or fromStream.loader
.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 -