Error in training Neural Network: Invalid training data. For a recurrent layer with output mode 'last', responses must be a categorical column vector.

조회 수: 2 (최근 30일)
I am trying to train an LSTM on a time-series dataset.
The training data is of dimensions (time x samples) and in preprocessing I put it into a cell (samples x 1) with each array in the cell having dimension (1 x time)
The target data is of dimensions (1 x samples) and specifies the category the sample belongs to. In preprocessing I create a cell (samples x 1) of categorical labels with dimension (1 x categories). The labels are arrays with one-hot encoding to indicate the category.
I'm getting the error: "Invalid training data. For a recurrent layer with output mode 'last', responses must be a categorical column vector."
I'm not sure what is causing this error, any help would be greatly appreciated! Thank you!
Code:
%training
train_on = full(getfield(train_data,'spikes'));
targets = mod(getfield(train_data,'target_direction'), 360);
tm = getfield(train_data,'target_motion');
directions = unique(targets);
directions_index = 1:length(directions);
%% preprocess data
true = zeros(length(directions), length(targets));
for i = 1:length(targets)
ind = find(directions == targets(i));
true(ind, i) = 1;
end
train_on = train_on(tm(1): end-1, :);
train_on = permute(train_on, [2, 1]);
true = permute(true, [2, 1]);
input = cell(size(train_on, 1), 1);
labels = cell(size(train_on, 1), 1);
for i = 1:size(train_on,1)
input{i, 1} = [train_on(i, :)];
labels{i, 1} = categorical(true(i,:));
end
%% make LSTM
numFeatures = 1; numHiddenUnits = 100; numClasses = length(directions);
layers = [ ...
sequenceInputLayer(numFeatures)
lstmLayer(numHiddenUnits,'OutputMode','last')
fullyConnectedLayer(numClasses)
softmaxLayer
classificationLayer];
maxEpochs = 10; miniBatchSize = 20;
options = trainingOptions('adam', ...
'ExecutionEnvironment','cpu', ...
'MaxEpochs',maxEpochs, ...
'MiniBatchSize',miniBatchSize, ...
'GradientThreshold',1, ...
'Verbose',false, ...
'Plots','training-progress');
net = trainNetwork(input,labels,layers,options);
  댓글 수: 1
shan liu
shan liu 2022년 5월 23일
I got a same error as you and resolved it.
at your code there:
labels = cell(size(train_on, 1), 1);
for i = 1:size(train_on,1)
input{i, 1} = [train_on(i, :)];
labels{i, 1} = categorical(true(i,:));
end
Check your labels. It is a cell, not a categorical. Make it to size(train_on,1)*1 categorical.

댓글을 달려면 로그인하십시오.

답변 (1개)

Harsha Priya Daggubati
Harsha Priya Daggubati 2020년 5월 11일
Hi,
As it is mentioned in the error message, responses (i.e. training data labels) should be of categorical type. In your case can you check the type of labels, just to ensure it is of categorical type with size samplesx1.
Also, are you sure that each sample has information about only one feature?

카테고리

Help CenterFile Exchange에서 Deep Learning Toolbox에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by