How to use trainNetwork with transform datastore with multiple outputs?

조회 수: 16 (최근 30일)
Noam
Noam 2023년 2월 9일
댓글: Noam 2023년 2월 9일
my code create a audioDataStore, transform it to yamnet features (mel spectrum) and try to train it.
But i get the following error:
Input datastore returned more than one observation per row for network input 1.
The code:
net = yamnet;
DS = audioDatastore(FolderName, ...
'FileExtensions',{'.wav','.mp3'},"IncludeSubfolders",true,'LabelSource','foldernames');
DS.Labels = setcats(DS.Labels,cellstr(net.Layers(86).Classes));
TR = transform(DS,@(audio,info)preProcess(audio,info),"IncludeInfo",true);
options = trainingOptions("adam");
trainNetwork(TR,net.Layers,options)
function [data,info] = preProcess(audio,info)
data{1} = yamnetPreprocess(audio,info.SampleRate);
data{2} = repmat(info.Label,1,size(data{1},4));
end
Yamnet produce multiple observations for each audio file (for instance, for 10 seconds file it will create 96×64×1×19 matrix which are 19 observations. For some reason trainNetwork want only one observation, how do I fix it?

채택된 답변

jibrahim
jibrahim 2023년 2월 9일
Hi Noam,
Check out this example:
The example uses a transformed datastore as well. the transformation function is at the bottom:
function [data,info] = audioPreprocess(audioIn,info)
class = info.Label;
fs = info.SampleRate;
features = yamnetPreprocess(audioIn,fs);
numSpectrograms = size(features,4);
data = cell(numSpectrograms,2);
for index = 1:numSpectrograms
data{index,1} = features(:,:,:,index);
data{index,2} = class;
end
end

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Pretrained Models에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by