LSTM input size mismatch

Hi,
I am meeting a trouble when I want to build a network with CNN and LSTM. Basically, I learn and follow from this link: https://uk.mathworks.com/help/deeplearning/ug/classify-videos-using-deep-learning.html. my dataset has 2000 samples (each sample contains 40 points), when I test my custom network, there exists an error on the LSTM layer:
Layer 'lstm': Input size mismatch. Size of input to this layer is different from the expected input size.
Inputs to this layer:
from layer 'flatten' (output size 100)
Attached please find the analysis of my network architecture

回答(1 个)

With the following code I was able to construct layerGraph with no errors. Make sure you define the lstmLayer with right input arguments.
inputSize = [1 40 1];
filterSize = [1 3];
numFilters = 5;
numHiddenUnits = 25;
numClasses = 2;
layers = [ ...
sequenceInputLayer(inputSize,'Name','input')
sequenceFoldingLayer('Name','fold')
convolution2dLayer(filterSize,numFilters,'Name','conv','stride',[1 1],'padding','same')
maxPooling2dLayer([1 2],'padding',[0 0 0 0],'Name','maxpool','Stride',[1 2])
sequenceUnfoldingLayer('Name','unfold')
flattenLayer('Name','flatten')
lstmLayer(numHiddenUnits,'OutputMode','last','Name','lstm')
fullyConnectedLayer(numClasses, 'Name','fc')
softmaxLayer('Name','softmax')
classificationLayer('Name','classification')];
lgraph = layerGraph(layers);
lgraph = connectLayers(lgraph,'fold/miniBatchSize','unfold/miniBatchSize');
analyzeNetwork(lgraph)

类别

帮助中心File Exchange 中查找有关 Deep Learning Toolbox 的更多信息

产品

版本

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by