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.
Datastores
The calibrate
and
validate
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 | |
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 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 |
---|---|
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. |
Features | 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 |
---|---|
Classification | Categorical scalar |
Regression |
|
Segmentation | The default format returned by reading from a |
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
calibrate
| validate
| datastore
| read
| dlquantizer
| quantize