Testing classifying gender on LSTM

조회 수: 7 (최근 30일)
Alfi
Alfi 2021년 1월 19일
댓글: jibrahim 2021년 1월 20일
I tried to recreate gender classification using LSTM Method for deep learning.
On the example, it show the prediction for all training data.
But I still confused on how to test a random sample .wav file fom the test dataset, so that my matlab can give specific prediction ouput of its gender labels.
I tried to add new line below and use predict, but it didn't work.
prediction = classify(net,sample_feature)
Can anyone explain or provide me link on how to test random file and give specific labels ouput?

채택된 답변

jibrahim
jibrahim 2021년 1월 19일
Alfi,
The second section of this example (Classify Gender with a Pre-Trained Network) addresses this:
  댓글 수: 2
Alfi
Alfi 2021년 1월 20일
편집: Alfi 2021년 1월 20일
Thank you! I forgot to save the trained-network.
But now I have another problem with Confusion Matrix.
% Testing
load('TestLSTM.mat', 'net', 'M', 'S');
[audioIn, Fs] = audioread('common_voice_en_1720.wav');
sound(audioIn, Fs)
boundaries = detectSpeech(audioIn, Fs);
audioIn = audioIn(boundaries(1):boundaries(2));
extractor = audioFeatureExtractor( ...
"SampleRate",Fs, ...
"Window",hamming(round(0.03*Fs),"periodic"), ...
"OverlapLength",round(0.02*Fs), ...
...
"gtcc",true, ...
"gtccDelta",true, ...
"gtccDeltaDelta",true, ...
...
"SpectralDescriptorInput","melSpectrum", ...
"spectralCentroid",true, ...
"spectralEntropy",true, ...
"spectralFlux",true, ...
"spectralSlope",true, ...
...
"pitch",true, ...
"harmonicRatio",true);
sample_features = extract(extractor, audioIn);
sample_features = (sample_features.' - M)./S;
classify(net, sample_features)
%Confusion Matrix
prediction = classify(net,sample_features);
figure
cm = confusionchart(labelsTrain,prediction,'title','Prediction Accuracy');
cm.ColumnSummary = 'column-normalized';
cm.RowSummary = 'row-normalized';
It says that "Vectors of true and predicted labels must have the same number of observations."
What should I do? Do I need to cross validate?
jibrahim
jibrahim 2021년 1월 20일
In your code, prediction is the predicted label from the speech file you're chekcing. I do not know what labelsTrain is, but I suspect it contains labels from multiple files, rather just one, so you get an error because prediction and labelsTrain have inconsistent sizes. Note that it does not make much sense to generate a confusion matrix for one prediction. A confusion matric would be useful if you classify a large number of files.

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 AI for Signals에 대해 자세히 알아보기

제품


릴리스

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by