How to input validation data correctly for neural network?

8 views (last 30 days)
I am having trouble getting MATLAB to accept my validation data correctly.
I am doing sequence-to-sequence classification, with inputs as doubles and responses as categorical arrays. I have separated out my data for training, validation, and testing. Here is some code.
inputSize = 1;
embeddingDimension = 256;
numClasses = numel(categories([YTrain{:}]));
batchSize = 121;
layers = [
sequenceInputLayer(inputSize)
lstmLayer(256,'OutputMode','sequence')
dropoutLayer(0.2)
fullyConnectedLayer(numClasses)
softmaxLayer
classificationLayer];
options = trainingOptions('adam', ...
'MaxEpochs',500, ...
'InitialLearnRate',0.01, ...
'GradientThreshold',2, ...
'MiniBatchSize',batchSize, ...
'Shuffle','never', ...
'Plots','training-progress', ...
'Verbose',false, ...
'ValidationData',[XVal,YVal], ...
'ValidationFrequency',1512, ...
'CheckpointPath','checkpoints', ...
'CheckpointFrequency',1, ...
'CheckpointFrequencyUnit','epoch');
net = trainNetwork(XTrain,YTrain,layers,options);
XVal is an N x 1 cell array of doubles, and YVal is an N x 1 cell array of categorical. Here are some errors I have recieved after trying [XVal,YVal] and {XVal,YVal}.
Error 1
Error using nnet.cnn.TrainingOptionsADAM
The value of 'ValidationData' is invalid. Cell array with validation data must have two elements:
the input data X and a numeric array of responses Y.
Error in trainingOptions (line 342)
opts = nnet.cnn.TrainingOptionsADAM(varargin{:});
Error 2
Error using trainNetwork
Training and validation responses must have the same categories. To view the categories of the responses, use the
categories function.
Error in script (line 198)
net = trainNetwork(XTrain,YTrain,layers,options);
Caused by:
Error using nnet.internal.cnn.trainNetwork.DLTDataPreprocessor>iAssertClassNamesAreTheSame
Training and validation responses must have the same categories. To view the categories of the responses, use
the categories function.
Thank you for any help that may be provided!

Answers (0)

Categories

Find more on Deep Learning with Time Series and Sequence Data 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!

Translated by