Why is there this issue when I follow Waveform Segmentation using Deep Learning issues with Documentation?

22 vues (au cours des 30 derniers jours)
I am trying to detect whether a wavform is an arc fault or nuissance fault.
For this documentation, https://www.mathworks.com/help/signal/ug/waveform-segmentation-using-deep-learning.html , in the download and prepare the data section, the documentation talks about a resizeData function, and I am looking for the same function because my code is erroring and I believe that is a reason why. Can someone direct to where the resizeData function is?
In the documentation, it talks about ECG signals, the attached signals are the signals that I am trying to train, and here is the code I have written thus far.
I PRIMARILY GET THE ERROR WHERE IT SAYS rawNet, AND I DON'T KNOW WHY
% Loading the data
datasetFolder = fullfile("Signal Training Folder")
sds = signalDatastore(datasetFolder, 'SignalVariableNames', ["faultSignalCondition", "signalLabels"])
data = preview(sds)
% Separate into Training Data
head(data{2})
M = signalMask(data{2});
plotsigroi(M, data{1}(1:1000))
rng default
[trainIdx,~,testIdx] = dividerand(numel(sds.Files), 0.7, 0, 0.3);
trainDs = subset(sds, trainIdx);
testDs = subset(sds, testIdx);
type getmask.m
trainDs = transform(trainDs, @getmask);
testDs = transform(testDs, @getmask);
transformedData = preview(trainDs)
plot(transformedData{2}(1:1000))
trainDs = transform(trainDs,@resizeData);
testDs = transform(testDs,@resizeData);
preview(trainDs)
tallTrainSet = tall(trainDs);
tallTestSet = tall(testDs);
trainData = gather(tallTrainSet);
trainData(1,:)
testData = gather(tallTestSet);
Raw Signals into the LSTM Network
% actionFlag = "Train networks"
% if actionFlag == "Download networks"
% load("trainedNetworks.mat")
% end
load LSTM_layers_2.mat
% Training Options
options = trainingOptions('adam', ...
'MaxEpochs',10, ...
'MiniBatchSize',50, ...
'InitialLearnRate',0.01, ...
'LearnRateDropPeriod',3, ...
'LearnRateSchedule','piecewise', ...
'GradientThreshold',1, ...
'Plots','training-progress',...
'shuffle','every-epoch',...
'Verbose',0,...
'DispatchInBackground',true);
% Train LSTM Network
trainDataInput = trainData(:, 1)
% trainDataInput = trainDataInput{:, 1}
% trainDataInput_Curr = trainDataInput(:, 1);
% trainDataInput_RSSI = trainDataInput(:, 2);
trainDataOutput = trainData(:, 2);
trainDataOutput = trainDataOutput{1, 1}
% rawNet = trainNetwork(, trainDataOutput, layers_2, options);
Get Mask Function
function outputCell = getmask(inputCell)
%GETMASK Convert region labels to a mask of labels of size equal to the
%size of the input ECG signal.
%
% inputCell is a two-element cell array containing an ECG signal vector
% and a table of region labels.
%
% outputCell is a two-element cell array containing the ECG signal vector
% and a categorical label vector mask of the same length as the signal.
sig = inputCell{1};
roiTable = inputCell{2};
L = length(sig);
M = signalMask(roiTable);
% Get categorical mask and give priority to QRS regions when there is overlap
mask = catmask(M,L,'OverlapAction','prioritizeByList','PriorityList',[1 2]); %I CHANGED THIS, COULD THIS BE THE ISSUE
% Set missing values to "n/a"
mask(ismissing(mask)) = "n/a";
outputCell = {sig,mask};
end
And these are my layers, I couldn't upload any attachments, but these layers are the layers that I used
layers = [ ...
sequenceInputLayer(28271) %in a video about this documentation, they used 1, but I did not, is this the issue?
lstmLayer(138,'OutputMode','sequence')
fullyConnectedLayer(4)
softmaxLayer
classificationLayer];
Is there anyone that can help with the resize or general issue? I don't mind discussing this issue in more detail.

Réponses (1)

YANHUI LI
YANHUI LI le 28 Mar 2023
function outputCell = resizeData(inputCell)
%RESIZEDATA Break input ECG signal and label mask into segments of length
%5000.
%
% inputCell is a two-element cell array containing an ECG signal and a
% label mask.
%
% outputCell is a two-column cell array containing as many 5000-long
% signal segments and label masks that were possible to generate from the
% input data.
% Copyright 2019 The MathWorks, Inc.
targetLength = 5000;
sig = inputCell{1};
mask = inputCell{2};
% Get number of chunks
numChunks = floor(size(sig,1)/targetLength);
% Truncate signal and mask to integer number of chunks
sig = sig(1:numChunks*targetLength);
mask = mask(1:numChunks*targetLength);
% Create a cell array containing signal chunks
sigOut = reshape(sig,targetLength,numChunks)';
sigOut = num2cell(sigOut,2);
% Create a cell array containing mask chunks
lblOut = reshape(mask,targetLength,numChunks)';
lblOut = num2cell(lblOut,2);
% Output a two-column cell array with all chunks
outputCell = [sigOut, lblOut];
end

Community Treasure Hunt

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

Start Hunting!

Translated by