Getting error in CNN LSTM code?

Consider 144 speech files.
Error using trainNetwork (line 165)
Invalid training data. X and Y must have the same number of observations.
Error in Untitled (line 50)
net = trainNetwork(f,labelsTrain1,lgraph,options);
code:
clc
clear all
close all
for i=1:60
A=rand(50,32)
f(:,:,1,i)=A
end
wLabels1 = repelem(categorical("class-1"),10,1);
wLabels2 = repelem(categorical("class-2"),10,1);
wLabels3 = repelem(categorical("class-3"),10,1);
wLabels4 = repelem(categorical("class-4"),10,1);
wLabels5 = repelem(categorical("class-5"),10,1);
wLabels6 = repelem(categorical("class-6"),10,1);
labelsTrain1=[wLabels1;wLabels2;wLabels3;wLabels4;wLabels5;wLabels6]
inputSize = [50 32 1];
filterSize = 5;
numFilters = 20;
numHiddenUnits = 200;
numClasses = 6;
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,'Name','lstm')
fullyConnectedLayer(numClasses, 'Name','fc')
softmaxLayer('Name','softmax')
classificationLayer('Name','classification')];
lgraph = layerGraph(layers);
lgraph = connectLayers(lgraph,'fold/miniBatchSize','unfold/miniBatchSize');
options = trainingOptions('sgdm', ...
'MaxEpochs',20,...
'InitialLearnRate',1e-4, ...
'Verbose',false, ...
'Plots','training-progress');
net = trainNetwork(f,labelsTrain1,lgraph,options);

Answers (0)

Categories

Find more on Deep Learning Toolbox in Help Center and File Exchange

Asked:

on 9 Jun 2021

Community Treasure Hunt

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

Start Hunting!