Data Providers

Data providers are wrappers that load external data, be it images, text, or general tensors, and split it into mini-batches so that the model can consume the data in a uniformed way.

AbstractDataProvider interface

# MXNet.mx.AbstractDataProviderType.

AbstractDataProvider

The root type for all data provider. A data provider should implement the following interfaces:

As well as the Julia iterator interface (see the Julia manual). Normally this involves defining:

  • Base.eltype(provider) -> AbstractDataBatch
  • Base.iterate(provider[, state]) -> (AbstractDataBatch, AbstractDataProvider)

source

The difference between data and label is that during training stage, both data and label will be feeded into the model, while during prediction stage, only data is loaded. Otherwise, they could be anything, with any names, and of any shapes. The provided data and label names here should match the input names in a target SymbolicNode.

A data provider should also implement the Julia iteration interface, in order to allow iterating through the data set. The provider will be called in the following way:

for batch in eachbatch(provider)
    data = get_data(provider, batch)
end

which will be translated by Julia compiler into

state = Base.start(eachbatch(provider))
while !Base.done(provider, state)
    (batch, state) = Base.next(provider, state)
    data = get_data(provider, batch)
end

By default, eachbatch simply returns the provider itself, so the iterator interface is implemented on the provider type itself. But the extra layer of abstraction allows us to implement a data provider easily via a Julia Task coroutine. See the data provider defined in the char-lstm example for an example of using coroutine to define data providers.

The detailed interface functions for the iterator API is listed below:

Base.eltype(provider) -> AbstractDataBatch

Returns the specific subtype representing a data batch. See AbstractDataBatch.

  • provider::AbstractDataProvider: the data provider.

    Base.start(provider) -> AbstractDataProviderState

This function is always called before iterating into the dataset. It should initialize the iterator, reset the index, and do data shuffling if needed.

  • provider::AbstractDataProvider: the data provider.

    Base.done(provider, state) -> Bool

True if there is no more data to iterate in this dataset.

  • provider::AbstractDataProvider: the data provider.
  • state::AbstractDataProviderState: the state returned by Base.start and Base.next.

    Base.next(provider) -> (AbstractDataBatch, AbstractDataProviderState)

Returns the current data batch, and the state for the next iteration.

  • provider::AbstractDataProvider: the data provider.

Note sometimes you are wrapping an existing data iterator (e.g. the built-in libmxnet data iterator) that is built with a different convention. It might be difficult to adapt to the interfaces stated here. In this case, you can safely assume that

  • Base.start will always be called, and called only once before the iteration starts.
  • Base.done will always be called at the beginning of every iteration and always be called once.
  • If Base.done return true, the iteration will stop, until the next round, again, starting with a call to Base.start.
  • Base.next will always be called only once in each iteration. It will always be called after one and only one call to Base.done; but if Base.done returns true, Base.next will not be called.

With those assumptions, it will be relatively easy to adapt any existing iterator. See the implementation of the built-in MXDataProvider for example.

Note

Please do not use the one data provider simultaneously in two different places, either in parallel, or in a nested loop. For example, the behavior for the following code is undefined

```julia for batch in data # updating the parameters

# now let's test the performance on the training set
for b2 in data
    # ...
end

end ```

# MXNet.mx.get_batch_sizeFunction.

get_batch_size(provider) -> Int

Arguments:

  • provider::AbstractDataProvider: the data provider.

Returns the mini-batch size of the provided data. All the provided data should have the same mini-batch size (i.e. the last dimension).

source

# MXNet.mx.provide_dataFunction.

provide_data(provider) -> Vector{Tuple{Base.Symbol, Tuple}}

Arguments:

  • provider::AbstractDataProvider: the data provider.

Returns a vector of (name, shape) pairs describing the names of the data it provides, and the corresponding shapes.

source

# MXNet.mx.provide_labelFunction.

provide_label(provider) -> Vector{Tuple{Base.Symbol, Tuple}}

Arguments:

  • provider::AbstractDataProvider: the data provider.

Returns a vector of (name, shape) pairs describing the names of the labels it provides, and the corresponding shapes.

source

AbstractDataBatch interface

# MXNet.mx.AbstractDataProviderStateType.

AbstractDataProviderState

Base type for data provider states.

source

# MXNet.mx.count_samplesFunction.

count_samples(provider, batch) -> Int

Arguments:

  • batch::AbstractDataBatch: the data batch object.

Returns the number of samples in this batch. This number should be greater than 0, but less than or equal to the batch size. This is used to indicate at the end of the data set, there might not be enough samples for a whole mini-batch.

source

# MXNet.mx.get_dataFunction.

get_data(provider, batch) -> Vector{NDArray}

Arguments:

  • provider::AbstractDataProvider: the data provider.
  • batch::AbstractDataBatch: the data batch object.

Returns a vector of data in this batch, should be in the same order as declared in provide_data() <AbstractDataProvider.provide_data>.

The last dimension of each NDArray should always match the batch*size, even when count*samples returns a value less than the batch size. In this case, the data provider is free to pad the remaining contents with any value.

source

# MXNet.mx.get_labelFunction.

get_label(provider, batch) -> Vector{NDArray}

Arguments:

  • provider::AbstractDataProvider: the data provider.
  • batch::AbstractDataBatch: the data batch object.

Returns a vector of labels in this batch. Similar to get_data.

source

# Base.getFunction.

get(sched)
  • sched::AbstractMomentumScheduler: the momentum scheduler.

Returns the current momentum.

source

# MXNet.mx.load_data!Function.

load_data!(provider, batch, targets)

Arguments:

  • provider::AbstractDataProvider: the data provider.
  • batch::AbstractDataBatch: the data batch object.
  • targets::Vector{Vector{SlicedNDArray}}: the targets to load data into.

The targets is a list of the same length as number of data provided by this provider. Each element in the list is a list of SlicedNDArray. This list described a spliting scheme of this data batch into different slices, each slice is specified by a slice-ndarray pair, where slice specify the range of samples in the mini-batch that should be loaded into the corresponding ndarray.

This utility function is used in data parallelization, where a mini-batch is splited and computed on several different devices.

source

# MXNet.mx.load_label!Function.

load_label!(provider, batch, targets)
  • provider::AbstractDataProvider provider: the data provider.
  • batch::AbstractDataBatch batch: the data batch object.
  • targets::Vector{Vector{SlicedNDArray}}: the targets to load label into.

The same as load_data!, except that this is for loading labels.

source

Implemented providers and other methods

# MXNet.mx.AbstractDataBatchType.

AbstractDataBatch

Base type for a data mini-batch. It should implement the following interfaces:

The following utility functions will be automatically defined:

source

# MXNet.mx.ArrayDataProviderType.

ArrayDataProvider

A convenient tool to iterate NDArray or Julia Array.

ArrayDataProvider(data[, label]; batch_size, shuffle, data_padding, label_padding)

Construct a data provider from NDArray or Julia Arrays.

Arguments:

  • data: the data, could be

    • a NDArray, or a Julia Array. This is equivalent to :data => data.
    • a name-data pair, like :mydata => array, where :mydata is the name of the data
    • and array is an NDArray or a Julia Array.
    • a list of name-data pairs.
    • label: the same as the data parameter. When this argument is omitted, the constructed provider will provide no labels.
    • batch_size::Int: the batch size, default is 0, which means treating the whole array as a single mini-batch.
    • shuffle::Bool: turn on if the data should be shuffled at every epoch.
    • data_padding::Real: when the mini-batch goes beyond the dataset boundary, there might be less samples to include than a mini-batch. This value specify a scalar to pad the contents of all the missing data points.
    • label_padding::Real: the same as data_padding, except for the labels.

TODO: remove data_padding and label_padding, and implement rollover that copies the last or first several training samples to feed the padding.

source

# MXNet.mx.DataBatchType.

DataBatch

A basic subclass of AbstractDataBatch, that implement the interface by accessing member fields.

source

# MXNet.mx.MXDataProviderType.

MXDataProvider

A data provider that wrap built-in data iterators from libmxnet. See below for a list of built-in data iterators.

source

# MXNet.mx.SlicedNDArrayType.

SlicedNDArray

A alias type of Tuple{UnitRange{Int},NDArray}.

source

# Base.getMethod.

get(provider, batch, name) -> NDArray
  • provider::AbstractDataProvider: the data provider.
  • batch::AbstractDataBatch: the data batch object.
  • name::Symbol: the name of the data to get, should be one of the names provided in either provide_data() <AbstractDataProvider.provide_data> or provide_label() <AbstractDataProvider.provide_label>.

Returns the corresponding data array corresponding to that name.

source

# MXNet.mx.CSVIterMethod.

CSVIter(data_csv, data_shape, label_csv, label_shape, batch_size, round_batch, prefetch_buffer, ctx, dtype)

Can also be called with the alias CSVProvider. Returns the CSV file iterator.

