(loader, epoch_size, num_epochs=None)
To use with the infinite training loader: groups the training data
    batches into epochs of the given size.
To use with the infinite training loader: groups the training data
    batches into epochs of the given size.
To use with the infinite training loader : groups the training data batches into epochs of the given size .
def epoch_grouper(loader, epoch_size, num_epochs=None):
    '''
    To use with the infinite training loader: groups the training data
    batches into epochs of the given size.
    '''
    it = iter(loader)
    epoch = 0
    while True:
        chunk_it = itertools.islice(it, epoch_size)
        try:
            first_el = next(chunk_it)
        except StopIteration:
            return
        yield itertools.chain((first_el,), chunk_it)
        epoch += 1
        if num_epochs is not None and epoch >= num_epochs:
            return
def epoch_grouper ( loader , epoch_size , num_epochs = None ) : it = iter ( loader ) epoch = 0 while True : chunk_it = itertools . islice ( it , epoch_size ) try : first_el = next ( chunk_it ) except StopIteration : return yield itertools . chain ( ( first_el , ) , chunk_it ) epoch += 1 if num_epochs is not None and epoch >= num_epochs : return