Invalid training data. X and Y must have the same number of observations for training a network with MFCC coefficients..
43 views (last 30 days)
Show older comments
My Xtrain is 13854x14 where 14 is feature double and Ytrain(label) is 13854x1 double.Xtrain is mfcc coefficient of an audio file and Ytrain is the corresponding label.How can I train such a network with unequal number of observations.
I would like to use something like this but options are welcome:
layers = [
% input signal chunk - 1000x1
imageInputLayer([1000 1 1])
convolution2dLayer([3,1],1,'Padding','same')
reluLayer
convolution2dLayer([3,1],32,'Padding','same')
reluLayer
convolution2dLayer([3,1],32,'Padding','same')
reluLayer
convolution2dLayer([3,1],32,'Padding','same')
reluLayer
fullyConnectedLayer(1000)
regressionLayer
];
% define training options
miniBatchSize = 128;
validationFrequency = floor(numel(YTrain)/miniBatchSize);
options = trainingOptions('adam', ...
'MiniBatchSize',miniBatchSize, ...
'MaxEpochs',30, ...
'InitialLearnRate',1e-3, ...
'LearnRateSchedule','piecewise', ...
'LearnRateDropFactor',0.1, ...
'LearnRateDropPeriod',20, ...
'Shuffle','every-epoch', ...
'ValidationData',{XValidation,YValidation}, ...
'ValidationFrequency',validationFrequency, ...
'Plots','training-progress', ...
'Verbose',false);
% train and wait
net = trainNetwork(XTrain,YTrain,layers,options);
0 Comments
Answers (1)
Sourav Bairagya
on 22 Aug 2019
To use the “XTrain”and “YTrain” in “trainNetwork” function, you should reshape those properly, otherwise it will throw this type of error.
“XTrain” should be stored as a 4-D vector where the first three dimension describes the dimension of single training sample and fourth dimension will be the number of training samples. For example, say training data contains 50 color images of size 256X256. Then, “XTrain” should be arranged in 256X256X3X50 format.
XTrain=reshape(XTrain, [14,1,1,13854]);
Here, your training data is of size 13854X14 where each sample has 14 features and total number of samples is 13854. Hence, this should be arranged as 14X1X1X13854.
“YTrain” is in correct form. Hence, it need not to be reshaped.
Now, in layers you should specify the dimensions of your input and output corresponding to a single sample. Hence, here, as per your requirement in “imageInputLayer” dimension would be [14 1 1] and in “fullyConnectedLayer” dimension of output will be 1. The code section is as follows:
layers =[
imageInputLayer([14 1 1])
convolution2dLayer([3,1],1,'Padding','same')
reluLayer
convolution2dLayer([3,1],32,'Padding','same')
reluLayer
convolution2dLayer([3,1],32,'Padding','same')
reluLayer
convolution2dLayer([3,1],32,'Padding','same')
reluLayer
fullyConnectedLayer(1)
regressionLayer
];
Similarly, you have to arrange your validation datasets also.
0 Comments
See Also
Categories
Find more on Deep Learning Toolbox 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!