Error using trainNetwork (line 184) Invalid training data. Predictors must be in a N-by-1 cell array of sequences, where N is the number of sequences.

1 view (last 30 days)
I tried to make a sequential classifier using using a LSTM but I got an error saying:
"Error using trainNetwork (line 184) Invalid training data. Predictors must be in a N-by-1 cell array of sequences, where N is the number of sequences. All sequences must have the same feature dimension and at least one time step."
below I included the code and images.
load Data1
load Data2
load Data1_ds1
load Data2_ds1
XTrain = {Data1;Data2;Data1_ds1;Data2_ds1}
XValidation = {Data1_ds1;Data2_ds1}
TTrain = [1;1;2;2]
TTrain = categorical(TTrain)
TValidation = [1;2]
TValidation = categorical(TValidation)
XTrain(1:2)
classes = categories(TTrain)
numClasses = numel(classes)
%numClasses = 23
filterSize = 3;
numFilters = 32;
numFeatures = 2;
layers = [ ...
sequenceInputLayer(numFeatures)
bilstmLayer(100,'OutputMode','sequence')
fullyConnectedLayer(2)
softmaxLayer
classificationLayer
]
miniBatchSize = 27;
% options = trainingOptions("adam", ...
% MiniBatchSize=miniBatchSize, ...
% MaxEpochs=10, ...
% SequencePaddingDirection="left", ...
% ValidationData={XValidation,TValidation}, ...
% Plots="training-progress", ...
% Verbose=0);
options = trainingOptions('adam', ...
'MaxEpochs',10, ...
'MiniBatchSize', miniBatchSize, ...
'InitialLearnRate', 0.01, ...
'SequenceLength', 100, ...
'GradientThreshold', 1, ...
'ExecutionEnvironment',"auto",...
'plots','training-progress', ...
'Verbose',false);
net = trainNetwork(XTrain,TTrain,layers,options);

Answers (1)

yanqi liu
yanqi liu on 8 Jan 2022
yes,sir,may be modify
XTrain = {Data1;Data2;Data1_ds1;Data2_ds1}
XValidation = {Data1_ds1;Data2_ds1}
to
XTrain = [Data1;Data2;Data1_ds1;Data2_ds1]
XValidation = [Data1_ds1;Data2_ds1]

Categories

Find more on Image Data Workflows 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!