Expanding Deep Network Architecture for Signal Classification

4 次查看(过去 30 天)
I have implemented a code for classifying P, QRS, T, and NA segments from ECG signals. The current network architecture consists of a sequence input layer, an LSTM layer, and fully connected layers for classification. However, I would like to enhance the performance of the network by incorporating convolutional neural network (CNN) layers to capture more informative features from the ECG signals.
Here is the existing code that I have:
input_data = fsstTrainData(:, 1);
target_data = fsstTrainData(:, 2);
size_input = size(input_data); %cell 315*1
size_input_signals = size(input_data{1, 1}); %double 40*5000
size_target = size(target_data); %cell 315*1
size_target_signals = size(target_data{1, 1}); %categorical 1*5000
layers = [
sequenceInputLayer(size_input_signals(1))
lstmLayer(200, 'OutputMode', 'sequence')
fullyConnectedLayer(class_num)
softmaxLayer
classificationLayer];
trainNetwork(input_data, target_data, layers, options);
I would appreciate any assistance in modifying the network architecture to incorporate CNN layers that can extract more informative features from the signals. Your suggestions and guidance would be highly valuable in improving the classification accuracy.
Thank you for your help!

回答(2 个)

Aniketh
Aniketh 2023-7-9
编辑:Aniketh 2023-7-9
In order to answer your question how you can incorporate CNN layers to your architecture it is quite straight forward, here is one short example to give you an idea:
cnn_layers = [
imageInputLayer([size_input_signals(1), size_input_signals(2), 1])
convolution2dLayer([3, 3], 16, 'Padding', 'same')
reluLayer
maxPooling2dLayer(2, 'Stride', 2)
convolution2dLayer([3, 3], 32, 'Padding', 'same')
reluLayer
maxPooling2dLayer(2, 'Stride', 2)
];
lstm_layers = [
sequenceInputLayer(size_input_signals(1))
lstmLayer(200, 'OutputMode', 'sequence')
fullyConnectedLayer(class_num)
softmaxLayer
classificationLayer
];
layers = [
cnn_layers
sequenceFoldingLayer('Name', 'fold')
lstm_layers
];
As for increasing the accuracy/enhancing the performance, you should know these are really empirical methods, just adding more layers or introducing more complex architectures such as this would not necessarily produce better results and might even produce worse results.
Try and experiment on your own, changing the parameters and different architectural changes see what works best for your case, I would suggest reading up on how DL architectures are popularly used for processing ECG Signals, I believe MathWorks has a lot of resources on this as well.
Hope this helped!

Abolfazl Nejatian
Abolfazl Nejatian 2023-7-10
Thank you for taking the time to explain and provide a solution for incorporating CNN layers into the LSTM-based architecture for ECG signal classification. I appreciate your effort and guidance in this matter.
However, I encountered an error while running the code you shared.
here is the error
Error using trainNetwork
Invalid network.
Caused by:
Layer 'fold': Unconnected output. Each layer output must be
connected to the input of another layer.
Layer 9: An input layer must be first in the layer array.
Layer 9: The size of the input data does not match the size
expected by the layer.
It appears that there is an issue with the structure of the network, specifically with the unconnected output in the sequenceFoldingLayer. Additionally, the order of the layers seems to be incorrect, causing a mismatch in the expected input size.
Although the code did not run successfully, I want to express my gratitude for your willingness to help and for sharing your insights. and also i try to update the code by generating random input and target data to see the excactly what i work on
% ------ Generate random input and target data with the original format
% Set the size of the cell arrays
numRows = 315;
signalLen = 5000;
featuresNum = 40;
% Create the inputData cell array
inputData = cell(numRows, 1);
% Create the targetData cell array
targetData = cell(numRows, 1);
% Generate random numbers and assign them to each cell in inputData
for i = 1:numRows
% Generate a random matrix
randomMatrix = rand(featuresNum, signalLen);
% Assign the random matrix to the inputData cell
inputData{i, 1} = randomMatrix;
% Generate a random categorical variable from 'P', 'QRS', 'T', 'NA'
categories = ["P", "QRS", "T", "NA"];
var_P = repmat(categories(1), 1, signalLen);
var_QRS = repmat(categories(2), 1, signalLen);
var_T = repmat(categories(3), 1, signalLen);
var_NA = repmat(categories(4), 1, signalLen);
vars = [var_P,var_QRS,var_T,var_NA];
subsetIdx = randperm(numel(vars),signalLen);
randomCategory = categorical(vars(subsetIdx));
% Create categorical variable and assign it to the targetData cell
targetData{i, 1} = randomCategory;
end
% LSTM Network Architect
class_num = numel(categories);
layers = [ ...
sequenceInputLayer(featuresNum)
lstmLayer(200,'OutputMode','sequence')
fullyConnectedLayer(class_num)
softmaxLayer
classificationLayer];
% Train the Network
options = trainingOptions('adam', ...
'MaxEpochs',10, ...
'MiniBatchSize',40, ...
'InitialLearnRate',0.01, ...
'LearnRateDropPeriod',3, ...
'LearnRateSchedule','piecewise', ...
'GradientThreshold',1, ...
'ExecutionEnvironment','cpu',...
'Plots','training-progress',...
'shuffle','every-epoch',...
'Verbose',0,...
'DispatchInBackground',true);
trainNet = trainNetwork(inputData,targetData,layers,options);
  2 个评论
Aniketh
Aniketh 2023-7-10
Apologies for the confusion, as I mentioned it was just an example to get you started, the dimensions would not match in the template I gave, having a look at it, the dimensions should be 1/4th the original dimension passed to the CNN, but further in the code you would have to be mindful and check carefully for dimensions.
Abolfazl Nejatian
Abolfazl Nejatian 2023-7-11
Certainly, I acknowledge your statement. I would greatly appreciate it if you could kindly add an additional example that aptly fulfills the given problem data type.

请先登录,再进行评论。

类别

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