Preparing input data for classification using LSTM

조회 수: 16 (최근 30일)
Ernest Modise - Kgamane
Ernest Modise - Kgamane 2024년 5월 31일
댓글: Cris LaPierre 2024년 8월 18일
I am interested in classifying graphs (senquence) data to category labels. I saw that I could use LSTM however, I would like know how the primary sequence data is store for inputing into the LSTM, I also want to know how to attach know labels to each graph for purpose of training.
In this there is a variable / struture called waveform, how was it constructed?
Please assist
  댓글 수: 2
Cris LaPierre
Cris LaPierre 2024년 5월 31일
The format is described at the top of the linked example.
You can also find it described at the top of this example: Sequence-to-One Regression Using Deep Learning
Ernest Modise - Kgamane
Ernest Modise - Kgamane 2024년 6월 1일
편집: Ernest Modise - Kgamane 2024년 6월 1일
Hi Cris
I am looking at your response, I am trying to understand it, please see my code and input file and explain where I went wrong
label = strings(997,1);
label(1:200) = 'graphtype1';
label(201:399) = 'graphtype2';
label(400:598) = 'graphtype3';
label(599:798) = 'graphtype4';
label(799:997) = 'graphtype5';
className = categorical(label);
className2 = categories(className);
Datain = xlsread('C:\Users\ernes\OneDrive\Documents\MATLAB\LSTMdataIn.xlsx');
% Above Datain has 897 graphs each with 100 samples
% E.g for graphs Datain(1:200,:) - graphtype 1
% graphs Datain(201:399) - graphtype 2
%So my objective is to train my LSTM using the graphs to labels
numObservations = 997;
[idxTrain,idxTest] = trainingPartitions(numObservations,[0.9 0.1]);
XTrain = Datain(idxTrain,:);% in Xtrain - there are 897 graphs each with 100 values, so
% Xtrain is 897 x 100,
TTrain = className(idxTrain,:);
numHiddenUnits = 120;
numClasses = 5;
layers = [
sequenceInputLayer(100) % I am not sure about this input, because my data comes in 1 by 100 arrys of a seq
%,with 1 - 100 ms timestamps
bilstmLayer(numHiddenUnits,OutputMode="last")
fullyConnectedLayer(numClasses)
softmaxLayer]
options = trainingOptions("adam", ...
MaxEpochs=200, ...
InitialLearnRate=0.002,...
GradientThreshold=1, ...
Shuffle="never", ...
Plots="training-progress", ...
Metrics="accuracy", ...
Verbose=false);
net = trainnet(XTrain,TTrain,layers,"crossentropy",options);

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

채택된 답변

Cris LaPierre
Cris LaPierre 2024년 5월 31일
It is a mat file. This is a way of saving variables in MATLAB to a file (see save). It loads 3 variables to the Workspace
  • data - a 1000x1 cell array. Each cell contains an nx3 array of signal data
  • freq - 1000x1 array. This is the frequency of the corresponding observation
  • labels - a 1000x1 categorical array containg the waveform label for the corresponding observation
You don't need to create a mat file. You just need to organze your data into a numObservations-by-1 cell array of sequences as the input data.
Each sequence (cell of data) is a numTimeSteps-by-numChannels numeric array, where numTimeSteps is the number of time steps of the sequence and numChannels is the number of channels of the sequence.
The label data is a numObservations-by-1 categorical vector.
You do not need to use freq for the example you are using.
  댓글 수: 5
Fan
Fan 2024년 8월 14일
Hi Cris,
Sorry for jumpping into this answered question, but i do have a similar question thats been bugging me for a while. I think the Waveform example uses a timestep of 1 so that each row in a observation ( or in a cell), is 1 timepoint.
However, if I want to use a timestep of 5 sliding from time0 - timeN using a slideing window of 1, so basically creating another dimenssion within each observation, how should I organize my input data and label vector? Do i simply make each cell a 3d array, like timestep by channel by number of sliding window?
Also, does it matter if I transpose the input from time by channel to channel by time?
Cris LaPierre
Cris LaPierre 2024년 8월 18일
There is no time data in the linked eample. Instead, index is used (1:numel)..You might be able to back out the actual time step size using the freq data if necessary, but it will require some exta work, as the number of periods captured varies across observations.
If you are following the LSTM example, then yes, order matters. You can read more about the input syntax for trainnet here:
As for your question about data format, that can be specified in the InputDataFormats training option. From the linked doc page:
  • "The size and shape of the numeric arrays or dlarray objects that represent sequences depend on the type of sequence data and must be consistent with the InputDataFormats training option."

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

추가 답변 (0개)

카테고리

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

태그

제품


릴리스

R2024a

Community Treasure Hunt

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

Start Hunting!

Translated by