Main Content

spatialDropoutLayer

Spatial dropout layer

Since R2024a

    Description

    A spatial dropout layer randomly selects input channels with a given probability, and sets all its elements to zero during training.

    Creation

    Description

    layer = spatialDropoutLayer creates a spatial dropout layer.

    layer = spatialDropoutLayer(Name=Value) sets the optional Probability and Name properties using name-value arguments. For example, spatialDropoutLayer(Probability=0.25) creates a spatial dropout layer with dropout probability 0.25. spatialDropoutLayer(Name="spat1") creates a spatial dropout layer with name "spat1".

    example

    Properties

    expand all

    Dropout

    Probability for dropping out all input elements in a channel, specified as a nonnegative number less than 1.

    For an input of size [sizeDim1,...,sizeCDim, sizeBDim,...,sizeDimN], where sizeCDim is the number of channels, and sizeBDim is the batch size, a dropout mask is created using rand([1,...,sizeCDim, sizeBDim,...,1])<Probability. The input to the rand function is a vector of ones except at the locations of the channel dimension and the batch dimension. At training time, the layer randomly sets all the input elements to zero according to the dropout mask. It then scales the remaining elements by 1/(1-Probability). This operation effectively improve generalization performance by preventing activations from becoming strongly correlated [1], and helps prevent the network from overfitting. A higher probability results in more elements being dropped during training. At prediction time, the output of the layer is equal to its input.

    Example: 0.4

    Layer

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

    The SpatialDropoutLayer 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 1. This layer accepts a single input only.

    Data Types: double

    This property is read-only.

    Input names, returned as {'in'}. This layer accepts a single input only.

    Data Types: cell

    This property is read-only.

    Number of outputs from the layer, returned as 1. This layer has a single output only.

    Data Types: double

    This property is read-only.

    Output names, returned as {'out'}. This layer has a single output only.

    Data Types: cell

    Examples

    collapse all

    Create a spatial dropout layer with name "spat_drop1" and dropout probability 0.25.

    layer = spatialDropoutLayer(Name="spat_drop1",Probability=0.25)
    layer = 
      SpatialDropoutLayer with properties:
    
               Name: 'spat_drop1'
        Probability: 0.2500
    
       Learnable Parameters
        No properties.
    
       State Parameters
        No properties.
    
    Use properties method to see a list of all properties.
    
    

    Include a spatial dropout layer in a Layer array.

    layers = [ ...
        imageInputLayer([28 28 1])
        convolution2dLayer(5,20)
        reluLayer
        spatialDropoutLayer
        fullyConnectedLayer(10)
        softmaxLayer]
    layers = 
      6x1 Layer array with layers:
    
         1   ''   Image Input       28x28x1 images with 'zerocenter' normalization
         2   ''   2-D Convolution   20 5x5 convolutions with stride [1  1] and padding [0  0  0  0]
         3   ''   ReLU              ReLU
         4   ''   Spatial Dropout   Spatial Dropout
         5   ''   Fully Connected   10 fully connected layer
         6   ''   Softmax           softmax
    

    References

    [1] Jonathan Tompson, Ross Goroshin, Arjun Jain, Yann LeCun, and Christoph Bregler. "Efficient Object Localization Using Convolution Networks." arXiv preprint arXiv:1411.4280v3 (2015)

    Extended Capabilities

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

    GPU Code Generation
    Generate CUDA® code for NVIDIA® GPUs using GPU Coder™.

    Version History

    Introduced in R2024a