Problem in Deep Learning training process
6 views (last 30 days)
Show older comments
I am using Deep Learning to identify bearing faults through transfer learning. I am using a CWRU database which contains vibration signals, and then obtains images starting from scalograms. Without going into many details I have 1364 images of faults at inner ring, 1385 images of faults at outter ring and 492 images of normal bearings without faults.
During running the script, it shows evolution of the training and as it can see on the images below, Accuracy is at 100% and Loss at 0 all the training even from the begining.
I don't understand what possibly happen. I'm not sure if is an overfitting, training options or another things. Sorry if question is too oubvious but I am starting in deep learning and I don't have so much knowlege about it.
Here i attached my script and I appreciate help:
Scalogram of Bearing Data
% Import data with inner race fault
data_inner = load('C:\Program Files\MATLAB\R2022b\toolbox\predmaint\predmaintdemos\bearingFaultDiagnosis\RollingElementBearingFaultDiagnosis-Data-master\train_data\IR_0.mat');
% Plot bearing signal and scalogram
plotBearingSignalAndScalogram(data_inner)
% Import data with outer race fault
data_outer = load('C:\Program Files\MATLAB\R2022b\toolbox\predmaint\predmaintdemos\bearingFaultDiagnosis\RollingElementBearingFaultDiagnosis-Data-master\test_data\OR_8.mat');
% Plot original signal and its scalogram
plotBearingSignalAndScalogram(data_outer)
% Import normal bearing data
data_normal = load('C:\Program Files\MATLAB\R2022b\toolbox\predmaint\predmaintdemos\bearingFaultDiagnosis\RollingElementBearingFaultDiagnosis-Data-master\train_data\N_0.mat');
% Plot original signal and its scalogram
plotBearingSignalAndScalogram(data_normal)
Prepare Training Data
fileLocation = 'C:\Program Files\MATLAB\R2022b\toolbox\predmaint\predmaintdemos\bearingFaultDiagnosis\RollingElementBearingFaultDiagnosis-Data-master\train_data';
fileExtension = '.mat';
ensembleTrain = fileEnsembleDatastore(fileLocation, fileExtension);
ensembleTrain.ReadFcn = @readMFPTBearing;
ensembleTrain.DataVariables = ["gs", "sr", "rate", "load", "BPFO", "BPFI", "FTF", "BSF"];
ensembleTrain.ConditionVariables = ["Label", "FileName"];
ensembleTrain.SelectedVariables = ["gs", "sr", "rate", "load", "BPFO", "BPFI", "FTF", "BSF", "Label", "FileName"]
reset(ensembleTrain)
while hasdata(ensembleTrain)
folderName = 'train_image';
convertSignalToScalogram(ensembleTrain,folderName);
end
% Create image datastore to store all training images
path = fullfile('.', folderName);
imds = imageDatastore(path, ...
'IncludeSubfolders',true,'LabelSource','foldernames');
% Use 20% training data as validation set
[imdsTrain,imdsValidation] = splitEachLabel(imds,0.8,'randomize');
Train Network with Transfer Learning
net = squeezenet
analyzeNetwork(net)
lgraph = layerGraph(net);
numClasses = numel(categories(imdsTrain.Labels));
newConvLayer = convolution2dLayer([1, 1],numClasses,'WeightLearnRateFactor',10,'BiasLearnRateFactor',10,"Name",'new_conv');
lgraph = replaceLayer(lgraph,'conv10',newConvLayer);
newClassificationLayer = classificationLayer('Name','new_classoutput');
lgraph = replaceLayer(lgraph,'ClassificationLayer_predictions',newClassificationLayer);
options = trainingOptions('sgdm', ...
'InitialLearnRate',0.0001, ...
'MaxEpochs',4, ...
'Shuffle','every-epoch', ...
'ValidationData',imdsValidation, ...
'ValidationFrequency',30, ...
'Verbose',false, ...
'MiniBatchSize',20, ...
'Plots','training-progress');
net = trainNetwork(imdsTrain,lgraph,options);
Validate Using Test Data Sets
fileLocation = fullfile('.', 'RollingElementBearingFaultDiagnosis-Data-master', 'test_data');
fileExtension = '.mat';
ensembleTest = fileEnsembleDatastore(fileLocation, fileExtension);
ensembleTest.ReadFcn = @readMFPTBearing;
ensembleTest.DataVariables = ["gs", "sr", "rate", "load", "BPFO", "BPFI", "FTF", "BSF"];
ensembleTest.ConditionVariables = ["Label", "FileName"];
ensembleTest.SelectedVariables = ["gs", "sr", "rate", "load", "BPFO", "BPFI", "FTF", "BSF", "Label", "FileName"];
reset(ensembleTest)
while hasdata(ensembleTest)
folderName = 'test_image';
convertSignalToScalogram(ensembleTest,folderName);
end
path = fullfile('.','test_image');
imdsTest = imageDatastore(path, ...
'IncludeSubfolders',true,'LabelSource','foldernames');
YPred = classify(net,imdsTest,'MiniBatchSize',20);
YTest = imdsTest.Labels;
accuracy = sum(YPred == YTest)/numel(YTest)
figure
confusionchart(YTest,YPred)
Adicional Functions
function plotBearingSignalAndScalogram(data)
% Convert 1-D bearing signals to scalograms through wavelet transform
fs = data.bearing.sr;
t_total = 0.1; % seconds
n = round(t_total*fs);
bearing = data.bearing.gs(1:n);
[cfs,frq] = cwt(bearing,'amor', fs);
% Plot the original signal and its scalogram
figure
subplot(2,1,1)
plot(0:1/fs:(n-1)/fs,bearing)
xlim([0,0.1])
title('Vibration Signal')
xlabel('Time (s)')
ylabel('Amplitude')
subplot(2,1,2)
surface(0:1/fs:(n-1)/fs,frq,abs(cfs))
shading flat
xlim([0,0.1])
ylim([0,max(frq)])
title('Scalogram')
xlabel('Time (s)')
ylabel('Frequency (Hz)')
end
function convertSignalToScalogram(ensemble,folderName)
% Convert 1-D signals to scalograms and save scalograms as images
data = read(ensemble);
fs = data.sr;
x = data.gs{:};
label = char(data.Label);
fname = char(data.FileName);
ratio = 5000/97656;
interval = ratio*fs;
N = floor(numel(x)/interval);
% Create folder to save images
path = fullfile('.',folderName,label);
if ~exist(path,'dir')
mkdir(path);
end
for idx = 1:N
sig = envelope(x(interval*(idx-1)+1:interval*idx));
cfs = cwt(sig,'amor', seconds(1/fs));
cfs = abs(cfs);
img = ind2rgb(round(rescale(flip(cfs),0,255)),jet(320));
outfname = fullfile('.',path,[fname '-' num2str(idx) '.jpg']);
imwrite(imresize(img,[227,227]),outfname);
end
end
0 Comments
Accepted Answer
Matt J
on 21 Aug 2023
Moved: Matt J
on 23 Aug 2023
If I had to guess (I do have to), it is because numClasses=1 and you only have one label, accidentally of course. This response is very easy to learn with 100% accuracy.
If you attached imdsTrain and imdsValidation in a .mat file, it may be possible to do more meaningful troubleshooting.
2 Comments
Matt J
on 23 Aug 2023
You're welcome, but please Accept-click the answer if the question has been addressed.
More Answers (0)
See Also
Categories
Find more on AI for Signals and Images in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!