What is an appropriate sequence input for the trainNetwork command

3 visualizaciones (últimos 30 días)
Hello
I am trying to fit a LSTM network for sequence-to-label classification using the example for sequence classification on this help-page i.e with the trainNetwork command :
My problem is to decide how to structure my input data. I have 500 training samples, each with 30000 time-steps. My first though was to divide the data into a 500x1 cell, with each cell being of dimention 30000x1. This however does not seem to work and I am un able to run trainNetwork without errors*.
When instead changing the cells to being of dimention 1x30000 I get an other error message**
Any help would be much appriciated
* Error using trainNetwork (line 165)
Invalid training data. If the network outputs sequences, then the responses must be a cell array of categorical
sequences, or a categorical sequence.*
**The training sequences are of feature dimension 1 but the input layer expects sequences of feature dimension
30000.**

Respuestas (2)

Srivardhan Gadila
Srivardhan Gadila el 7 de Abr. de 2020
The following code might help you:
layers = [sequenceInputLayer(3000) fullyConnectedLayer(10) fullyConnectedLayer(5) softmaxLayer classificationLayer];
% analyzeNetwork(layers)
%%
trainData = randn([3000 500]);
trainLabels = categorical(randi([1 5], 1,500));
size(trainData)
%%
options = trainingOptions('adam', ...
'InitialLearnRate',0.005, ...
'LearnRateSchedule','piecewise',...
'MaxEpochs',300, ...
'MiniBatchSize',1024, ...
'Verbose',1, ...
'Plots','training-progress');
net = trainNetwork(trainData,trainLabels,layers,options);
Based on the above code, reshape your training data and label data accordingly.
  1 comentario
Lihan Tang
Lihan Tang el 18 de Jun. de 2020
Hello~I have the similar problem.
I designed a network (using deepNetworkDesigner) that combines the CNN and LSTM to classify the image sequences, which is similar to the networks in the following links:
The size of each image is 28x28x1 and there are 10~20 images in a sequence (a trial). I have about 100 image sequences like this. I have searhced matlab documentations and find no such examples for the input structure. So how should i form the "trainData" for the network? Thank you very much!

Iniciar sesión para comentar.


Anouar Yatribi
Anouar Yatribi el 20 de Ag. de 2020
Editada: Anouar Yatribi el 20 de Ag. de 2020
Hi Axel,
Your training data should be a 500x1 cell, and each cell must be of dimension 1x30000 cell, where in this case, one feature is considered (1 row).
For the training labels, they should smilarly be organized in a 500x1 cell, where each cell is a categorical label. You can simply use the function categorical() for transforming your cell array of labels into a cell of categorical labels. In this case, I guess the problem will be solved. Note that this is for sequence to label classification, so you have to use the OutputMode 'last' in the LSTM layer. In the case of a sequence to sequence classification, your training labels will also be a 500x1 cell, but each cell is a categorical sequence of dimension 1x30000, and the LSTM layer should use the OutputMode 'sequence' rather than 'last'.
Good luck.

Community Treasure Hunt

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

Start Hunting!

Translated by