Iterator module introduction

  • SerialIterator
  • MultiProcessIterator

In [1]:
# Initial setup following http://docs.chainer.org/en/stable/tutorial/basic.html
import numpy as np
import chainer
from chainer import cuda, Function, gradient_check, report, training, utils, Variable
from chainer import datasets, iterators, optimizers, serializers
from chainer import Link, Chain, ChainList
import chainer.functions as F
import chainer.links as L
from chainer.training import extensions
import chainer.dataset
import chainer.datasets
import chainer.iterators

SerialIterator

This iterator is basic function.

Implment custom Iterator

You can implement custom Iterator class to achieve this functionality. The parent class Iterator is implemented as following, Iterator code. So what we need to implement is

  • init(self, ...) : Initialization code.
  • next(self) : This is the core part of iterator. For each iteration, this function is automatically called to get next minibatch.
  • epoch_detail(self) : This property is used by trainer module to show the progress of training.
  • serialize(self) : Implement if you want to support resume functionality of trainer.

MultiprocessIterator

The data is prefetched before feeding to the model, using background process in parallel.


In [ ]:

Implment custom Iterator

You can implement custom Iterator class to achieve this functionality. The parent class Iterator is implemented as following, Iterator code. So what we need to implement is

  • init(self, ...) : Initialization code.
  • next(self) : This is the core part of iterator. For each iteration, this function is automatically called to get next minibatch.
  • epoch_detail(self) : This property is used by trainer module to show the progress of training.
  • serialize(self) : Implement if you want to support resume functionality of trainer.

In [ ]: