Preparing input data for classification using LSTM

16 Ansichten (letzte 30 Tage)
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 Kommentare
Cris LaPierre
Cris LaPierre am 31 Mai 2024
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 am 1 Jun. 2024
Bearbeitet: Ernest Modise - Kgamane am 1 Jun. 2024
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);

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

Cris LaPierre
Cris LaPierre am 31 Mai 2024
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 Kommentare
Fan
Fan am 14 Aug. 2024
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 am 18 Aug. 2024
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."

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Image Data Workflows finden Sie in Help Center und File Exchange

Tags

Produkte


Version

R2024a

Community Treasure Hunt

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

Start Hunting!

Translated by