Table Of Contents
Table Of Contents

ImageIter

class mxnet.image.ImageIter(batch_size, data_shape, label_width=1, path_imgrec=None, path_imglist=None, path_root=None, path_imgidx=None, shuffle=False, part_index=0, num_parts=1, aug_list=None, imglist=None, data_name='data', label_name='softmax_label', dtype='float32', last_batch_handle='pad', **kwargs)[source]

Image data iterator with a large number of augmentation choices. This iterator supports reading from both .rec files and raw image files.

To load input images from .rec files, use path_imgrec parameter and to load from raw image files, use path_imglist and path_root parameters.

To use data partition (for distributed training) or shuffling, specify path_imgidx parameter.

Parameters:
  • batch_size (int) – Number of examples per batch.
  • data_shape (tuple) – Data shape in (channels, height, width) format. For now, only RGB image with 3 channels is supported.
  • label_width (int, optional) – Number of labels per example. The default label width is 1.
  • path_imgrec (str) – Path to image record file (.rec). Created with tools/im2rec.py or bin/im2rec.
  • path_imglist (str) – Path to image list (.lst). Created with tools/im2rec.py or with custom script. Format: Tab separated record of index, one or more labels and relative_path_from_root.
  • imglist (list) – A list of images with the label(s). Each item is a list [imagelabel: float or list of float, imgpath].
  • path_root (str) – Root folder of image files.
  • path_imgidx (str) – Path to image index file. Needed for partition and shuffling when using .rec source.
  • shuffle (bool) – Whether to shuffle all images at the start of each iteration or not. Can be slow for HDD.
  • part_index (int) – Partition index.
  • num_parts (int) – Total number of partitions.
  • data_name (str) – Data name for provided symbols.
  • label_name (str) – Label name for provided symbols.
  • dtype (str) – Label data type. Default: float32. Other options: int32, int64, float64
  • last_batch_handle (str, optional) – How to handle the last batch. This parameter can be ‘pad’(default), ‘discard’ or ‘roll_over’. If ‘pad’, the last batch will be padded with data starting from the begining If ‘discard’, the last batch will be discarded If ‘roll_over’, the remaining elements will be rolled over to the next iteration
  • kwargs – More arguments for creating augmenter. See mx.image.CreateAugmenter.
__init__(batch_size, data_shape, label_width=1, path_imgrec=None, path_imglist=None, path_root=None, path_imgidx=None, shuffle=False, part_index=0, num_parts=1, aug_list=None, imglist=None, data_name='data', label_name='softmax_label', dtype='float32', last_batch_handle='pad', **kwargs)[source]

Initialize self. See help(type(self)) for accurate signature.

Methods

__init__(batch_size, data_shape[, …]) Initialize self.
augmentation_transform(data) Transforms input data with specified augmentation.
check_data_shape(data_shape) Checks if the input data shape is valid
check_valid_image(data) Checks if the input data is valid
getdata() Get data of current batch.
getindex() Get index of the current batch.
getlabel() Get label of the current batch.
getpad() Get the number of padding examples in the current batch.
hard_reset() Resets the iterator and ignore roll over data
imdecode(s) Decodes a string or byte string to an NDArray.
iter_next() Move to the next batch.
next() Returns the next batch of data.
next_sample() Helper function for reading in next sample.
postprocess_data(datum) Final postprocessing step before image is loaded into the batch.
read_image(fname) Reads an input image fname and returns the decoded raw bytes.
reset() Resets the iterator to the beginning of the data.