Error in using sequenceFoldingLayer
显示 更早的评论
I am trying to input a sequence of array into a convolution + LSTM neural network. The input data is 128x1 in 30744x1 cells. The neural network architecture is as followed:
layers = [ ...
sequenceInputLayer([128 1 1],'Name','input') %Sequence input with 1 dimension
sequenceFoldingLayer('Name','fold')
convolution2dLayer([3 1],16,'Name','conv')
batchNormalizationLayer('Name','bn')
reluLayer('Name','relu')
maxPooling2dLayer([2 1],'Stride',1,'Name','maxpool1')
convolution2dLayer([3 1],32,'Name','conv2')
batchNormalizationLayer('Name','bn1')
reluLayer('Name','relu1')
maxPooling2dLayer([2 1],'Stride',1, 'Name','maxpool2')
sequenceUnfoldingLayer('Name','unfold')
flattenLayer('Name','flatten')
bilstmLayer(128,'OutputMode','last','Name','bilstm') %Number of layers
fullyConnectedLayer(256, 'Name','fc')
dropoutLayer(0.5, 'Name','do')
fullyConnectedLayer(128, 'Name','fc2')
dropoutLayer(0.5, 'Name','do2')
fullyConnectedLayer(4, 'Name','fc3') %()the number of the input/output
dropoutLayer(0.5, 'Name','do3')
softmaxLayer('Name','softmax')
classificationLayer('Name','classification') %Classify the data into corresponding group
]
lgraph = layerGraph(layers);
lgraph = connectLayers(lgraph,'fold/miniBatchSize','unfold/miniBatchSize');
The error message poped up stated this is an invalid network
Caused by:
Layer 'fold': Unconnected output. Each layer output must be connected to the input of another layer.
Detected unconnected outputs:
output 'miniBatchSize'
Layer 'unfold': Unconnected input. Each layer input must be connected to the output of another layer.
Detected unconnected inputs:
input 'miniBatchSize'
I read through the documentation about sequenceFoldingLayer. The example inside only mention I should connect the layers with these
lgraph = layerGraph(layers);
lgraph = connectLayers(lgraph,'fold/miniBatchSize','unfold/miniBatchSize');
1 个评论
Anshika Chaurasia
2021-9-17
Hi,
I ran your code on R2021a and it's not giving any error.
回答(1 个)
Boban Sazdic-Jotic
2022-5-31
Helo,
I had the same problem, however I managed to solve this in the following way:
- this is the network code :
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')];
lgraph = layerGraph(layers);
lgraph = connectLayers(lgraph,'fold/miniBatchSize','unfold/miniBatchSize');
- this is the code for training:
netTransfer = trainNetwork(augimdsTrain,lgraph,options);
All the best
Boban
类别
在 帮助中心 和 File Exchange 中查找有关 Deep Learning Toolbox 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!