This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English version of the page.

Note: This page has been translated by MathWorks. Click here to see
To view all translated materials including this page, select Country from the country navigator on the bottom of this page.

sequenceUnfoldingLayer

Sequence unfolding layer

Description

A sequence unfolding layer restores the sequence structure of the input data after sequence folding.

To use a sequence unfolding layer, you must connect the miniBatchSize output of the corresponding sequence folding layer to the miniBatchSize input of the sequence unfolding layer. For an example, see Create Network for Video Classification.

Creation

Syntax

layer = sequenceUnfoldingLayer
layer = sequenceUnfoldingLayer('Name',Name)

Description

layer = sequenceUnfoldingLayer creates a sequence unfolding layer.

example

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

Properties

expand all

Layer name, specified as a character vector or a string scalar. To include a layer in a layer graph, you must specify a nonempty unique layer name. If you train a series network with the layer and Name is set to '', then the software automatically assigns a name to the layer at training time.

Data Types: char | string

Number of inputs of the layer.

This layer has two inputs:

  • 'in' – Input feature map.

  • 'miniBatchSize' – Size of the mini-batch from the corresponding sequence folding layer. This output must be connected to the 'miniBatchSize' output of the corresponding sequence folding layer.

Data Types: double

Input names of the layer.

This layer has two inputs:

  • 'in' – Input feature map.

  • 'miniBatchSize' – Size of the mini-batch from the corresponding sequence folding layer. This output must be connected to the 'miniBatchSize' output of the corresponding sequence folding layer.

Data Types: cell

Number of outputs of the layer. This layer has a single output only.

Data Types: double

Output names of the layer. This layer has a single output only.

Data Types: cell

Examples

collapse all

Create a sequence unfolding layer with the name 'unfold1'.

layer = sequenceUnfoldingLayer('Name','unfold1')
layer = 
  SequenceUnfoldingLayer with properties:

          Name: 'unfold1'
     NumInputs: 2
    InputNames: {'in'  'miniBatchSize'}

Create a deep learning network for data containing sequences of images, such as video and medical image data.

  • To input sequences of images into a network, use a sequence input layer.

  • To apply convolutional operations independently to each time step, first convert the sequences of images to an array of images using a sequence folding layer.

  • To restore the sequence structure after performing these operations, convert this array of images back to image sequences using a sequence unfolding layer.

  • To convert images to feature vectors, use a flatten layer.

You can then input vector sequences into LSTM and BiLSTM layers.

Define Network Architecture

Create a classification LSTM network that classifies sequences of 28-by-28 grayscale images into 10 classes.

Define the following network architecture:

  • A sequence input layer with an input size of [28 28 1].

  • A convolution, batch normalization, and ReLU layer block with 20 5-by-5 filters.

  • An LSTM layer with 200 hidden units that outputs the last time step only.

  • A fully connected layer of size 10 (the number of classes) followed by a softmax layer and a classification layer.

To perform the convolutional operations on each time step independently, include a sequence folding layer before the convolutional layers. LSTM layers expect vector sequence input. To restore the sequence structure and reshape the output of the convolutional layers to sequences of feature vectors, insert a sequence unfolding layer and a flatten layer between the convolutional layers and the LSTM layer.

inputSize = [28 28 1];
filterSize = 5;
numFilters = 20;
numHiddenUnits = 200;
numClasses = 10;

layers = [ ...
    sequenceInputLayer(inputSize,'Name','input')
    
    sequenceFoldingLayer('Name','fold')
    
    convolution2dLayer(filterSize,numFilters,'Name','conv')
    batchNormalizationLayer('Name','bn')
    reluLayer('Name','relu')
    
    sequenceUnfoldingLayer('Name','unfold')
    flattenLayer('Name','flatten')
    
    lstmLayer(numHiddenUnits,'OutputMode','last','Name','lstm')
    
    fullyConnectedLayer(numClasses, 'Name','fc')
    softmaxLayer('Name','softmax')
    classificationLayer('Name','classification')];

Convert the layers to a layer graph and connect the miniBatchSize output of the sequence folding layer to the corresponding input of the sequence unfolding layer.

lgraph = layerGraph(layers);
lgraph = connectLayers(lgraph,'fold/miniBatchSize','unfold/miniBatchSize');

View the final network architecture using the plot function.

figure
plot(lgraph)

Introduced in R2019a