Main Content

Prepare Data for Quantizing Networks

Quantizing a deep neural network in MATLAB® requires calibration by exercising the network to determine the dynamic ranges of its weights, biases, and activations. After calibrating, you can validate the performance of the quantized network and inspect the reduction in size and performance (if any) of the network. However, not all data formats supported for training and prediction are supported for quantization workflows.


The calibrate function requires that calibration data be passed as a datastore object or a numeric array. The validate function requires validation data to be passed as a datastore object. Passing data as a numeric array is not supported for validate. Many built-in datastores are supported for quantization workflows. The supported datastores for particular networks are detailed below. Passing data as a table is not supported.

For more information on using datastore objects for training and prediction, see Datastores for Deep Learning.

Choose a Built-In Datastore

This table describes which built-in datastores are supported for validation and quantization of different network types.

Network TypeSupported Datastores

Image classification or regression

Object detection

Semantic segmentation

Sequence and numeric feature classification and regression

Calibration and Validation

To be a valid input for validation, the read function of a datastore must return data either as a cell array or as a table with the responses as the second column.

As calibration exercises the network and collects the dynamic range statistics, the calibration data does not require responses. In addition to the datastores in the previous table, calibration supports the use of arrayDatastore objects.

The format of the predictors used for calibration and validation depends on the type of input.

DataFormat of Predictors
2-D image

h-by-w-by-c numeric array, where h, w, and c are the height, width, and number of channels of the image, respectively.

Vector sequence

c-by-s matrix, where c is the number of features of the sequence and s is the sequence length. Each sequence must have the same length.

2-D image sequence

h-by-w-by-c-by-s array, where h, w, and c correspond to the height, width, and number of channels of the image, respectively, and s is the sequence length.

Each sequence in the mini-batch must have the same sequence length.


1-by-c column vector, where c is the number of features.

For data returned in tables, the elements must contain a 1-by-1 cell array containing a numeric array.

For validation, the datastore must return responses. The format of the responses depends on the type of task.

For calibration data passed as a numeric array, the format of the predictors used for calibration has an additional dimension for the number of batches. For example, vector sequence input data with numeric calibration data is a c-by-s-by-b array, where c is the number of features of the sequence, s is the sequence length, and b is the number of batches.

TaskFormat of Responses
ClassificationCategorical scalar

  • Scalar

  • Numeric vector

  • 3-D numeric array representing an image


The default format returned by reading from a pixelLabelDatastore (Computer Vision Toolbox)

Object detection

Categorical array

Transform and Combine Datastores

Deep learning frequently requires data to be preprocessed and augmented before data is in an appropriate form to input to a network. The transform and combine functions of datastores are useful in preparing data to be fed into a network.

Transform Datastores

A transformed datastore applies a particular data transformation to an underlying datastore when reading data. To create a transformed datastore, use the transform function and specify the underlying datastore and the transformation.

For validation, reading from a transformed datastore must return a cell array with the predictors as the first column and the responses as the third column.

Combine Datastores

The combine function combines data from multiple datastores. Operating on the resulting CombinedDatastore, such as resetting the datastore, performs the same operation on all of the underlying datastores.

The calibrate and validate functions support only CombinedDatastore objects with two underlying datastores. The first datastore must be an imageDatastore, augmentedImageDatastore, or arrayDatastore and the second datastore must be a pixelLabelDatastore (Computer Vision Toolbox) or arrayDatastore.

See Also

| | | | |

Related Topics