Below is my code as well as the information about the variables for a basic audio classification problem, which is reading an audio file and distinguishing whether the signal is a car horn or a dog barking. I followed the same format as this tutorial I found: https://www.mathworks.com/help/audio/gs/classify-sound-using-deep-learning.html.
I'm not sure where I went wrong, but when training the program did not plot the loss value. And when I tried to test a sample file, the result was "<undefined>". I would appreciate any help on this.
% --------------------------------------------------------------
% Loading Training and Evaluation Sets for Car Horn and Dog Bark
% --------------------------------------------------------------carDataStore = UrbanSound8K(UrbanSound8K.class == "car_horn",:);carDataStore = carDataStore(carDataStore.salience == 1,:);dogDataStore = UrbanSound8K(UrbanSound8K.class == "dog_bark",:);dogDataStore = dogDataStore(dogDataStore.salience == 1,:);carData = [];dogData = [];% Add first 2 seconds of each audiofile to their respective matrices and
% produce labels
for i = 1:height(carDataStore) thisfile = "UrbanSound8K\audio\fold" + string(carDataStore(i,:).fold) + "\" + string(carDataStore(i,:).slice_file_name); if audioinfo(thisfile).Duration >= 2 && audioinfo(thisfile).SampleRate == 44100 [y,fs] = audioread(thisfile); samples = [1,2*fs]; clear y fs; [y,fs] = audioread(thisfile, samples); carData = [carData,y(:,1)]; endendcarLabels = repelem(categorical("car horn"),width(carData),1);for i = 1:height(dogDataStore) thisfile = "UrbanSound8K\audio\fold" + string(dogDataStore(i,:).fold) + "\" + string(dogDataStore(i,:).slice_file_name); if audioinfo(thisfile).Duration >= 2 && audioinfo(thisfile).SampleRate == 44100 [y,fs] = audioread(thisfile); samples = [1,2*fs]; clear y fs; [y,fs] = audioread(thisfile, samples); dogData = [dogData,y(:,1)]; endenddogLabels = repelem(categorical("dog barking"),width(dogData),1);dogVals = round(0.8*width(dogData));carVals = round(0.8*width(carData));audioTrain = [dogData(:,1:dogVals),carData(:,1:carVals)];labelsTrain = [dogLabels(1:dogVals);carLabels(1:carVals)];audioValidation = [dogData(:,(dogVals + 1):end),carData(:,(carVals + 1):end)];labelsValidation = [dogLabels((dogVals + 1):end);carLabels((carVals + 1):end)];% ---------------------------------------------------------
% Audio Feature Extractor to reduce dimensionality of audio,
% Extracting slope and centroid of mel spectrum over time
% ---------------------------------------------------------aFE = audioFeatureExtractor("SampleRate",fs, ... "SpectralDescriptorInput","melSpectrum", ... "spectralCentroid",true, ... "spectralSlope",true);featuresTrain = extract(aFE,audioTrain);[numHopsPerSequence,numFeatures,numSignals] = size(featuresTrain);featuresTrain = permute(featuresTrain,[2,1,3]);featuresTrain = squeeze(num2cell(featuresTrain,[1,2]));numSignals = numel(featuresTrain);[numFeatures,numHopsPerSequence] = size(featuresTrain{1});featuresValidation = extract(aFE,audioValidation);featuresValidation = permute(featuresValidation,[2,1,3]);featuresValidation = squeeze(num2cell(featuresValidation,[1,2]));% ----------------------------------------
% Defining the Neural Network Architecture
% ----------------------------------------layers = [ ... sequenceInputLayer(numFeatures) lstmLayer(50,"OutputMode","last") fullyConnectedLayer(numel(unique(labelsTrain))) softmaxLayer classificationLayer];options = trainingOptions("adam", ... "Shuffle","every-epoch", ... "ValidationData",{featuresValidation,labelsValidation}, ... "Plots","training-progress", ... "Verbose",false);net = trainNetwork(featuresTrain,labelsTrain,layers,options);
Best Answer