Main Content


Display the details for a quantized network



    qDetails = quantizationDetails(net) returns the details for your quantized network. The data is returned as a structure with the fields:

    • IsQuantized: True(1) if the network is quantized

    • TargetLibrary: Target library for code generation

    • QuantizedLayerNames: List of quantized layers

    • QuantizedLearnables: Quantized network learnable parameters


    collapse all

    This example shows how to display the details for a quantized network. The example uses the pretrained squeezeNet convolutional neural network to demonstrate quantization for the network.

    First load the squeezeNet network.

    load squeezenetmerch
    net = 
      DAGNetwork with properties:
             Layers: [68×1 nnet.cnn.layer.Layer]
        Connections: [75×2 table]
         InputNames: {'data'}
        OutputNames: {'new_classoutput'}

    Define calibration and validation data to use for quantization.

    Use the calibration data to collect the dynamic ranges of the weights and biases in the convolution and fully connected layers of the network and the dynamic ranges of the activations in all layers of the network. For the best quantization results, the calibration data must be representative of inputs to the network.

    Use the validation data to test the network after quantization to understand the effects of the limited range and precision of the quantized convolution layers in the network.

    For this example, use the images in the MerchData data set. Define an augmentedImageDatastore object to resize the data for the network. Then, split the data into calibration and validation data sets.

    imds = imageDatastore('MerchData', ...
        'IncludeSubfolders',true, ...
    [calData, valData] = splitEachLabel(imds, 0.7, 'randomized');
    aug_calData = augmentedImageDatastore([227 227], calData);
    aug_valData = augmentedImageDatastore([227 227], valData);

    Create a dlquantizer object and specify the network to quantize.

    quantObj = dlquantizer(net,'ExecutionEnvironment','MATLAB');

    Calibrate the network.

    calResults = calibrate(quantObj, aug_calData)
    calResults=121×5 table
            Optimized Layer Name         Network Layer Name     Learnables / Activations    MinValue     MaxValue
        ____________________________    ____________________    ________________________    _________    ________
        {'conv1_Weights'           }    {'conv1'           }           "Weights"             -0.91985     0.88489
        {'conv1_Bias'              }    {'conv1'           }           "Bias"                -0.07925     0.26343
        {'fire2-squeeze1x1_Weights'}    {'fire2-squeeze1x1'}           "Weights"                -1.38      1.2477
        {'fire2-squeeze1x1_Bias'   }    {'fire2-squeeze1x1'}           "Bias"                -0.11641     0.24273
        {'fire2-expand1x1_Weights' }    {'fire2-expand1x1' }           "Weights"              -0.7406     0.90982
        {'fire2-expand1x1_Bias'    }    {'fire2-expand1x1' }           "Bias"               -0.060056     0.14602
        {'fire2-expand3x3_Weights' }    {'fire2-expand3x3' }           "Weights"             -0.74397     0.66905
        {'fire2-expand3x3_Bias'    }    {'fire2-expand3x3' }           "Bias"               -0.051778    0.074239
        {'fire3-squeeze1x1_Weights'}    {'fire3-squeeze1x1'}           "Weights"              -0.7712     0.68917
        {'fire3-squeeze1x1_Bias'   }    {'fire3-squeeze1x1'}           "Bias"                -0.10138     0.32675
        {'fire3-expand1x1_Weights' }    {'fire3-expand1x1' }           "Weights"             -0.72035      0.9743
        {'fire3-expand1x1_Bias'    }    {'fire3-expand1x1' }           "Bias"               -0.067029     0.30425
        {'fire3-expand3x3_Weights' }    {'fire3-expand3x3' }           "Weights"             -0.61443      0.7741
        {'fire3-expand3x3_Bias'    }    {'fire3-expand3x3' }           "Bias"               -0.053613     0.10329
        {'fire4-squeeze1x1_Weights'}    {'fire4-squeeze1x1'}           "Weights"              -0.7422      1.0877
        {'fire4-squeeze1x1_Bias'   }    {'fire4-squeeze1x1'}           "Bias"                -0.10885     0.13881
    qNet = quantize(quantObj)
    qNet = 
    Quantized DAGNetwork with properties:
             Layers: [68×1 nnet.cnn.layer.Layer]
        Connections: [75×2 table]
         InputNames: {'data'}
        OutputNames: {'new_classoutput'}
    Use the quantizationDetails method to extract quantization details.
    qDetails = quantizationDetails(qNet) 
    qDetails = struct with fields:
                IsQuantized: 1
              TargetLibrary: "none"
        QuantizedLayerNames: [26×1 string]
        QuantizedLearnables: [52×3 table]

    Input Arguments

    collapse all

    Quantized neural network specified as a DAGNetwork, SeriesNetwork, or a dlnetwork (Computer Vision Toolbox).

    Version History

    Introduced in R2022a