MXNet Plugin API reference

class nvidia.dali.plugin.mxnet.DALIClassificationIterator(pipelines, size, data_name='data', label_name='softmax_label', data_layout='NCHW', fill_last_batch=True, auto_reset=False, squeeze_labels=True, dynamic_shape=False, last_batch_padded=False)

DALI iterator for classification tasks for MXNet. It returns 2 outputs (data and label) in the form of MXNet’s DataBatch of NDArrays.

Calling

DALIClassificationIterator(pipelines, size, data_name,
                           label_name, data_layout)

is equivalent to calling

DALIGenericIterator(pipelines,
                    [data_name, DALIClassificationIterator.DATA_TAG,
                     label_name, DALIClassificationIterator.LABEL_TAG],
                    size, data_name, label_name,
                    data_layout)

Please keep in mind that NDArrays returned by the iterator are still owned by DALI. They are valid till the next iterator call. If the content needs to be preserved please copy it to another NDArray.

Parameters
  • pipelines (list of nvidia.dali.pipeline.Pipeline) – List of pipelines to use

  • size (int) – Number of samples in the epoch (Usually the size of the dataset). Providing -1 means that the iterator will work until StopIteration is raised from the inside of iter_setup(). The options fill_last_batch, last_batch_padded and auto_reset don’t work in such case. It works with only one pipeline inside the iterator.

  • data_name (str, optional, default = 'data') – Data name for provided symbols.

  • label_name (str, optional, default = 'softmax_label') – Label name for provided symbols.

  • data_layout (str, optional, default = 'NCHW') – Either ‘NHWC’ or ‘NCHW’ - layout of the pipeline outputs.

  • fill_last_batch (bool, optional, default = True) – Whether to fill the last batch with data up to ‘self.batch_size’. The iterator would return the first integer multiple of self._num_gpus * self.batch_size entries which exceeds ‘size’. Setting this flag to False will cause the iterator to return exactly ‘size’ entries.

  • auto_reset (bool, optional, default = False) – Whether the iterator resets itself for the next epoch or it requires reset() to be called separately.

  • squeeze_labels (bool, optional, default = True) – Whether the iterator should squeeze the labels before copying them to the ndarray.

  • dynamic_shape (bool, optional, default = False) – Whether the shape of the output of the DALI pipeline can change during execution. If True, the mxnet.ndarray will be resized accordingly if the shape of DALI returned tensors changes during execution. If False, the iterator will fail in case of change.

  • last_batch_padded (bool, optional, default = False) – Whether the last batch provided by DALI is padded with the last sample or it just wraps up. In the conjunction with fill_last_batch it tells if the iterator returning last batch with data only partially filled with data from the current epoch is dropping padding samples or samples from the next epoch. If set to False next epoch will end sooner as data from it was consumed but dropped. If set to True next epoch would be the same length as the first one.

Example

With the data set [1,2,3,4,5,6,7] and the batch size 2:

fill_last_batch = False, last_batch_padded = True -> last batch = [7], next iteration will return [1, 2]

fill_last_batch = False, last_batch_padded = False -> last batch = [7], next iteration will return [2, 3]

fill_last_batch = True, last_batch_padded = True -> last batch = [7, 7], next iteration will return [1, 2]

fill_last_batch = True, last_batch_padded = False -> last batch = [7, 1], next iteration will return [2, 3]

DATA_TAG = 'data'
LABEL_TAG = 'label'
next()

Returns the next batch of data.

reset()

Resets the iterator after the full epoch. DALI iterators do not support resetting before the end of the epoch and will ignore such request.

class nvidia.dali.plugin.mxnet.DALIGenericIterator(pipelines, output_map, size, data_layout='NCHW', fill_last_batch=True, auto_reset=False, squeeze_labels=True, dynamic_shape=False, last_batch_padded=False)

General DALI iterator for MXNet. It can return any number of outputs from the DALI pipeline in the form of MXNet’s DataBatch of NDArrays.

Please keep in mind that NDArrays returned by the iterator are still owned by DALI. They are valid till the next iterator call. If the content needs to be preserved please copy it to another NDArray.

Parameters
  • pipelines (list of nvidia.dali.pipeline.Pipeline) – List of pipelines to use

  • output_map (list of (str, str)) – List of pairs (output_name, tag) which maps consecutive outputs of DALI pipelines to proper field in MXNet’s DataBatch. tag is one of DALIGenericIterator.DATA_TAG and DALIGenericIterator.LABEL_TAG mapping given output for data or label correspondingly. output_names should be distinct.

  • size (int) – Number of samples in the epoch (Usually the size of the dataset). Providing -1 means that the iterator will work until StopIteration is raised from the inside of iter_setup(). The options fill_last_batch, last_batch_padded and auto_reset don’t work in such case. It works with only one pipeline inside the iterator.

  • data_layout (str, optional, default = 'NCHW') – Either ‘NHWC’ or ‘NCHW’ - layout of the pipeline outputs.

  • fill_last_batch (bool, optional, default = True) – Whether to fill the last batch with data up to ‘self.batch_size’. The iterator would return the first integer multiple of self._num_gpus * self.batch_size entries which exceeds ‘size’. Setting this flag to False will cause the iterator to return exactly ‘size’ entries.

  • auto_reset (bool, optional, default = False) – Whether the iterator resets itself for the next epoch or it requires reset() to be called separately.

  • squeeze_labels (bool, optional, default = True) – Whether the iterator should squeeze the labels before copying them to the ndarray.

  • dynamic_shape (bool, optional, default = False) – Whether the shape of the output of the DALI pipeline can change during execution. If True, the mxnet.ndarray will be resized accordingly if the shape of DALI returned tensors changes during execution. If False, the iterator will fail in case of change.

  • last_batch_padded (bool, optional, default = False) – Whether the last batch provided by DALI is padded with the last sample or it just wraps up. In the conjunction with fill_last_batch it tells if the iterator returning last batch with data only partially filled with data from the current epoch is dropping padding samples or samples from the next epoch. If set to False next epoch will end sooner as data from it was consumed but dropped. If set to True next epoch would be the same length as the first one. For this happen, the option pad_last_batch in the reader need to be set to True as well.

Example

With the data set [1,2,3,4,5,6,7] and the batch size 2:

fill_last_batch = False, last_batch_padded = True -> last batch = [7], next iteration will return [1, 2]

fill_last_batch = False, last_batch_padded = False -> last batch = [7], next iteration will return [2, 3]

fill_last_batch = True, last_batch_padded = True -> last batch = [7, 7], next iteration will return [1, 2]

fill_last_batch = True, last_batch_padded = False -> last batch = [7, 1], next iteration will return [2, 3]

DATA_TAG = 'data'
LABEL_TAG = 'label'
next()

Returns the next batch of data.

reset()

Resets the iterator after the full epoch. DALI iterators do not support resetting before the end of the epoch and will ignore such request.

nvidia.dali.plugin.mxnet.feed_ndarray(dali_tensor, arr)

Copy contents of DALI tensor to MXNet’s NDArray.

Parameters