In this function, the data_shape parameter is used to set the shape of each line of the input data. If a row in an input file is 1,2,3,4,5,6``anddata_shape` is (3,2), that row will be reshaped, yielding the array [[1,2],[3,4],[5,6]] of shape (3,2).

By default, the CSVIter has round_batch parameter set to $True$. So, if batch_size is 3 and there are 4 total rows in CSV file, 2 more examples are consumed at the first round. If reset function is called after first round, the call is ignored and remaining examples are returned in the second round.

If one wants all the instances in the second round after calling reset, make sure to set round_batch to False.

If $data_csv = 'data/'$ is set, then all the files in this directory will be read.

$reset()$ is expected to be called only after a complete pass of data.

By default, the CSVIter parses all entries in the data file as float32 data type, if dtype argument is set to be 'int32' or 'int64' then CSVIter will parse all entries in the file as int32 or int64 data type accordingly.

Examples::

// Contents of CSV file $data/data.csv$. 1,2,3 2,3,4 3,4,5 4,5,6

// Creates a CSVIter with batch_size=2 and default round_batch=True. CSVIter = mx.io.CSVIter(datacsv = 'data/data.csv', datashape = (3,), batch_size = 2)

// Two batches read from the above iterator are as follows: [[ 1. 2. 3.] [ 2. 3. 4.]] [[ 3. 4. 5.] [ 4. 5. 6.]]

// Creates a CSVIter with default round_batch set to True. CSVIter = mx.io.CSVIter(datacsv = 'data/data.csv', datashape = (3,), batch_size = 3)

// Two batches read from the above iterator in the first pass are as follows: [[1. 2. 3.] [2. 3. 4.] [3. 4. 5.]]

[[4. 5. 6.] [1. 2. 3.] [2. 3. 4.]]

// Now, reset method is called. CSVIter.reset()

// Batch read from the above iterator in the second pass is as follows: [[ 3. 4. 5.] [ 4. 5. 6.] [ 1. 2. 3.]]

// Creates a CSVIter with round_batch=False. CSVIter = mx.io.CSVIter(datacsv = 'data/data.csv', datashape = (3,), batchsize = 3, roundbatch=False)

// Contents of two batches read from the above iterator in both passes, after calling // reset method before second pass, is as follows: [[1. 2. 3.] [2. 3. 4.] [3. 4. 5.]]

[[4. 5. 6.] [2. 3. 4.] [3. 4. 5.]]

// Creates a 'CSVIter' with dtype='int32' CSVIter = mx.io.CSVIter(datacsv = 'data/data.csv', datashape = (3,), batchsize = 3, roundbatch=False, dtype='int32')

// Contents of two batches read from the above iterator in both passes, after calling // reset method before second pass, is as follows: [[1 2 3] [2 3 4] [3 4 5]]

[[4 5 6] [2 3 4] [3 4 5]]

Defined in src/io/iter_csv.cc:L308

Arguments:

  • data_name::Symbol: keyword argument, default :data. The name of the data.
  • label_name::Symbol: keyword argument, default :softmax_label. The name of the label. Could be nothing if no label is presented in this dataset.
  • data_csv::string, required: The input CSV file or a directory path.
  • data_shape::Shape(tuple), required: The shape of one example.
  • label_csv::string, optional, default='NULL': The input CSV file or a directory path. If NULL, all labels will be returned as 0.
  • label_shape::Shape(tuple), optional, default=[1]: The shape of one label.
  • batch_size::int (non-negative), required: Batch size.
  • round_batch::boolean, optional, default=1: Whether to use round robin to handle overflow batch or not.
  • prefetch_buffer::long (non-negative), optional, default=4: Maximum number of batches to prefetch.
  • ctx::{'cpu', 'gpu'},optional, default='gpu': Context data loader optimized for.
  • dtype::{None, 'bfloat16', 'float16', 'float32', 'float64', 'int32', 'int64', 'int8', 'uint8'},optional, default='None': Output data type. $None$ means no change.

Returns the constructed MXDataProvider.

source

# MXNet.mx.ImageDetRecordIterMethod.

ImageDetRecordIter(path_imglist, path_imgrec, aug_seq, label_width, data_shape, preprocess_threads, verbose, num_parts, part_index, shuffle_chunk_size, shuffle_chunk_seed, label_pad_width, label_pad_value, shuffle, seed, verbose, batch_size, round_batch, prefetch_buffer, ctx, dtype, resize, rand_crop_prob, min_crop_scales, max_crop_scales, min_crop_aspect_ratios, max_crop_aspect_ratios, min_crop_overlaps, max_crop_overlaps, min_crop_sample_coverages, max_crop_sample_coverages, min_crop_object_coverages, max_crop_object_coverages, num_crop_sampler, crop_emit_mode, emit_overlap_thresh, max_crop_trials, rand_pad_prob, max_pad_scale, max_random_hue, random_hue_prob, max_random_saturation, random_saturation_prob, max_random_illumination, random_illumination_prob, max_random_contrast, random_contrast_prob, rand_mirror_prob, fill_value, inter_method, data_shape, resize_mode, seed, mean_img, mean_r, mean_g, mean_b, mean_a, std_r, std_g, std_b, std_a, scale, verbose)

Can also be called with the alias ImageDetRecordProvider. Create iterator for image detection dataset packed in recordio.

Arguments:

  • data_name::Symbol: keyword argument, default :data. The name of the data.
  • label_name::Symbol: keyword argument, default :softmax_label. The name of the label. Could be nothing if no label is presented in this dataset.
  • path_imglist::string, optional, default='': Dataset Param: Path to image list.
  • path_imgrec::string, optional, default='./data/imgrec.rec': Dataset Param: Path to image record file.
  • aug_seq::string, optional, default='det_aug_default': Augmentation Param: the augmenter names to represent sequence of augmenters to be applied, seperated by comma. Additional keyword parameters will be seen by these augmenters. Make sure you don't use normal augmenters for detection tasks.
  • label_width::int, optional, default='-1': Dataset Param: How many labels for an image, -1 for variable label size.
  • data_shape::Shape(tuple), required: Dataset Param: Shape of each instance generated by the DataIter.
  • preprocess_threads::int, optional, default='4': Backend Param: Number of thread to do preprocessing.
  • verbose::boolean, optional, default=1: Auxiliary Param: Whether to output parser information.
  • num_parts::int, optional, default='1': partition the data into multiple parts
  • part_index::int, optional, default='0': the index of the part will read
  • shuffle_chunk_size::long (non-negative), optional, default=0: the size(MB) of the shuffle chunk, used with shuffle=True, it can enable global shuffling
  • shuffle_chunk_seed::int, optional, default='0': the seed for chunk shuffling
  • label_pad_width::int, optional, default='0': pad output label width if set larger than 0, -1 for auto estimate
  • label_pad_value::float, optional, default=-1: label padding value if enabled
  • shuffle::boolean, optional, default=0: Augmentation Param: Whether to shuffle data.
  • seed::int, optional, default='0': Augmentation Param: Random Seed.
  • batch_size::int (non-negative), required: Batch size.
  • round_batch::boolean, optional, default=1: Whether to use round robin to handle overflow batch or not.
  • prefetch_buffer::long (non-negative), optional, default=4: Maximum number of batches to prefetch.
  • ctx::{'cpu', 'gpu'},optional, default='gpu': Context data loader optimized for.
  • dtype::{None, 'bfloat16', 'float16', 'float32', 'float64', 'int32', 'int64', 'int8', 'uint8'},optional, default='None': Output data type. $None$ means no change.
  • resize::int, optional, default='-1': Augmentation Param: scale shorter edge to size before applying other augmentations, -1 to disable.
  • rand_crop_prob::float, optional, default=0: Augmentation Param: Probability of random cropping, <= 0 to disable
  • min_crop_scales::tuple of <float>, optional, default=[0]: Augmentation Param: Min crop scales.
  • max_crop_scales::tuple of <float>, optional, default=[1]: Augmentation Param: Max crop scales.
  • min_crop_aspect_ratios::tuple of <float>, optional, default=[1]: Augmentation Param: Min crop aspect ratios.
  • max_crop_aspect_ratios::tuple of <float>, optional, default=[1]: Augmentation Param: Max crop aspect ratios.
  • min_crop_overlaps::tuple of <float>, optional, default=[0]: Augmentation Param: Minimum crop IOU between crop_box and ground-truths.
  • max_crop_overlaps::tuple of <float>, optional, default=[1]: Augmentation Param: Maximum crop IOU between crop_box and ground-truth.
  • min_crop_sample_coverages::tuple of <float>, optional, default=[0]: Augmentation Param: Minimum ratio of intersect/crop_area between crop box and ground-truths.
  • max_crop_sample_coverages::tuple of <float>, optional, default=[1]: Augmentation Param: Maximum ratio of intersect/crop_area between crop box and ground-truths.
  • min_crop_object_coverages::tuple of <float>, optional, default=[0]: Augmentation Param: Minimum ratio of intersect/gt_area between crop box and ground-truths.
  • max_crop_object_coverages::tuple of <float>, optional, default=[1]: Augmentation Param: Maximum ratio of intersect/gt_area between crop box and ground-truths.
  • num_crop_sampler::int, optional, default='1': Augmentation Param: Number of crop samplers.
  • crop_emit_mode::{'center', 'overlap'},optional, default='center': Augmentation Param: Emition mode for invalid ground-truths after crop. center: emit if centroid of object is out of crop region; overlap: emit if overlap is less than emitoverlapthresh.
  • emit_overlap_thresh::float, optional, default=0.300000012: Augmentation Param: Emit overlap thresh for emit mode overlap only.
  • max_crop_trials::Shape(tuple), optional, default=[25]: Augmentation Param: Skip cropping if fail crop trail count exceeds this number.
  • rand_pad_prob::float, optional, default=0: Augmentation Param: Probability for random padding.
  • max_pad_scale::float, optional, default=1: Augmentation Param: Maximum padding scale.
  • max_random_hue::int, optional, default='0': Augmentation Param: Maximum random value of H channel in HSL color space.
  • random_hue_prob::float, optional, default=0: Augmentation Param: Probability to apply random hue.
  • max_random_saturation::int, optional, default='0': Augmentation Param: Maximum random value of S channel in HSL color space.
  • random_saturation_prob::float, optional, default=0: Augmentation Param: Probability to apply random saturation.
  • max_random_illumination::int, optional, default='0': Augmentation Param: Maximum random value of L channel in HSL color space.
  • random_illumination_prob::float, optional, default=0: Augmentation Param: Probability to apply random illumination.
  • max_random_contrast::float, optional, default=0: Augmentation Param: Maximum random value of delta contrast.
  • random_contrast_prob::float, optional, default=0: Augmentation Param: Probability to apply random contrast.
  • rand_mirror_prob::float, optional, default=0: Augmentation Param: Probability to apply horizontal flip aka. mirror.
  • fill_value::int, optional, default='127': Augmentation Param: Filled color value while padding.
  • inter_method::int, optional, default='1': Augmentation Param: 0-NN 1-bilinear 2-cubic 3-area 4-lanczos4 9-auto 10-rand.
  • resize_mode::{'fit', 'force', 'shrink'},optional, default='force': Augmentation Param: How image data fit in datashape. force: force reshape to datashape regardless of aspect ratio; shrink: ensure each side fit in datashape, preserve aspect ratio; fit: fit image to datashape, preserve ratio, will upscale if applicable.
  • mean_img::string, optional, default='': Augmentation Param: Mean Image to be subtracted.
  • mean_r::float, optional, default=0: Augmentation Param: Mean value on R channel.
  • mean_g::float, optional, default=0: Augmentation Param: Mean value on G channel.
  • mean_b::float, optional, default=0: Augmentation Param: Mean value on B channel.
  • mean_a::float, optional, default=0: Augmentation Param: Mean value on Alpha channel.
  • std_r::float, optional, default=0: Augmentation Param: Standard deviation on R channel.
  • std_g::float, optional, default=0: Augmentation Param: Standard deviation on G channel.
  • std_b::float, optional, default=0: Augmentation Param: Standard deviation on B channel.
  • std_a::float, optional, default=0: Augmentation Param: Standard deviation on Alpha channel.
  • scale::float, optional, default=1: Augmentation Param: Scale in color space.

Returns the constructed MXDataProvider.

source

# MXNet.mx.ImageRecordInt8IterMethod.

ImageRecordInt8Iter(path_imglist, path_imgrec, path_imgidx, aug_seq, label_width, data_shape, preprocess_threads, verbose, num_parts, part_index, device_id, shuffle_chunk_size, shuffle_chunk_seed, seed_aug, shuffle, seed, verbose, batch_size, round_batch, prefetch_buffer, ctx, dtype, resize, rand_crop, random_resized_crop, max_rotate_angle, max_aspect_ratio, min_aspect_ratio, max_shear_ratio, max_crop_size, min_crop_size, max_random_scale, min_random_scale, max_random_area, min_random_area, max_img_size, min_img_size, brightness, contrast, saturation, pca_noise, random_h, random_s, random_l, rotate, fill_value, data_shape, inter_method, pad)

Can also be called with the alias ImageRecordInt8Provider. Iterating on image RecordIO files

.. note:: $ImageRecordInt8Iter$ is deprecated. Use ImageRecordIter(dtype='int8') instead.

This iterator is identical to $ImageRecordIter$ except for using $int8$ as the data type instead of $float$.

Defined in src/io/iterimagerecordio_2.cc:L941

Arguments:

  • data_name::Symbol: keyword argument, default :data. The name of the data.
  • label_name::Symbol: keyword argument, default :softmax_label. The name of the label. Could be nothing if no label is presented in this dataset.
  • path_imglist::string, optional, default='': Path to the image list (.lst) file. Generally created with tools/im2rec.py. Format (Tab separated): .
  • path_imgrec::string, optional, default='': Path to the image RecordIO (.rec) file or a directory path. Created with tools/im2rec.py.
  • path_imgidx::string, optional, default='': Path to the image RecordIO index (.idx) file. Created with tools/im2rec.py.
  • aug_seq::string, optional, default='aug_default': The augmenter names to represent sequence of augmenters to be applied, seperated by comma. Additional keyword parameters will be seen by these augmenters.
  • label_width::int, optional, default='1': The number of labels per image.
  • data_shape::Shape(tuple), required: The shape of one output image in (channels, height, width) format.
  • preprocess_threads::int, optional, default='4': The number of threads to do preprocessing.
  • verbose::boolean, optional, default=1: If or not output verbose information.
  • num_parts::int, optional, default='1': Virtually partition the data into these many parts.
  • part_index::int, optional, default='0': The i-th virtual partition to be read.
  • device_id::int, optional, default='0': The device id used to create context for internal NDArray. Setting deviceid to -1 will create Context::CPU(0). Setting deviceid to valid positive device id will create Context::CPUPinned(device_id). Default is 0.
  • shuffle_chunk_size::long (non-negative), optional, default=0: The data shuffle buffer size in MB. Only valid if shuffle is true.
  • shuffle_chunk_seed::int, optional, default='0': The random seed for shuffling
  • seed_aug::int or None, optional, default='None': Random seed for augmentations.
  • shuffle::boolean, optional, default=0: Whether to shuffle data randomly or not.
  • seed::int, optional, default='0': The random seed.
  • batch_size::int (non-negative), required: Batch size.
  • round_batch::boolean, optional, default=1: Whether to use round robin to handle overflow batch or not.
  • prefetch_buffer::long (non-negative), optional, default=4: Maximum number of batches to prefetch.
  • ctx::{'cpu', 'gpu'},optional, default='gpu': Context data loader optimized for.
  • dtype::{None, 'bfloat16', 'float16', 'float32', 'float64', 'int32', 'int64', 'int8', 'uint8'},optional, default='None': Output data type. $None$ means no change.
  • resize::int, optional, default='-1': Down scale the shorter edge to a new size before applying other augmentations.
  • rand_crop::boolean, optional, default=0: If or not randomly crop the image
  • random_resized_crop::boolean, optional, default=0: If or not perform random resized cropping on the image, as a standard preprocessing for resnet training on ImageNet data.
  • max_rotate_angle::int, optional, default='0': Rotate by a random degree in $[-v, v]$
  • max_aspect_ratio::float, optional, default=0: Change the aspect (namely width/height) to a random value. If minaspectratio is None then the aspect ratio ins sampled from [1 - maxaspectratio, 1 + maxaspectratio], else it is in $[min_aspect_ratio, max_aspect_ratio]$
  • min_aspect_ratio::float or None, optional, default=None: Change the aspect (namely width/height) to a random value in $[min_aspect_ratio, max_aspect_ratio]$
  • max_shear_ratio::float, optional, default=0: Apply a shear transformation (namely $(x,y)->(x+my,y)$) with $m$ randomly chose from $[-max_shear_ratio, max_shear_ratio]$
  • max_crop_size::int, optional, default='-1': Crop both width and height into a random size in $[min_crop_size, max_crop_size].$Ignored if $random_resized_crop$ is True.
  • min_crop_size::int, optional, default='-1': Crop both width and height into a random size in $[min_crop_size, max_crop_size].$Ignored if $random_resized_crop$ is True.
  • max_random_scale::float, optional, default=1: Resize into $[widths, heights]$ with $s$ randomly chosen from $[min_random_scale, max_random_scale]$. Ignored if $random_resized_crop$ is True.
  • min_random_scale::float, optional, default=1: Resize into $[widths, heights]$ with $s$ randomly chosen from $[min_random_scale, max_random_scale]$Ignored if $random_resized_crop$ is True.
  • max_random_area::float, optional, default=1: Change the area (namely width * height) to a random value in $[min_random_area, max_random_area]$. Ignored if $random_resized_crop$ is False.
  • min_random_area::float, optional, default=1: Change the area (namely width * height) to a random value in $[min_random_area, max_random_area]$. Ignored if $random_resized_crop$ is False.
  • max_img_size::float, optional, default=1e+10: Set the maximal width and height after all resize and rotate argumentation are applied
  • min_img_size::float, optional, default=0: Set the minimal width and height after all resize and rotate argumentation are applied
  • brightness::float, optional, default=0: Add a random value in $[-brightness, brightness]$ to the brightness of image.
  • contrast::float, optional, default=0: Add a random value in $[-contrast, contrast]$ to the contrast of image.
  • saturation::float, optional, default=0: Add a random value in $[-saturation, saturation]$ to the saturation of image.
  • pca_noise::float, optional, default=0: Add PCA based noise to the image.
  • random_h::int, optional, default='0': Add a random value in $[-random_h, random_h]$ to the H channel in HSL color space.
  • random_s::int, optional, default='0': Add a random value in $[-random_s, random_s]$ to the S channel in HSL color space.
  • random_l::int, optional, default='0': Add a random value in $[-random_l, random_l]$ to the L channel in HSL color space.
  • rotate::int, optional, default='-1': Rotate by an angle. If set, it overwrites the $max_rotate_angle$ option.
  • fill_value::int, optional, default='255': Set the padding pixels value to $fill_value$.
  • inter_method::int, optional, default='1': The interpolation method: 0-NN 1-bilinear 2-cubic 3-area 4-lanczos4 9-auto 10-rand.
  • pad::int, optional, default='0': Change size from $[width, height]$ into $[pad + width + pad, pad + height + pad]$ by padding pixes

Returns the constructed MXDataProvider.

source

# MXNet.mx.ImageRecordIterMethod.

ImageRecordIter(path_imglist, path_imgrec, path_imgidx, aug_seq, label_width, data_shape, preprocess_threads, verbose, num_parts, part_index, device_id, shuffle_chunk_size, shuffle_chunk_seed, seed_aug, shuffle, seed, verbose, batch_size, round_batch, prefetch_buffer, ctx, dtype, resize, rand_crop, random_resized_crop, max_rotate_angle, max_aspect_ratio, min_aspect_ratio, max_shear_ratio, max_crop_size, min_crop_size, max_random_scale, min_random_scale, max_random_area, min_random_area, max_img_size, min_img_size, brightness, contrast, saturation, pca_noise, random_h, random_s, random_l, rotate, fill_value, data_shape, inter_method, pad, seed, mirror, rand_mirror, mean_img, mean_r, mean_g, mean_b, mean_a, std_r, std_g, std_b, std_a, scale, max_random_contrast, max_random_illumination, verbose)

Can also be called with the alias ImageRecordProvider. Iterates on image RecordIO files

Reads batches of images from .rec RecordIO files. One can use $im2rec.py$ tool (in tools/) to pack raw image files into RecordIO files. This iterator is less flexible to customization but is fast and has lot of language bindings. To iterate over raw images directly use $ImageIter$ instead (in Python).

Example::

dataiter = mx.io.ImageRecordIter( pathimgrec="./sample.rec", # The target record file. datashape=(3, 227, 227), # Output data shape; 227x227 region will be cropped from the original image. batchsize=4, # Number of items per batch. resize=256 # Resize the shorter edge to 256 before cropping. # You can specify more augmentation options. Use help(mx.io.ImageRecordIter) to see all the options. )

You can now use the data_iter to access batches of images.

batch = dataiter.next() # first batch. images = batch.data[0] # This will contain 4 (=batchsize) images each of 3x227x227.

process the images

... data_iter.reset() # To restart the iterator from the beginning.

Defined in src/io/iterimagerecordio_2.cc:L904

Arguments:

  • data_name::Symbol: keyword argument, default :data. The name of the data.
  • label_name::Symbol: keyword argument, default :softmax_label. The name of the label. Could be nothing if no label is presented in this dataset.
  • path_imglist::string, optional, default='': Path to the image list (.lst) file. Generally created with tools/im2rec.py. Format (Tab separated): .
  • path_imgrec::string, optional, default='': Path to the image RecordIO (.rec) file or a directory path. Created with tools/im2rec.py.
  • path_imgidx::string, optional, default='': Path to the image RecordIO index (.idx) file. Created with tools/im2rec.py.
  • aug_seq::string, optional, default='aug_default': The augmenter names to represent sequence of augmenters to be applied, seperated by comma. Additional keyword parameters will be seen by these augmenters.
  • label_width::int, optional, default='1': The number of labels per image.
  • data_shape::Shape(tuple), required: The shape of one output image in (channels, height, width) format.
  • preprocess_threads::int, optional, default='4': The number of threads to do preprocessing.
  • verbose::boolean, optional, default=1: If or not output verbose information.
  • num_parts::int, optional, default='1': Virtually partition the data into these many parts.
  • part_index::int, optional, default='0': The i-th virtual partition to be read.
  • device_id::int, optional, default='0': The device id used to create context for internal NDArray. Setting deviceid to -1 will create Context::CPU(0). Setting deviceid to valid positive device id will create Context::CPUPinned(device_id). Default is 0.
  • shuffle_chunk_size::long (non-negative), optional, default=0: The data shuffle buffer size in MB. Only valid if shuffle is true.
  • shuffle_chunk_seed::int, optional, default='0': The random seed for shuffling
  • seed_aug::int or None, optional, default='None': Random seed for augmentations.
  • shuffle::boolean, optional, default=0: Whether to shuffle data randomly or not.
  • seed::int, optional, default='0': The random seed.
  • batch_size::int (non-negative), required: Batch size.
  • round_batch::boolean, optional, default=1: Whether to use round robin to handle overflow batch or not.
  • prefetch_buffer::long (non-negative), optional, default=4: Maximum number of batches to prefetch.
  • ctx::{'cpu', 'gpu'},optional, default='gpu': Context data loader optimized for.
  • dtype::{None, 'bfloat16', 'float16', 'float32', 'float64', 'int32', 'int64', 'int8', 'uint8'},optional, default='None': Output data type. $None$ means no change.
  • resize::int, optional, default='-1': Down scale the shorter edge to a new size before applying other augmentations.
  • rand_crop::boolean, optional, default=0: If or not randomly crop the image
  • random_resized_crop::boolean, optional, default=0: If or not perform random resized cropping on the image, as a standard preprocessing for resnet training on ImageNet data.
  • max_rotate_angle::int, optional, default='0': Rotate by a random degree in $[-v, v]$
  • max_aspect_ratio::float, optional, default=0: Change the aspect (namely width/height) to a random value. If minaspectratio is None then the aspect ratio ins sampled from [1 - maxaspectratio, 1 + maxaspectratio], else it is in $[min_aspect_ratio, max_aspect_ratio]$
  • min_aspect_ratio::float or None, optional, default=None: Change the aspect (namely width/height) to a random value in $[min_aspect_ratio, max_aspect_ratio]$
  • max_shear_ratio::float, optional, default=0: Apply a shear transformation (namely $(x,y)->(x+my,y)$) with $m$ randomly chose from $[-max_shear_ratio, max_shear_ratio]$
  • max_crop_size::int, optional, default='-1': Crop both width and height into a random size in $[min_crop_size, max_crop_size].$Ignored if $random_resized_crop$ is True.
  • min_crop_size::int, optional, default='-1': Crop both width and height into a random size in $[min_crop_size, max_crop_size].$Ignored if $random_resized_crop$ is True.
  • max_random_scale::float, optional, default=1: Resize into $[widths, heights]$ with $s$ randomly chosen from $[min_random_scale, max_random_scale]$. Ignored if $random_resized_crop$ is True.
  • min_random_scale::float, optional, default=1: Resize into $[widths, heights]$ with $s$ randomly chosen from $[min_random_scale, max_random_scale]$Ignored if $random_resized_crop$ is True.
  • max_random_area::float, optional, default=1: Change the area (namely width * height) to a random value in $[min_random_area, max_random_area]$. Ignored if $random_resized_crop$ is False.
  • min_random_area::float, optional, default=1: Change the area (namely width * height) to a random value in $[min_random_area, max_random_area]$. Ignored if $random_resized_crop$ is False.
  • max_img_size::float, optional, default=1e+10: Set the maximal width and height after all resize and rotate argumentation are applied
  • min_img_size::float, optional, default=0: Set the minimal width and height after all resize and rotate argumentation are applied
  • brightness::float, optional, default=0: Add a random value in $[-brightness, brightness]$ to the brightness of image.
  • contrast::float, optional, default=0: Add a random value in $[-contrast, contrast]$ to the contrast of image.
  • saturation::float, optional, default=0: Add a random value in $[-saturation, saturation]$ to the saturation of image.
  • pca_noise::float, optional, default=0: Add PCA based noise to the image.
  • random_h::int, optional, default='0': Add a random value in $[-random_h, random_h]$ to the H channel in HSL color space.
  • random_s::int, optional, default='0': Add a random value in $[-random_s, random_s]$ to the S channel in HSL color space.
  • random_l::int, optional, default='0': Add a random value in $[-random_l, random_l]$ to the L channel in HSL color space.
  • rotate::int, optional, default='-1': Rotate by an angle. If set, it overwrites the $max_rotate_angle$ option.
  • fill_value::int, optional, default='255': Set the padding pixels value to $fill_value$.
  • inter_method::int, optional, default='1': The interpolation method: 0-NN 1-bilinear 2-cubic 3-area 4-lanczos4 9-auto 10-rand.
  • pad::int, optional, default='0': Change size from $[width, height]$ into $[pad + width + pad, pad + height + pad]$ by padding pixes
  • mirror::boolean, optional, default=0: Whether to mirror the image or not. If true, images are flipped along the horizontal axis.
  • rand_mirror::boolean, optional, default=0: Whether to randomly mirror images or not. If true, 50% of the images will be randomly mirrored (flipped along the horizontal axis)
  • mean_img::string, optional, default='': Filename of the mean image.
  • mean_r::float, optional, default=0: The mean value to be subtracted on the R channel
  • mean_g::float, optional, default=0: The mean value to be subtracted on the G channel
  • mean_b::float, optional, default=0: The mean value to be subtracted on the B channel
  • mean_a::float, optional, default=0: The mean value to be subtracted on the alpha channel
  • std_r::float, optional, default=1: Augmentation Param: Standard deviation on R channel.
  • std_g::float, optional, default=1: Augmentation Param: Standard deviation on G channel.
  • std_b::float, optional, default=1: Augmentation Param: Standard deviation on B channel.
  • std_a::float, optional, default=1: Augmentation Param: Standard deviation on Alpha channel.
  • scale::float, optional, default=1: Multiply the image with a scale value.
  • max_random_contrast::float, optional, default=0: Change the contrast with a value randomly chosen from $[-max_random_contrast, max_random_contrast]$
  • max_random_illumination::float, optional, default=0: Change the illumination with a value randomly chosen from $[-max_random_illumination, max_random_illumination]$

Returns the constructed MXDataProvider.

source

# MXNet.mx.ImageRecordIter_v1Method.

ImageRecordIter_v1(path_imglist, path_imgrec, path_imgidx, aug_seq, label_width, data_shape, preprocess_threads, verbose, num_parts, part_index, device_id, shuffle_chunk_size, shuffle_chunk_seed, seed_aug, shuffle, seed, verbose, batch_size, round_batch, prefetch_buffer, ctx, dtype, resize, rand_crop, random_resized_crop, max_rotate_angle, max_aspect_ratio, min_aspect_ratio, max_shear_ratio, max_crop_size, min_crop_size, max_random_scale, min_random_scale, max_random_area, min_random_area, max_img_size, min_img_size, brightness, contrast, saturation, pca_noise, random_h, random_s, random_l, rotate, fill_value, data_shape, inter_method, pad, seed, mirror, rand_mirror, mean_img, mean_r, mean_g, mean_b, mean_a, std_r, std_g, std_b, std_a, scale, max_random_contrast, max_random_illumination, verbose)

Iterating on image RecordIO files

.. note::

$ImageRecordIter_v1$ is deprecated. Use $ImageRecordIter$ instead.

Read images batches from RecordIO files with a rich of data augmentation options.

One can use $tools/im2rec.py$ to pack individual image files into RecordIO files.

Defined in src/io/iterimagerecordio.cc:L352

Arguments:

  • data_name::Symbol: keyword argument, default :data. The name of the data.
  • label_name::Symbol: keyword argument, default :softmax_label. The name of the label. Could be nothing if no label is presented in this dataset.
  • path_imglist::string, optional, default='': Path to the image list (.lst) file. Generally created with tools/im2rec.py. Format (Tab separated): .
  • path_imgrec::string, optional, default='': Path to the image RecordIO (.rec) file or a directory path. Created with tools/im2rec.py.
  • path_imgidx::string, optional, default='': Path to the image RecordIO index (.idx) file. Created with tools/im2rec.py.
  • aug_seq::string, optional, default='aug_default': The augmenter names to represent sequence of augmenters to be applied, seperated by comma. Additional keyword parameters will be seen by these augmenters.
  • label_width::int, optional, default='1': The number of labels per image.
  • data_shape::Shape(tuple), required: The shape of one output image in (channels, height, width) format.
  • preprocess_threads::int, optional, default='4': The number of threads to do preprocessing.
  • verbose::boolean, optional, default=1: If or not output verbose information.
  • num_parts::int, optional, default='1': Virtually partition the data into these many parts.
  • part_index::int, optional, default='0': The i-th virtual partition to be read.
  • device_id::int, optional, default='0': The device id used to create context for internal NDArray. Setting deviceid to -1 will create Context::CPU(0). Setting deviceid to valid positive device id will create Context::CPUPinned(device_id). Default is 0.
  • shuffle_chunk_size::long (non-negative), optional, default=0: The data shuffle buffer size in MB. Only valid if shuffle is true.
  • shuffle_chunk_seed::int, optional, default='0': The random seed for shuffling
  • seed_aug::int or None, optional, default='None': Random seed for augmentations.
  • shuffle::boolean, optional, default=0: Whether to shuffle data randomly or not.
  • seed::int, optional, default='0': The random seed.
  • batch_size::int (non-negative), required: Batch size.
  • round_batch::boolean, optional, default=1: Whether to use round robin to handle overflow batch or not.
  • prefetch_buffer::long (non-negative), optional, default=4: Maximum number of batches to prefetch.
  • ctx::{'cpu', 'gpu'},optional, default='gpu': Context data loader optimized for.
  • dtype::{None, 'bfloat16', 'float16', 'float32', 'float64', 'int32', 'int64', 'int8', 'uint8'},optional, default='None': Output data type. $None$ means no change.
  • resize::int, optional, default='-1': Down scale the shorter edge to a new size before applying other augmentations.
  • rand_crop::boolean, optional, default=0: If or not randomly crop the image
  • random_resized_crop::boolean, optional, default=0: If or not perform random resized cropping on the image, as a standard preprocessing for resnet training on ImageNet data.
  • max_rotate_angle::int, optional, default='0': Rotate by a random degree in $[-v, v]$
  • max_aspect_ratio::float, optional, default=0: Change the aspect (namely width/height) to a random value. If minaspectratio is None then the aspect ratio ins sampled from [1 - maxaspectratio, 1 + maxaspectratio], else it is in $[min_aspect_ratio, max_aspect_ratio]$
  • min_aspect_ratio::float or None, optional, default=None: Change the aspect (namely width/height) to a random value in $[min_aspect_ratio, max_aspect_ratio]$
  • max_shear_ratio::float, optional, default=0: Apply a shear transformation (namely $(x,y)->(x+my,y)$) with $m$ randomly chose from $[-max_shear_ratio, max_shear_ratio]$
  • max_crop_size::int, optional, default='-1': Crop both width and height into a random size in $[min_crop_size, max_crop_size].$Ignored if $random_resized_crop$ is True.
  • min_crop_size::int, optional, default='-1': Crop both width and height into a random size in $[min_crop_size, max_crop_size].$Ignored if $random_resized_crop$ is True.
  • max_random_scale::float, optional, default=1: Resize into $[widths, heights]$ with $s$ randomly chosen from $[min_random_scale, max_random_scale]$. Ignored if $random_resized_crop$ is True.
  • min_random_scale::float, optional, default=1: Resize into $[widths, heights]$ with $s$ randomly chosen from $[min_random_scale, max_random_scale]$Ignored if $random_resized_crop$ is True.
  • max_random_area::float, optional, default=1: Change the area (namely width * height) to a random value in $[min_random_area, max_random_area]$. Ignored if $random_resized_crop$ is False.
  • min_random_area::float, optional, default=1: Change the area (namely width * height) to a random value in $[min_random_area, max_random_area]$. Ignored if $random_resized_crop$ is False.
  • max_img_size::float, optional, default=1e+10: Set the maximal width and height after all resize and rotate argumentation are applied
  • min_img_size::float, optional, default=0: Set the minimal width and height after all resize and rotate argumentation are applied
  • brightness::float, optional, default=0: Add a random value in $[-brightness, brightness]$ to the brightness of image.
  • contrast::float, optional, default=0: Add a random value in $[-contrast, contrast]$ to the contrast of image.
  • saturation::float, optional, default=0: Add a random value in $[-saturation, saturation]$ to the saturation of image.
  • pca_noise::float, optional, default=0: Add PCA based noise to the image.
  • random_h::int, optional, default='0': Add a random value in $[-random_h, random_h]$ to the H channel in HSL color space.
  • random_s::int, optional, default='0': Add a random value in $[-random_s, random_s]$ to the S channel in HSL color space.
  • random_l::int, optional, default='0': Add a random value in $[-random_l, random_l]$ to the L channel in HSL color space.
  • rotate::int, optional, default='-1': Rotate by an angle. If set, it overwrites the $max_rotate_angle$ option.
  • fill_value::int, optional, default='255': Set the padding pixels value to $fill_value$.
  • inter_method::int, optional, default='1': The interpolation method: 0-NN 1-bilinear 2-cubic 3-area 4-lanczos4 9-auto 10-rand.
  • pad::int, optional, default='0': Change size from $[width, height]$ into $[pad + width + pad, pad + height + pad]$ by padding pixes
  • mirror::boolean, optional, default=0: Whether to mirror the image or not. If true, images are flipped along the horizontal axis.
  • rand_mirror::boolean, optional, default=0: Whether to randomly mirror images or not. If true, 50% of the images will be randomly mirrored (flipped along the horizontal axis)
  • mean_img::string, optional, default='': Filename of the mean image.
  • mean_r::float, optional, default=0: The mean value to be subtracted on the R channel
  • mean_g::float, optional, default=0: The mean value to be subtracted on the G channel
  • mean_b::float, optional, default=0: The mean value to be subtracted on the B channel
  • mean_a::float, optional, default=0: The mean value to be subtracted on the alpha channel
  • std_r::float, optional, default=1: Augmentation Param: Standard deviation on R channel.
  • std_g::float, optional, default=1: Augmentation Param: Standard deviation on G channel.
  • std_b::float, optional, default=1: Augmentation Param: Standard deviation on B channel.
  • std_a::float, optional, default=1: Augmentation Param: Standard deviation on Alpha channel.
  • scale::float, optional, default=1: Multiply the image with a scale value.
  • max_random_contrast::float, optional, default=0: Change the contrast with a value randomly chosen from $[-max_random_contrast, max_random_contrast]$
  • max_random_illumination::float, optional, default=0: Change the illumination with a value randomly chosen from $[-max_random_illumination, max_random_illumination]$

Returns the constructed MXDataProvider.

source

# MXNet.mx.ImageRecordUInt8IterMethod.

ImageRecordUInt8Iter(path_imglist, path_imgrec, path_imgidx, aug_seq, label_width, data_shape, preprocess_threads, verbose, num_parts, part_index, device_id, shuffle_chunk_size, shuffle_chunk_seed, seed_aug, shuffle, seed, verbose, batch_size, round_batch, prefetch_buffer, ctx, dtype, resize, rand_crop, random_resized_crop, max_rotate_angle, max_aspect_ratio, min_aspect_ratio, max_shear_ratio, max_crop_size, min_crop_size, max_random_scale, min_random_scale, max_random_area, min_random_area, max_img_size, min_img_size, brightness, contrast, saturation, pca_noise, random_h, random_s, random_l, rotate, fill_value, data_shape, inter_method, pad)

Can also be called with the alias ImageRecordUInt8Provider. Iterating on image RecordIO files

.. note:: ImageRecordUInt8Iter is deprecated. Use ImageRecordIter(dtype='uint8') instead.

This iterator is identical to $ImageRecordIter$ except for using $uint8$ as the data type instead of $float$.

Defined in src/io/iterimagerecordio_2.cc:L923

Arguments:

  • data_name::Symbol: keyword argument, default :data. The name of the data.
  • label_name::Symbol: keyword argument, default :softmax_label. The name of the label. Could be nothing if no label is presented in this dataset.
  • path_imglist::string, optional, default='': Path to the image list (.lst) file. Generally created with tools/im2rec.py. Format (Tab separated): .
  • path_imgrec::string, optional, default='': Path to the image RecordIO (.rec) file or a directory path. Created with tools/im2rec.py.
  • path_imgidx::string, optional, default='': Path to the image RecordIO index (.idx) file. Created with tools/im2rec.py.
  • aug_seq::string, optional, default='aug_default': The augmenter names to represent sequence of augmenters to be applied, seperated by comma. Additional keyword parameters will be seen by these augmenters.
  • label_width::int, optional, default='1': The number of labels per image.
  • data_shape::Shape(tuple), required: The shape of one output image in (channels, height, width) format.
  • preprocess_threads::int, optional, default='4': The number of threads to do preprocessing.
  • verbose::boolean, optional, default=1: If or not output verbose information.
  • num_parts::int, optional, default='1': Virtually partition the data into these many parts.
  • part_index::int, optional, default='0': The i-th virtual partition to be read.
  • device_id::int, optional, default='0': The device id used to create context for internal NDArray. Setting deviceid to -1 will create Context::CPU(0). Setting deviceid to valid positive device id will create Context::CPUPinned(device_id). Default is 0.
  • shuffle_chunk_size::long (non-negative), optional, default=0: The data shuffle buffer size in MB. Only valid if shuffle is true.
  • shuffle_chunk_seed::int, optional, default='0': The random seed for shuffling
  • seed_aug::int or None, optional, default='None': Random seed for augmentations.
  • shuffle::boolean, optional, default=0: Whether to shuffle data randomly or not.
  • seed::int, optional, default='0': The random seed.
  • batch_size::int (non-negative), required: Batch size.
  • round_batch::boolean, optional, default=1: Whether to use round robin to handle overflow batch or not.
  • prefetch_buffer::long (non-negative), optional, default=4: Maximum number of batches to prefetch.
  • ctx::{'cpu', 'gpu'},optional, default='gpu': Context data loader optimized for.
  • dtype::{None, 'bfloat16', 'float16', 'float32', 'float64', 'int32', 'int64', 'int8', 'uint8'},optional, default='None': Output data type. $None$ means no change.
  • resize::int, optional, default='-1': Down scale the shorter edge to a new size before applying other augmentations.
  • rand_crop::boolean, optional, default=0: If or not randomly crop the image
  • random_resized_crop::boolean, optional, default=0: If or not perform random resized cropping on the image, as a standard preprocessing for resnet training on ImageNet data.
  • max_rotate_angle::int, optional, default='0': Rotate by a random degree in $[-v, v]$
  • max_aspect_ratio::float, optional, default=0: Change the aspect (namely width/height) to a random value. If minaspectratio is None then the aspect ratio ins sampled from [1 - maxaspectratio, 1 + maxaspectratio], else it is in $[min_aspect_ratio, max_aspect_ratio]$
  • min_aspect_ratio::float or None, optional, default=None: Change the aspect (namely width/height) to a random value in $[min_aspect_ratio, max_aspect_ratio]$
  • max_shear_ratio::float, optional, default=0: Apply a shear transformation (namely $(x,y)->(x+my,y)$) with $m$ randomly chose from $[-max_shear_ratio, max_shear_ratio]$
  • max_crop_size::int, optional, default='-1': Crop both width and height into a random size in $[min_crop_size, max_crop_size].$Ignored if $random_resized_crop$ is True.
  • min_crop_size::int, optional, default='-1': Crop both width and height into a random size in $[min_crop_size, max_crop_size].$Ignored if $random_resized_crop$ is True.
  • max_random_scale::float, optional, default=1: Resize into $[widths, heights]$ with $s$ randomly chosen from $[min_random_scale, max_random_scale]$. Ignored if $random_resized_crop$ is True.
  • min_random_scale::float, optional, default=1: Resize into $[widths, heights]$ with $s$ randomly chosen from $[min_random_scale, max_random_scale]$Ignored if $random_resized_crop$ is True.
  • max_random_area::float, optional, default=1: Change the area (namely width * height) to a random value in $[min_random_area, max_random_area]$. Ignored if $random_resized_crop$ is False.
  • min_random_area::float, optional, default=1: Change the area (namely width * height) to a random value in $[min_random_area, max_random_area]$. Ignored if $random_resized_crop$ is False.
  • max_img_size::float, optional, default=1e+10: Set the maximal width and height after all resize and rotate argumentation are applied
  • min_img_size::float, optional, default=0: Set the minimal width and height after all resize and rotate argumentation are applied
  • brightness::float, optional, default=0: Add a random value in $[-brightness, brightness]$ to the brightness of image.
  • contrast::float, optional, default=0: Add a random value in $[-contrast, contrast]$ to the contrast of image.
  • saturation::float, optional, default=0: Add a random value in $[-saturation, saturation]$ to the saturation of image.
  • pca_noise::float, optional, default=0: Add PCA based noise to the image.
  • random_h::int, optional, default='0': Add a random value in $[-random_h, random_h]$ to the H channel in HSL color space.
  • random_s::int, optional, default='0': Add a random value in $[-random_s, random_s]$ to the S channel in HSL color space.
  • random_l::int, optional, default='0': Add a random value in $[-random_l, random_l]$ to the L channel in HSL color space.
  • rotate::int, optional, default='-1': Rotate by an angle. If set, it overwrites the $max_rotate_angle$ option.
  • fill_value::int, optional, default='255': Set the padding pixels value to $fill_value$.
  • inter_method::int, optional, default='1': The interpolation method: 0-NN 1-bilinear 2-cubic 3-area 4-lanczos4 9-auto 10-rand.
  • pad::int, optional, default='0': Change size from $[width, height]$ into $[pad + width + pad, pad + height + pad]$ by padding pixes

Returns the constructed MXDataProvider.

source

# MXNet.mx.ImageRecordUInt8Iter_v1Method.

ImageRecordUInt8Iter_v1(path_imglist, path_imgrec, path_imgidx, aug_seq, label_width, data_shape, preprocess_threads, verbose, num_parts, part_index, device_id, shuffle_chunk_size, shuffle_chunk_seed, seed_aug, shuffle, seed, verbose, batch_size, round_batch, prefetch_buffer, ctx, dtype, resize, rand_crop, random_resized_crop, max_rotate_angle, max_aspect_ratio, min_aspect_ratio, max_shear_ratio, max_crop_size, min_crop_size, max_random_scale, min_random_scale, max_random_area, min_random_area, max_img_size, min_img_size, brightness, contrast, saturation, pca_noise, random_h, random_s, random_l, rotate, fill_value, data_shape, inter_method, pad)

Iterating on image RecordIO files

.. note::

$ImageRecordUInt8Iter_v1$ is deprecated. Use $ImageRecordUInt8Iter$ instead.

This iterator is identical to $ImageRecordIter$ except for using $uint8$ as the data type instead of $float$.

Defined in src/io/iterimagerecordio.cc:L377

Arguments:

  • data_name::Symbol: keyword argument, default :data. The name of the data.
  • label_name::Symbol: keyword argument, default :softmax_label. The name of the label. Could be nothing if no label is presented in this dataset.
  • path_imglist::string, optional, default='': Path to the image list (.lst) file. Generally created with tools/im2rec.py. Format (Tab separated): .
  • path_imgrec::string, optional, default='': Path to the image RecordIO (.rec) file or a directory path. Created with tools/im2rec.py.
  • path_imgidx::string, optional, default='': Path to the image RecordIO index (.idx) file. Created with tools/im2rec.py.
  • aug_seq::string, optional, default='aug_default': The augmenter names to represent sequence of augmenters to be applied, seperated by comma. Additional keyword parameters will be seen by these augmenters.
  • label_width::int, optional, default='1': The number of labels per image.
  • data_shape::Shape(tuple), required: The shape of one output image in (channels, height, width) format.
  • preprocess_threads::int, optional, default='4': The number of threads to do preprocessing.
  • verbose::boolean, optional, default=1: If or not output verbose information.
  • num_parts::int, optional, default='1': Virtually partition the data into these many parts.
  • part_index::int, optional, default='0': The i-th virtual partition to be read.
  • device_id::int, optional, default='0': The device id used to create context for internal NDArray. Setting deviceid to -1 will create Context::CPU(0). Setting deviceid to valid positive device id will create Context::CPUPinned(device_id). Default is 0.
  • shuffle_chunk_size::long (non-negative), optional, default=0: The data shuffle buffer size in MB. Only valid if shuffle is true.
  • shuffle_chunk_seed::int, optional, default='0': The random seed for shuffling
  • seed_aug::int or None, optional, default='None': Random seed for augmentations.
  • shuffle::boolean, optional, default=0: Whether to shuffle data randomly or not.
  • seed::int, optional, default='0': The random seed.
  • batch_size::int (non-negative), required: Batch size.
  • round_batch::boolean, optional, default=1: Whether to use round robin to handle overflow batch or not.
  • prefetch_buffer::long (non-negative), optional, default=4: Maximum number of batches to prefetch.
  • ctx::{'cpu', 'gpu'},optional, default='gpu': Context data loader optimized for.
  • dtype::{None, 'bfloat16', 'float16', 'float32', 'float64', 'int32', 'int64', 'int8', 'uint8'},optional, default='None': Output data type. $None$ means no change.
  • resize::int, optional, default='-1': Down scale the shorter edge to a new size before applying other augmentations.
  • rand_crop::boolean, optional, default=0: If or not randomly crop the image
  • random_resized_crop::boolean, optional, default=0: If or not perform random resized cropping on the image, as a standard preprocessing for resnet training on ImageNet data.
  • max_rotate_angle::int, optional, default='0': Rotate by a random degree in $[-v, v]$
  • max_aspect_ratio::float, optional, default=0: Change the aspect (namely width/height) to a random value. If minaspectratio is None then the aspect ratio ins sampled from [1 - maxaspectratio, 1 + maxaspectratio], else it is in $[min_aspect_ratio, max_aspect_ratio]$
  • min_aspect_ratio::float or None, optional, default=None: Change the aspect (namely width/height) to a random value in $[min_aspect_ratio, max_aspect_ratio]$
  • max_shear_ratio::float, optional, default=0: Apply a shear transformation (namely $(x,y)->(x+my,y)$) with $m$ randomly chose from $[-max_shear_ratio, max_shear_ratio]$
  • max_crop_size::int, optional, default='-1': Crop both width and height into a random size in $[min_crop_size, max_crop_size].$Ignored if $random_resized_crop$ is True.
  • min_crop_size::int, optional, default='-1': Crop both width and height into a random size in $[min_crop_size, max_crop_size].$Ignored if $random_resized_crop$ is True.
  • max_random_scale::float, optional, default=1: Resize into $[widths, heights]$ with $s$ randomly chosen from $[min_random_scale, max_random_scale]$. Ignored if $random_resized_crop$ is True.
  • min_random_scale::float, optional, default=1: Resize into $[widths, heights]$ with $s$ randomly chosen from $[min_random_scale, max_random_scale]$Ignored if $random_resized_crop$ is True.
  • max_random_area::float, optional, default=1: Change the area (namely width * height) to a random value in $[min_random_area, max_random_area]$. Ignored if $random_resized_crop$ is False.
  • min_random_area::float, optional, default=1: Change the area (namely width * height) to a random value in $[min_random_area, max_random_area]$. Ignored if $random_resized_crop$ is False.
  • max_img_size::float, optional, default=1e+10: Set the maximal width and height after all resize and rotate argumentation are applied
  • min_img_size::float, optional, default=0: Set the minimal width and height after all resize and rotate argumentation are applied
  • brightness::float, optional, default=0: Add a random value in $[-brightness, brightness]$ to the brightness of image.
  • contrast::float, optional, default=0: Add a random value in $[-contrast, contrast]$ to the contrast of image.
  • saturation::float, optional, default=0: Add a random value in $[-saturation, saturation]$ to the saturation of image.
  • pca_noise::float, optional, default=0: Add PCA based noise to the image.
  • random_h::int, optional, default='0': Add a random value in $[-random_h, random_h]$ to the H channel in HSL color space.
  • random_s::int, optional, default='0': Add a random value in $[-random_s, random_s]$ to the S channel in HSL color space.
  • random_l::int, optional, default='0': Add a random value in $[-random_l, random_l]$ to the L channel in HSL color space.
  • rotate::int, optional, default='-1': Rotate by an angle. If set, it overwrites the $max_rotate_angle$ option.
  • fill_value::int, optional, default='255': Set the padding pixels value to $fill_value$.
  • inter_method::int, optional, default='1': The interpolation method: 0-NN 1-bilinear 2-cubic 3-area 4-lanczos4 9-auto 10-rand.
  • pad::int, optional, default='0': Change size from $[width, height]$ into $[pad + width + pad, pad + height + pad]$ by padding pixes

Returns the constructed MXDataProvider.

source

# MXNet.mx.LibSVMIterMethod.

LibSVMIter(data_libsvm, data_shape, label_libsvm, label_shape, num_parts, part_index, batch_size, round_batch, prefetch_buffer, ctx, dtype)

Can also be called with the alias LibSVMProvider. Returns the LibSVM iterator which returns data with csr storage type. This iterator is experimental and should be used with care.

The input data is stored in a format similar to LibSVM file format, except that the indices are expected to be zero-based instead of one-based, and the column indices for each row are expected to be sorted in ascending order. Details of the LibSVM format are available here. <https://www.csie.ntu.edu.tw/~cjlin/libsvmtools/datasets/>_

The data_shape parameter is used to set the shape of each line of the data. The dimension of both data_shape and label_shape are expected to be 1.

The data_libsvm parameter is used to set the path input LibSVM file. When it is set to a directory, all the files in the directory will be read.

When label_libsvm is set to $NULL$, both data and label are read from the file specified by data_libsvm. In this case, the data is stored in csr storage type, while the label is a 1D dense array.

The LibSVMIter only support round_batch parameter set to $True$. Therefore, if batch_size is 3 and there are 4 total rows in libsvm file, 2 more examples are consumed at the first round.

When num_parts and part_index are provided, the data is split into num_parts partitions, and the iterator only reads the part_index-th partition. However, the partitions are not guaranteed to be even.

$reset()$ is expected to be called only after a complete pass of data.

Example::

Contents of libsvm file $data.t$.

1.0 0:0.5 2:1.2 -2.0 -3.0 0:0.6 1:2.4 2:1.2 4 2:-1.2

Creates a LibSVMIter with batch_size=3.

dataiter = mx.io.LibSVMIter(datalibsvm = 'data.t', datashape = (3,), batchsize = 3)

The data of the first batch is stored in csr storage type

batch = data_iter.next() csr = batch.data[0]

csr.asnumpy()

[[ 0.5 0. 1.2 ] [ 0. 0. 0. ] [ 0.6 2.4 1.2]]

The label of first batch

label = batch.label[0] label

[ 1. -2. -3.]

secondbatch = dataiter.next()

The data of the second batch

second_batch.data[0].asnumpy()

[[ 0. 0. -1.2 ] [ 0.5 0. 1.2 ] [ 0. 0. 0. ]]

The label of the second batch

second_batch.label[0].asnumpy()

[ 4. 1. -2.]

data_iter.reset()

To restart the iterator for the second pass of the data

When label_libsvm is set to the path to another LibSVM file, data is read from data_libsvm and label from label_libsvm. In this case, both data and label are stored in the csr format. If the label column in the data_libsvm file is ignored.

Example::

Contents of libsvm file $label.t$

1.0 -2.0 0:0.125 -3.0 2:1.2 4 1:1.0 2:-1.2

Creates a LibSVMIter with specified label file

dataiter = mx.io.LibSVMIter(datalibsvm = 'data.t', data_shape = (3,),

               label_libsvm = 'label.t', label_shape = (3,), batch_size = 3)

Both data and label are in csr storage type

batch = dataiter.next() csrdata = batch.data[0]

csr_data.asnumpy()

[[ 0.5 0. 1.2 ] [ 0. 0. 0. ] [ 0.6 2.4 1.2 ]]

csr_label = batch.label[0]

csr_label.asnumpy()

[[ 0. 0. 0. ] [ 0.125 0. 0. ] [ 0. 0. 1.2 ]]

Defined in src/io/iter_libsvm.cc:L298

Arguments:

  • data_name::Symbol: keyword argument, default :data. The name of the data.
  • label_name::Symbol: keyword argument, default :softmax_label. The name of the label. Could be nothing if no label is presented in this dataset.
  • data_libsvm::string, required: The input zero-base indexed LibSVM data file or a directory path.
  • data_shape::Shape(tuple), required: The shape of one example.
  • label_libsvm::string, optional, default='NULL': The input LibSVM label file or a directory path. If NULL, all labels will be read from $data_libsvm$.
  • label_shape::Shape(tuple), optional, default=[1]: The shape of one label.
  • num_parts::int, optional, default='1': partition the data into multiple parts
  • part_index::int, optional, default='0': the index of the part will read
  • batch_size::int (non-negative), required: Batch size.
  • round_batch::boolean, optional, default=1: Whether to use round robin to handle overflow batch or not.
  • prefetch_buffer::long (non-negative), optional, default=4: Maximum number of batches to prefetch.
  • ctx::{'cpu', 'gpu'},optional, default='gpu': Context data loader optimized for.
  • dtype::{None, 'bfloat16', 'float16', 'float32', 'float64', 'int32', 'int64', 'int8', 'uint8'},optional, default='None': Output data type. $None$ means no change.

Returns the constructed MXDataProvider.

source

# MXNet.mx.MNISTIterMethod.

MNISTIter(image, label, batch_size, shuffle, flat, seed, silent, num_parts, part_index, prefetch_buffer, ctx, dtype)

Can also be called with the alias MNISTProvider. Iterating on the MNIST dataset.

One can download the dataset from http://yann.lecun.com/exdb/mnist/

Defined in src/io/iter_mnist.cc:L265

Arguments:

  • data_name::Symbol: keyword argument, default :data. The name of the data.
  • label_name::Symbol: keyword argument, default :softmax_label. The name of the label. Could be nothing if no label is presented in this dataset.
  • image::string, optional, default='./train-images-idx3-ubyte': Dataset Param: Mnist image path.
  • label::string, optional, default='./train-labels-idx1-ubyte': Dataset Param: Mnist label path.
  • batch_size::int, optional, default='128': Batch Param: Batch Size.
  • shuffle::boolean, optional, default=1: Augmentation Param: Whether to shuffle data.
  • flat::boolean, optional, default=0: Augmentation Param: Whether to flat the data into 1D.
  • seed::int, optional, default='0': Augmentation Param: Random Seed.
  • silent::boolean, optional, default=0: Auxiliary Param: Whether to print out data info.
  • num_parts::int, optional, default='1': partition the data into multiple parts
  • part_index::int, optional, default='0': the index of the part will read
  • prefetch_buffer::long (non-negative), optional, default=4: Maximum number of batches to prefetch.
  • ctx::{'cpu', 'gpu'},optional, default='gpu': Context data loader optimized for.
  • dtype::{None, 'bfloat16', 'float16', 'float32', 'float64', 'int32', 'int64', 'int8', 'uint8'},optional, default='None': Output data type. $None$ means no change.

Returns the constructed MXDataProvider.

source

# MXNet.mx.eachbatchMethod.

eachbatch(provider::AbstractDataProvider)

Allows you to perform operations on data every epoch. This is especially useful when you need to perform real-time augmentation of the data.

Arguments:

  • provider: an instance of the custom DataProvider type. You must return this

instance after modifying its fields.

source

# MXNet.mx.from_jsonMethod.

from_json(repr :: AbstractString, ::Type{SymbolicNode})

Load a SymbolicNode from a JSON string representation.

source

# MXNet.mx.is_sharedMethod.

is_shared(j_arr, arr)

Test whether j_arr is sharing data with arr.

Arguments:

  • j_arr::Array: the Julia Array.
  • arr::NDArray: the NDArray.

source

# MXNet.mx.loadMethod.

load(filename, ::Type{NDArray})

Load NDArrays from binary file.

Arguments:

  • filename::String: the path of the file to load. It could be S3 or HDFS address.

Returns either Dict{Symbol, NDArray} or Vector{NDArray}.

filename can point to s3 or hdfs resources if the libmxnet is built with the corresponding components enabled. Examples:

  • s3://my-bucket/path/my-s3-ndarray
  • hdfs://my-bucket/path/my-hdfs-ndarray
  • /path-to/my-local-ndarray

source

# MXNet.mx.loadMethod.

load(filename :: AbstractString, ::Type{SymbolicNode})

Load a SymbolicNode from a JSON file.

source

# MXNet.mx.load_data!Method.

load_data!(provider, batch, targets)

Arguments:

  • provider::AbstractDataProvider: the data provider.
  • batch::AbstractDataBatch: the data batch object.
  • targets::Vector{Vector{SlicedNDArray}}: the targets to load data into.

The targets is a list of the same length as number of data provided by this provider. Each element in the list is a list of SlicedNDArray. This list described a spliting scheme of this data batch into different slices, each slice is specified by a slice-ndarray pair, where slice specify the range of samples in the mini-batch that should be loaded into the corresponding ndarray.

This utility function is used in data parallelization, where a mini-batch is splited and computed on several different devices.

source

# MXNet.mx.load_label!Method.

load_label!(provider, batch, targets)
  • provider::AbstractDataProvider provider: the data provider.
  • batch::AbstractDataBatch batch: the data batch object.
  • targets::Vector{Vector{SlicedNDArray}}: the targets to load label into.

The same as load_data!, except that this is for loading labels.

source

# MXNet.mx.saveMethod.

save(filename :: AbstractString, node :: SymbolicNode)

Save a SymbolicNode to a JSON file.

source

# MXNet.mx.saveMethod.

save(filename::AbstractString, data)

Save NDarrays to binary file. Filename could be S3 or HDFS address, if libmxnet is built with corresponding support (see load).

  • filename::String: path to the binary file to write to.
  • data: data to save to file. Data can be aNDArray, a Vector of NDArray, or a Dict{Symbol} contains NDArrays.

source

# MXNet.mx.to_jsonMethod.

to_json(s::SymbolicNode)

Convert a SymbolicNode into a JSON string.

source

# MXNet.mx.try_get_sharedMethod.

try_get_shared(arr; sync=:nop)

Try to create a Julia array by sharing the data with the underlying NDArray.

Arguments:

  • arr::NDArray: the array to be shared.

Note

The returned array does not guarantee to share data with the underlying NDArray. In particular, data sharing is possible only when the NDArray lives on CPU.

  • sync::Symbol: :nop,:write, :read On CPU, invoke _wait_to_read if :read; invoke _wait_to_write if :write.

source