url = 'https://ssd.mathworks.com/supportfiles/audio/FSDD.zip';
datasetFolder = tempdir;
unzip(url,datasetFolder)
ads = audioDatastore(fullfile(datasetFolder,'FSDD'), ...
'IncludeSubfolders',true);
[~,filenames] = fileparts(ads.Files);
ads.Labels = categorical(extractBetween(filenames,'_','_'));
[adsTrain,adsValidation] = splitEachLabel(ads,.9);
inputSize = 500;
numHiddenUnits = 100;
numClasses = length(unique(ads.Labels));
layers = [ ...
sequenceInputLayer(inputSize)
bilstmLayer(numHiddenUnits,"OutputMode","sequence")
bilstmLayer(numHiddenUnits,"OutputMode","last")
fullyConnectedLayer(numClasses)
softmaxLayer
classificationLayer];
tdsTrain = transform(@(x,info)processData(x,inputSize,info),adsTrain,'IncludeInfo',true);
tdsValidation = transform(@(x,info)processData(x,inputSize,info),adsValidation,'IncludeInfo',true);
options = trainingOptions("adam", ...
"MaxEpochs",4, ...
"MiniBatchSize",256, ...
"Plots","training-progress", ...
"Verbose",false, ...
"Shuffle","every-epoch", ...
"LearnRateSchedule","piecewise", ...
"LearnRateDropFactor",0.1, ...
"LearnRateDropPeriod",1, ...
"ValidationData",tdsValidation,...
'ValidationFrequency',100);
net = trainNetwork(tdsTrain,layers, options)
Best Answer