how to create Time distributed layer

4 views (last 30 days)
angeline yap
angeline yap on 12 Feb 2022
Answered: Purvaja on 19 Feb 2025
Hi, i try to create a time distributed layer for my lstm encoder decoder, which i make use of timedelaynet. But whenever i make use this, i get the error because it is the network instead of layer. May i know if there is anywhere to create time distributed layer. Thank you
layers=[...
sequenceInputLayer(numInFeatures)
lstmLayer(numEnUnits,"OutputMode","last")
repeatVectorLayer(30)
lstmLayer(numDeUnits)
timedelaynet(30,numDenseUnits)
timedelaynet(30,numOutFeatures)
regressionLayer];
-----------------------------------------------------------------------------------------
%% this is the error that is gotten
Cannot convert from 'network' to 'nnet.cnn.layer.SequenceInputLayer'.

Answers (1)

Purvaja
Purvaja on 19 Feb 2025
I understand that you want to create a “Time distributed Layer” in your implementation of network. As a matter of fact, the timedelaynet” function builds a new neural network and hence cannot be used as a layer in “Layer” function in MATLAB.
The following MATLAB Community question touches upon implementation of “Time Distributed” layer in MATLAB:
In answer it was mentioned that we can use “sequenceFoldingLayer” and “sequenceUnoldingLayerto implement “Time Distributed” layers.
By using the same we can incorporate “Time Distributed” layers by replacingtimedelaynet(30,numDenseUnits)” with this:
sequenceFoldingLayer()
fullyConnectedLayer(numDenseUnits)
sequenceUnfoldingLayer()
But if you want to incorporate user-defined time delay, try making a custom timedelay” layer function for such architecture and use it in layers.
Or for more clarification or adjusting it according to your input and output requirements, the following documentation links would be helpful:
  1. For "sequenceFoldingLayer" function: https://www.mathworks.com/help/deeplearning/ref/nnet.cnn.layer.sequencefoldinglayer.html
  2. For "sequenceUnfoldingLayer" function: https://www.mathworks.com/help/deeplearning/ref/nnet.cnn.layer.sequenceunfoldinglayer.html
You can also try this command in your MATLAB command window for specific release documentation:
  • For "sequenceUnoldingLayer" function:
web(fullfile(docroot,'deeplearning/ref/nnet.cnn.layer.sequenceunfoldinglayer.html'))
  • For "sequenceFoldingLayer" function:
web(fullfile(docroot,'deeplearning/ref/nnet.cnn.layer.sequencefoldinglayer.html'))
Hope this helps you!

Categories

Find more on Statistics and Machine Learning Toolbox in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!