Classify error: requires 3 arguments

조회 수: 8 (최근 30일)
Mohamed Taha
Mohamed Taha 2023년 12월 28일
답변: Cris LaPierre 2024년 1월 2일
Hello All I have trained an LSTM model to classify EMG signals ( one dimensional time series) to produce a class prediction. Now when trying to test the trained LSTM on a test signal , classify produces error of requiring 3 arguments. No matter how I changed the shape of the test signal nothing helped. Also predict produced error results. Could you please help.
% Training code:
% LSTM-1D classification using raw EMG signal
%
% Data path
path = '/home/ubuntu/Desktop/EMG data analysis/EMG signal Matlab'
parameters
numHiddenUnits = 120;
numClasses = 8;
numChannels = 1
% Now prepare training/lables dataset for LSTM training
% Assuming sorted_emg_data is your sorted array with data and labels
% Extract the data for training
XTrain = cellfun(@(c) c.signal, sorted_emg_data(:, 1), 'UniformOutput', false);
% Extract the labels for training
TTrain = sorted_emg_data(:, 2);
% Convert the labels to a categorical array
TTrain = categorical(TTrain);
% Now XTrain contains all the EMG signals and TTrain contains the corresponding labels
% Now training the LSTM model
numHiddenUnits = 120;
numClasses = 8;
numChannels = 1
% Now define your layers with the correct number of output classes
layers = [ ...
sequenceInputLayer(numChannels)
bilstmLayer(numHiddenUnits, 'OutputMode', 'last')
fullyConnectedLayer(numClasses) % Make sure this matches the number of unique classes in TTrain
softmaxLayer
classificationLayer];
% Define your training options (make sure MiniBatchSize is appropriate for your dataset)
options = trainingOptions('adam', ...
'MaxEpochs', 50, ...
'MiniBatchSize', 3, ... % Adjust based on your hardware capabilities
'InitialLearnRate', 0.01, ...
'GradientThreshold', 1, ...
'Verbose', 0, ...
'Plots', 'training-progress');
% Train the network
net = trainNetwork(XTrain, TTrain, layers, options);
% Testing code
%
% Loading the network
net = load ("lstm_trained_model.mat")
% Loading data
test = load ('emg_signal_3.mat')
net.layers
length (test)
length (signal) % signal directly loaded
% Classification
pred = classify(net, test);
  댓글 수: 5
Mohamed Taha
Mohamed Taha 2023년 12월 29일
Hello
I am sharing the actual codes and error here and training code
The training data was (signal/labels, with signals in first column as cell array) signals are one dimension time series
Cris LaPierre
Cris LaPierre 2023년 12월 29일
Can you share the result of this command?
which classify

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

답변 (1개)

Cris LaPierre
Cris LaPierre 2024년 1월 2일
I cannot duplicate your error. I used this example to create a sample data set. I then trained that data using your code, and then tested it using the code in the pdfs. My conclusion is there is nothing wrong with your code. Without more details, I don't know what more we can do to help.
Here are the results I obtained when running the model on test data using the code from your pdfs.

카테고리

Help CenterFile Exchange에서 Measurements and Feature Extraction에 대해 자세히 알아보기

제품


릴리스

R2023b

Community Treasure Hunt

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

Start Hunting!

Translated by