Main Content

inputLayer

Input layer

Since R2023b

    Description

    An input layer inputs unformatted data or data with a custom format into a neural network.

    Creation

    Description

    layer = inputLayer(inputSize) creates an input layer for unformatted data. (since R2025a)

    layer = inputLayer(inputSize,inputFormat) creates an input layer and specifies a custom data format.

    example

    layer = inputLayer(___,Name=name) also specifies the layer name in addition to any of the input argument combinations in previous syntaxes. For example, Name="in" specifies that the layer has the name "in".

    Input Arguments

    expand all

    Size of the input, specified as a row vector of positive integers or NaN.

    For networks that support variable sizes for the batch or time dimensions, specify the size of the corresponding dimension as NaN.

    This argument sets the InputSize property.

    Example: [224 224 3]

    Data Types: single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64

    Description of the data dimensions, specified as a character vector or string scalar.

    A data format is a string of characters, where each character describes the type of the corresponding data dimension.

    The characters are:

    • "S" — Spatial

    • "C" — Channel

    • "B" — Batch

    • "T" — Time

    • "U" — Unspecified

    For example, consider an array that represents a batch of sequences where the first, second, and third dimensions correspond to channels, observations, and time steps, respectively. You can describe the data as having the format "CBT" (channel, batch, time).

    If InputFormat is "", then the layer passes unformatted data to the neural network directly. Ensure that subsequent layers support unformatted input data. (since R2025a)

    For the layer input format, you can specify multiple dimensions labeled "S" or "U". You can use the labels "C", "B", and "T" at most once. When the number of dimensions is greater than two, the input size corresponding to the rightmost "U" dimension in the input format must be greater than 1.

    For more information, see Deep Learning Data Formats.

    This argument sets the InputFormat property.

    Example: "SSCB"

    Example: "SCBT"

    Example: "TCB"

    Data Types: char | string

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

    This argument sets the Name property.

    Data Types: char | string

    Properties

    expand all

    Input

    This property is read-only.

    This property is read-only after creation.

    Size of the input, stored as a row vector of positive integers or NaN.

    For networks that support variable sizes for the batch or time dimensions, the corresponding value is NaN.

    Data Types: double

    This property is read-only after creation.

    Description of the data dimensions, stored as a character vector.

    A data format is a string of characters, where each character describes the type of the corresponding data dimension.

    The characters are:

    • "S" — Spatial

    • "C" — Channel

    • "B" — Batch

    • "T" — Time

    • "U" — Unspecified

    For example, consider an array that represents a batch of sequences where the first, second, and third dimensions correspond to channels, observations, and time steps, respectively. You can describe the data as having the format "CBT" (channel, batch, time).

    If InputFormat is "", then the layer passes unformatted data to the neural network directly. Ensure that subsequent layers support unformatted input data. (since R2025a)

    For more information, see Deep Learning Data Formats.

    Data Types: char

    Layer

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

    The InputLayer object stores this property as a character vector.

    Data Types: char | string

    This property is read-only.

    Number of inputs of the layer. The layer has no inputs.

    Data Types: double

    This property is read-only.

    Input names of the layer. The layer has no inputs.

    Data Types: cell

    This property is read-only.

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

    Data Types: double

    This property is read-only.

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

    Data Types: cell

    Examples

    collapse all

    Create an input layer that inputs 1-D image data (3-D data, with dimensions corresponding to space, channels, and observations). Specify that the data has three channels and an image height size of 64. Specify that the batch dimension can vary.

    inputSize = [64 3 NaN];
    inputFormat = "SCB";
    layer = inputLayer(inputSize,inputFormat)
    layer = 
      InputLayer with properties:
    
               Name: ''
          InputSize: [64 3 NaN]
        InputFormat: 'SCB'
    
    

    Include the input layer in a network.

    layers = [
        inputLayer([64 3 NaN],"SCB")
        convolution1dLayer(5,32)
        batchNormalizationLayer
        reluLayer
        fullyConnectedLayer(10)
        softmaxLayer];

    Create an input layer that inputs spatiotemporal data (4-D data, with dimensions corresponding to space, channels, time, and observations). Specify that the data has three channels and a spatial size of 64. Specify that the batch and time dimensions can vary.

    inputSize = [64 3 NaN NaN];
    inputFormat = "SCBT";
    layer = inputLayer(inputSize,inputFormat)
    layer = 
      InputLayer with properties:
    
               Name: ''
          InputSize: [64 3 NaN NaN]
        InputFormat: 'SCBT'
    
    

    Include the input layer in a network.

    layers = [
        inputLayer([64 3 NaN NaN],"SCBT")
        convolution1dLayer(5,32)
        batchNormalizationLayer
        reluLayer
        globalAveragePooling1dLayer
        flattenLayer
        lstmLayer(100,OutputMode="last")
        fullyConnectedLayer(10)
        softmaxLayer];

    Algorithms

    expand all

    Extended Capabilities

    expand all

    Version History

    Introduced in R2023b

    expand all