trainNetwork function features dimensions problem
I’m working on the implementation of a LSTM classification model.
As input I have different time series, as output some categorical values (labels).
This is my code:
close all
clearvars -except ts data labels
clc
for ii = 1 : numel(ts)
timeVec = datenum(ts(ii).Timetable.Time);
data{ii} = [timeVec, data{ii}];
end
numChannels = size(data{1}, 2);
numHiddenUnits = 120;
numClasses = 2;
layers = [
sequenceInputLayer(numChannels)
lstmLayer(numHiddenUnits,’OutputMode’,’last’)
fullyConnectedLayer(numClasses)
softmaxLayer
classificationLayer];
maxEpochs = 200;
miniBatchSize = 27;
options = trainingOptions(‘adam’, …
‘ExecutionEnvironment’,’cpu’, …
‘MaxEpochs’, maxEpochs, …
‘MiniBatchSize’, miniBatchSize, …
‘GradientThreshold’, 1, …
‘Verbose’, false, …
‘Plots’, ‘training-progress’);
idxTrain = [1 2 3 9 10 11];
idxTest = [4 7 8];
Xtrain = cell(numel(idxTrain), 1);
Ytrain = categorical(labels(idxTrain))’;
for ii = 1 : numel(idxTrain)
Xtrain{ii} = data{idxTrain(ii)};
Ytrain(ii) = categorical(labels(idxTrain(ii)));
end
Xtest = cell(numel(idxTest), 1);
Ytest = categorical(labels(idxTest))’;
for ii = 1 : numel(idxTest)
Xtest{ii} = data{idxTest(ii)};
Ytest(ii) = categorical(labels(idxTest(ii)));
end
net = trainNetwork(Xtrain’, Ytrain, layers, options);
Running, I receive this error:
Error using trainNetwork
Invalid training data. Predictors must be 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.
Error in main (line 244)
net = trainNetwork(Xtrain’, Ytrain, layers, options);
I think it is related to the different sizes of the matrices inside each of the Xtrain cells.
Here a screenshot with the dimensions of the different cells of Xtrain.
Are there any way to train the model using inputs with different dimensions?I’m working on the implementation of a LSTM classification model.
As input I have different time series, as output some categorical values (labels).
This is my code:
close all
clearvars -except ts data labels
clc
for ii = 1 : numel(ts)
timeVec = datenum(ts(ii).Timetable.Time);
data{ii} = [timeVec, data{ii}];
end
numChannels = size(data{1}, 2);
numHiddenUnits = 120;
numClasses = 2;
layers = [
sequenceInputLayer(numChannels)
lstmLayer(numHiddenUnits,’OutputMode’,’last’)
fullyConnectedLayer(numClasses)
softmaxLayer
classificationLayer];
maxEpochs = 200;
miniBatchSize = 27;
options = trainingOptions(‘adam’, …
‘ExecutionEnvironment’,’cpu’, …
‘MaxEpochs’, maxEpochs, …
‘MiniBatchSize’, miniBatchSize, …
‘GradientThreshold’, 1, …
‘Verbose’, false, …
‘Plots’, ‘training-progress’);
idxTrain = [1 2 3 9 10 11];
idxTest = [4 7 8];
Xtrain = cell(numel(idxTrain), 1);
Ytrain = categorical(labels(idxTrain))’;
for ii = 1 : numel(idxTrain)
Xtrain{ii} = data{idxTrain(ii)};
Ytrain(ii) = categorical(labels(idxTrain(ii)));
end
Xtest = cell(numel(idxTest), 1);
Ytest = categorical(labels(idxTest))’;
for ii = 1 : numel(idxTest)
Xtest{ii} = data{idxTest(ii)};
Ytest(ii) = categorical(labels(idxTest(ii)));
end
net = trainNetwork(Xtrain’, Ytrain, layers, options);
Running, I receive this error:
Error using trainNetwork
Invalid training data. Predictors must be 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.
Error in main (line 244)
net = trainNetwork(Xtrain’, Ytrain, layers, options);
I think it is related to the different sizes of the matrices inside each of the Xtrain cells.
Here a screenshot with the dimensions of the different cells of Xtrain.
Are there any way to train the model using inputs with different dimensions? I’m working on the implementation of a LSTM classification model.
As input I have different time series, as output some categorical values (labels).
This is my code:
close all
clearvars -except ts data labels
clc
for ii = 1 : numel(ts)
timeVec = datenum(ts(ii).Timetable.Time);
data{ii} = [timeVec, data{ii}];
end
numChannels = size(data{1}, 2);
numHiddenUnits = 120;
numClasses = 2;
layers = [
sequenceInputLayer(numChannels)
lstmLayer(numHiddenUnits,’OutputMode’,’last’)
fullyConnectedLayer(numClasses)
softmaxLayer
classificationLayer];
maxEpochs = 200;
miniBatchSize = 27;
options = trainingOptions(‘adam’, …
‘ExecutionEnvironment’,’cpu’, …
‘MaxEpochs’, maxEpochs, …
‘MiniBatchSize’, miniBatchSize, …
‘GradientThreshold’, 1, …
‘Verbose’, false, …
‘Plots’, ‘training-progress’);
idxTrain = [1 2 3 9 10 11];
idxTest = [4 7 8];
Xtrain = cell(numel(idxTrain), 1);
Ytrain = categorical(labels(idxTrain))’;
for ii = 1 : numel(idxTrain)
Xtrain{ii} = data{idxTrain(ii)};
Ytrain(ii) = categorical(labels(idxTrain(ii)));
end
Xtest = cell(numel(idxTest), 1);
Ytest = categorical(labels(idxTest))’;
for ii = 1 : numel(idxTest)
Xtest{ii} = data{idxTest(ii)};
Ytest(ii) = categorical(labels(idxTest(ii)));
end
net = trainNetwork(Xtrain’, Ytrain, layers, options);
Running, I receive this error:
Error using trainNetwork
Invalid training data. Predictors must be 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.
Error in main (line 244)
net = trainNetwork(Xtrain’, Ytrain, layers, options);
I think it is related to the different sizes of the matrices inside each of the Xtrain cells.
Here a screenshot with the dimensions of the different cells of Xtrain.
Are there any way to train the model using inputs with different dimensions? lstm, machine learning, dimensions, input MATLAB Answers — New Questions