Error: Invalid network layer does not support sequence input

3 ビュー (過去 30 日間)
ZEMIN HUANG
ZEMIN HUANG 2021 年 1 月 26 日
コメント済み: ZEMIN HUANG 2021 年 1 月 31 日
hi, i am building a CNN training model. however, i got this error that do not know how to solve. i tried to insert a sequence folding layer then i got error again saying that "unconnected input and output". please help me with this
% Load training data and essential parameters
load('trainData.mat','XTrain','YTrain');
numSC = 64;
% Batch size
miniBatchSize = 4000;
% Iteration
maxEpochs = 10;
% Sturcture
inputSize = [6,64,1];
numHiddenUnits = 128;
numHiddenUnits2 = 64;
numHiddenUnits3 = numSC;
numClasses = 16;
% DNN Layers
layers = [ ...
sequenceInputLayer(inputSize,'Name','sequence')
convolution2dLayer(3,32,'Name','conv2')
reluLayer('Name','relu')
maxPooling2dLayer(2,'Name','maxpool')
flattenLayer('Name','flat')
lstmLayer(numHiddenUnits,'OutputMode','last','Name','lstm')
fullyConnectedLayer(numClasses,'Name','fc')
softmaxLayer('Name','sm')
classificationLayer('Name','class')];
% Training options
options = trainingOptions('adam',...
'InitialLearnRate',0.01,...
'ExecutionEnvironment','auto', ...
'GradientThreshold',1, ...
'LearnRateDropFactor',0.1,...
'MaxEpochs',maxEpochs, ...
'MiniBatchSize',miniBatchSize, ...
'Shuffle','every-epoch', ...
'Verbose',1,...
'Plots','training-progress');
% Train the neural network
tic;
net = trainNetwork(XTrain,YTrain,layers,options);
toc;
save('NN.mat','net');

採用された回答

Mahesh Taparia
Mahesh Taparia 2021 年 1 月 29 日
Hi
There is a requirement of sequenceFoldingLayer and sequenceUnfoldingLayer in the layer graph. For a sample layergraph, you can refer here. You can consider the below code for your case:
% DNN Layers
layers = [ ...
sequenceInputLayer(inputSize,'Name','sequence')
sequenceFoldingLayer('Name','fold')
convolution2dLayer(3,32,'Name','conv2')
reluLayer('Name','relu')
maxPooling2dLayer(2,'Name','maxpool')
sequenceUnfoldingLayer('Name','unfold')
flattenLayer('Name','flat')
lstmLayer(numHiddenUnits,'OutputMode','last','Name','lstm')
fullyConnectedLayer(numClasses,'Name','fc')
softmaxLayer('Name','sm')
classificationLayer('Name','class')];
lgraph = layerGraph(layers);
lgraph = connectLayers(lgraph,'fold/miniBatchSize','unfold/miniBatchSize');
analyzeNetwork(lgraph)
Hope it will help!
  1 件のコメント
ZEMIN HUANG
ZEMIN HUANG 2021 年 1 月 31 日
Hi!! it works for me, thank you!!!

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeParallel and Cloud についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by