필터 지우기
필터 지우기

What is an appropriate sequence input for the trainNetwork command

조회 수: 4 (최근 30일)
Axel Wetterlundh
Axel Wetterlundh 2020년 4월 1일
댓글: Fernando Junior Cocina 2021년 6월 25일
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.**

답변 (2개)

Srivardhan Gadila
Srivardhan Gadila 2020년 4월 7일
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
Lihan Tang
Lihan Tang 2020년 6월 18일
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!

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


Anouar Yatribi
Anouar Yatribi 2020년 8월 20일
편집: Anouar Yatribi 2020년 8월 20일
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.

카테고리

Help CenterFile Exchange에서 Image Data Workflows에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by