Contenido principal

ProjectedLayer

Compressed neural network layer using projection

Since R2023b

    Description

    Add-On Required: This feature requires the Deep Learning Toolbox Model Compression Library add-on.

    A projected layer is a compressed neural network layer resulting from projection.

    Creation

    To compress a neural network using projection, use the compressNetworkUsingProjection function.

    Properties

    expand all

    Projected

    This property is read-only.

    Class of the original layer, returned as a character vector.

    Example: 'nnet.cnn.layer.LSTMLayer'

    Data Types: char

    This property is read-only.

    Proportion of learnables removed in the layer, returned as a scalar in the interval [0,1].

    Data Types: double

    Neural network that represents projection, returned as a dlnetwork object.

    The neural network that represents the projection depends on the type of layer:

    Original LayerNetwork

    convolution1dLayer (since R2024b)

    Network containing two or three convolution1dLayer objects
    convolution2dLayerNetwork containing two or three convolution2dLayer objects
    fullyConnectedLayerNetwork containing two fullyConnectedLayer objects
    lstmLayerNetwork containing a single lstmProjectedLayer object
    gruLayerNetwork containing a single gruProjectedLayer object

    For more information, see Projected Layer. To replace the ProjectedLayer objects in a neural network with the equivalent network that represents the projection, use the unpackProjectedLayers function.

    This property is read-only.

    Number of input channels, returned as a positive integer.

    Data Types: double

    This property is read-only.

    Number of output channels, returned as a positive integer.

    Data Types: double

    This property is read-only.

    Number of columns of the input projector, returned as a positive integer.

    The input projector is the matrix Q used to project the layer input. For more information, see Projected Layer.

    Data Types: double

    This property is read-only.

    Number of columns of the output projector, returned as a positive integer.

    The output projector is the matrix Q used to project the layer output. For more information, see Projected Layer.

    Data Types: double

    Layer

    Layer name, specified as a character vector or a string scalar. For Layer array input, the trainnet and dlnetwork functions automatically assign new unique names to layers that have the name "".

    When you compress a neural network using the compressNetworkUsingProjection, the function replaces projectable layers with ProjectedLayer objects with the same name.

    The ProjectedLayer object stores this property as a character vector.

    Data Types: char | string

    This property is read-only.

    Number of inputs to the layer, returned as a positive integer.

    Data Types: double

    Input names, returned as a cell array of character vectors.

    Data Types: cell

    This property is read-only.

    Number of outputs from the layer, returned as a positive integer.

    Data Types: double

    Output names, returned as a cell array of character vectors.

    Data Types: cell

    Examples

    collapse all

    Load the pretrained network in dlnetJapaneseVowels and the training data in JapaneseVowelsTrainData.

    load dlnetJapaneseVowels
    load JapaneseVowelsTrainData

    Compress the network. Specify the mini-batch size for the principal component analysis as 16. Specify the input data format as "CTB".

    [netProjected,info] = compressNetworkUsingProjection(net,XTrain,MiniBatchSize=16,InputDataFormats="CTB");
    Compressed network has 85.4% fewer learnable parameters.
    Projection compressed 2 layers: "lstm","fc"
    

    View the network layers.

    netProjected.Layers
    ans = 
      4×1 Layer array with layers:
    
         1   'sequenceinput'   Sequence Input    Sequence input with 12 channels
         2   'lstm'            Projected Layer   Projected LSTM with 100 hidden units
         3   'fc'              Projected Layer   Projected fully connected layer with output size 9
         4   'softmax'         Softmax           Softmax
    

    View the projected LSTM layer.

    netProjected.Layers(2)
    ans = 
      ProjectedLayer with properties:
    
                       Name: 'lstm'
              OriginalClass: 'nnet.cnn.layer.LSTMLayer'
        LearnablesReduction: 0.8610
                  InputSize: 12
                 OutputSize: 100
    
       Hyperparameters
         InputProjectorSize: 7
        OutputProjectorSize: 6
    
       Learnable Parameters
                    Network: [1×1 dlnetwork]
    
       State Parameters
                    Network: [1×1 dlnetwork]
    
       Network Learnable Parameters
         Network/lstm/InputWeights      400×7 dlarray
         Network/lstm/RecurrentWeights  400×6 dlarray
         Network/lstm/Bias              400×1 dlarray
         Network/lstm/InputProjector    12×7  dlarray
         Network/lstm/OutputProjector   100×6 dlarray
    
       Network State Parameters
         Network/lstm/HiddenState  100×1 dlarray
         Network/lstm/CellState    100×1 dlarray
    
      Show all properties
    
    

    Load the pretrained network in dlnetProjectedJapaneseVowels.

    load dlnetProjectedJapaneseVowels

    View the network properties.

    net
    net = 
      dlnetwork with properties:
    
             Layers: [4×1 nnet.cnn.layer.Layer]
        Connections: [3×2 table]
         Learnables: [9×3 table]
              State: [2×3 table]
         InputNames: {'sequenceinput'}
        OutputNames: {'softmax'}
        Initialized: 1
    
      View summary with summary.
    
    

    View the network layers. The network has two projected layers.

    net.Layers
    ans = 
      4×1 Layer array with layers:
    
         1   'sequenceinput'   Sequence Input    Sequence input with 12 channels
         2   'lstm'            Projected Layer   Projected LSTM with 100 hidden units
         3   'fc'              Projected Layer   Projected fully connected layer with output size 9
         4   'softmax'         Softmax           Softmax
    

    Unpack the projected layers.

    netUnpacked = unpackProjectedLayers(net)
    netUnpacked = 
      dlnetwork with properties:
    
             Layers: [5×1 nnet.cnn.layer.Layer]
        Connections: [4×2 table]
         Learnables: [9×3 table]
              State: [2×3 table]
         InputNames: {'sequenceinput'}
        OutputNames: {'softmax'}
        Initialized: 1
    
      View summary with summary.
    
    

    View the unpacked network layers. The unpacked network has a projected LSTM layer and two fully connected layers in place of the projected layers.

    netUnpacked.Layers
    ans = 
      5×1 Layer array with layers:
    
         1   'sequenceinput'   Sequence Input    Sequence input with 12 channels
         2   'lstm'            Projected LSTM    Projected LSTM with 100 hidden units, an output projector size of 7, and an input projector size of 8
         3   'fc_proj_in'      Fully Connected   Fully connected layer with output size 4
         4   'fc_proj_out'     Fully Connected   Fully connected layer with output size 9
         5   'softmax'         Softmax           Softmax
    

    Algorithms

    expand all

    References

    [1] "Compressing Neural Networks Using Network Projection." Accessed July 20, 2023. https://www.mathworks.com/company/technical-articles/compressing-neural-networks-using-network-projection.html.

    Extended Capabilities

    expand all

    C/C++ Code Generation
    Generate C and C++ code using MATLAB® Coder™.

    Version History

    Introduced in R2023b

    expand all