Decorator to make a converter.
This decorator turns a converter function into a
chainer.dataset.Converterclass instance, which also is a callable. This is required to use the converter function from an old module that does not support
chainer.backend.Deviceinstances (See the Device argument conversion section below).
Requirements of the target function
The target converter function must accept two positional arguments: a batch and a device, and return a converted batch.
The type of the device argument is
The types and values of the batches (the first argument and the return value) are not specified: they depend on how the converter is used (e.g. by updaters).
>>> @chainer.dataset.converter() ... def custom_converter(batch, device): ... assert isinstance(device, chainer.backend.Device) ... # do something with batch... ... return device.send(batch)
Device argument conversion
For backward compatibility, the decorator wraps the function so that if the converter is called with the device argument with
inttype, it is converted to a
chainer.backend.Deviceinstance before calling the original function. The
intvalue indicates the CUDA device of the cupy backend.
Without the decorator, the converter cannot support ChainerX devices. If the batch were requested to be converted to ChainerX with such converters,
RuntimeErrorwill be raised.