Main Content

sequenceFoldingLayer

(Not recommended) Sequence folding layer

SequenceFoldingLayer objects are not recommended. Most neural networks specified as a dlnetwork object do not require sequence folding and unfolding layers. In most cases, deep learning layers have the same behavior when there is no folding or unfolding layer. Otherwise, instead of using a SequenceFoldingLayer to manipulate the dimensions of data for downstream layers, define a custom layer functionLayer layer object that operates on the data directly. For more information, see Version History.

Description

A sequence folding layer converts a batch of image sequences to a batch of images. Use a sequence folding layer to perform convolution operations on time steps of image sequences independently.

To use a sequence folding layer, you must connect the miniBatchSize output to the miniBatchSize input of the corresponding sequence unfolding layer.

Creation

Description

layer = sequenceFoldingLayer creates a sequence folding layer.

example

layer = sequenceFoldingLayer('Name',Name) creates a sequence folding layer and sets the optional Name property using a name-value pair. For example, sequenceFoldingLayer('Name','fold1') creates a sequence folding layer with the name 'fold1'. Enclose the property name in single quotes.

Properties

expand all

Layer name, specified as a character vector or a string scalar. For Layer array input, the trainNetwork function automatically assigns names to layers with the name "".

The SequenceFoldingLayer object stores this property as a character vector.

Data Types: char | string

Number of inputs to the layer, returned as 1. This layer accepts a single input only.

Data Types: double

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

Data Types: cell

Number of outputs of the layer.

The layer has two outputs:

  • 'out' – Output feature map corresponding to reshaped input.

  • 'miniBatchSize' – Size of the mini-batch passed into the layer. This output must be connected to the 'miniBatchSize' input of the corresponding sequence unfolding layer.

Data Types: double

Output names of the layer.

The layer has two outputs:

  • 'out' – Output feature map corresponding to reshaped input.

  • 'miniBatchSize' – Size of the mini-batch passed into the layer. This output must be connected to the 'miniBatchSize' input of the corresponding sequence unfolding layer.

Data Types: cell

Examples

collapse all

Create a sequence folding layer.

Create a sequence folding layer with name the 'fold1'.

layer = sequenceFoldingLayer('Name','fold1')
layer = 
  SequenceFoldingLayer with properties:

           Name: 'fold1'
     NumOutputs: 2
    OutputNames: {'out'  'miniBatchSize'}

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 R2019a

collapse all

R2024a: Not recommended

Starting in R2024a, DAGNetwork and SeriesNetwork objects are not recommended, use dlnetwork objects instead. This recommendation means that the SequenceFoldingLayer objects are also not recommended. Most neural networks specified as a dlnetwork object do not require sequence folding and unfolding layers. In most cases, deep learning layers have the same behavior when there is no folding or unfolding layer. Otherwise, instead of using a SequenceFoldingLayer to manipulate the dimensions of data for downstream layers, define a custom layer functionLayer layer object that operates on the data directly. For more information about custom layers, see Define Custom Deep Learning Layers.

There are no plans to remove support for DAGNetwork, SeriesNetwork, and SequenceFoldingLayer objects. However, dlnetwork objects have these advantages and are recommended instead:

  • dlnetwork objects are a unified data type that supports network building, prediction, built-in training, visualization, compression, verification, and custom training loops.

  • dlnetwork objects support a wider range of network architectures that you can create or import from external platforms.

  • The trainnet function supports dlnetwork objects, which enables you to easily specify loss functions. You can select from built-in loss functions or specify a custom loss function.

  • Training and prediction with dlnetwork objects is typically faster than LayerGraph and trainNetwork workflows.

To convert a trained DAGNetwork or SeriesNetwork object to a dlnetwork object, use the dag2dlnetwork function.