chainer.iterators.SerialIterator¶
-
class
chainer.iterators.
SerialIterator
(dataset, batch_size, repeat=True, shuffle=None, order_sampler=None)[source]¶ Dataset iterator that serially reads the examples.
This is a simple implementation of
Iterator
that just visits each example in either the order of indexes or a shuffled order.To avoid unintentional performance degradation, the
shuffle
option is set toTrue
by default. For validation, it is better to set it toFalse
when the underlying dataset supports fast slicing. If the order of examples has an important meaning and the updater depends on the original order, this option should be set toFalse
.This iterator saves
-1
instead ofNone
in snapshots since some serializers do not supportNone
.- Parameters
dataset – Dataset to iterate.
batch_size (int) – Number of examples within each batch.
repeat (bool) – If
True
, it infinitely loops over the dataset. Otherwise, it stops iteration at the end of the first epoch.shuffle (bool) – If
True
, the order of examples is shuffled at the beginning of each epoch. Otherwise, examples are extracted in the order of indexes. IfNone
and noorder_sampler
is given, the behavior is the same as the case withshuffle=True
.order_sampler (callable) – A callable that generates the order of the indices to sample in the next epoch when a epoch finishes. This function should take two arguments: the current order and the current position of the iterator. This should return the next order. The size of the order should remain constant. This option cannot be used when
shuffle
is notNone
.
Methods
-
__enter__
()[source]¶ With statement context manager method
This method does nothing by default. Implementation may override it to better handle the internal resources by with statement.
-
__exit__
(exc_type, exc_value, traceback)[source]¶ With statement context manager method
This method does nothing by default. Implementation may override it to better handle the internal resources by with statement.
-
__next__
()[source]¶ Returns the next batch.
This is a part of the iterator protocol of Python. It may raise the
StopIteration
exception when it stops the iteration.
-
finalize
()[source]¶ Finalizes the iterator and possibly releases the resources.
This method does nothing by default. Implementation may override it to better handle the internal resources.
-
next
()[source]¶ Returns the next batch.
This is a part of the iterator protocol of Python. It may raise the
StopIteration
exception when it stops the iteration.
-
serialize
(serializer)[source]¶ Serializes the internal state of the iterator.
This is a method to support the serializer protocol of Chainer.
Note
It should only serialize the internal state that changes over the iteration. It should not serialize what is set manually by users such as the batch size.
Attributes
-
current_position
¶
-
epoch
¶
-
epoch_detail
¶
-
is_new_epoch
¶
-
previous_epoch_detail
¶
-
repeat
¶