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.
functions require the calibration data and validation data to be passed as a
datastore object. Many built-in datastores are supported for quantization
workflows. The supported datastores for particular networks are detailed below. Passing
data as a numeric array or 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
The following table describes which built-in datastores are supported for quantization of different network types.
|Network Type||Supported Datastores|
Image classification or regression
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 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.
The format of the predictors used for calibration and validation depends on the type of input.
|Data||Format of Predictors|
h-by-w-by-c numeric array, where h, w, and c are the height, width, and number of channels of the image, respectively.
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 depend on the type of task.
|Task||Format of Responses|
The default format returned by reading from a
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
functions of datastores are useful in preparing data to be fed into a network.
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
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 function combines data from multiple datastores. Operating
on the resulting
such as resetting the datastore, performs the same operation on all of the
functions support only
objects with two underlying datastores. The first datastore must be an
arrayDatastore and the second datastore must be a
pixelLabelDatastore (Computer Vision Toolbox) or