could anyone help me how to feed the validation data into the options in deep neural network.

61 views (last 30 days)
I have done the matlab code written by myself instead of using tool box to train and test the model.
For training i am using net = trainNetwork(XTrain,YTrain,layers,options)
for options i am using training options ADAM which has in-built
options.ValidationData []
options.ValidationFrequency 50
options.ValidationPatience, 5
Now I want to include my (XVal, YVal) into it.
So I think the model can perform both training and validation if I am not mistaken.
Or else please help me how to feed (XVal, YVal) into the model.

Answers (1)

Katja Mogalle
Katja Mogalle on 30 Jun 2021
In order to perform validation periodically during training using trainNetwork, you can specify the validation data in the trainingOptions command that is used to generate training options.
Roughly, it could look as follows:
options = trainingOptions('adam', ...
'ValidationData',{XVal, YVal}, ...
'ValidationFrequency',30, ...
net = trainNetwork(XTrain,YTrain,layers,options);
I hope this answers your question.
jaah navi
jaah navi on 1 Jul 2021
When I tried to execute the code using options =
layers = [ ...
trainingOptions('adam', ...
'ValidationData',{XVal,YVal}, ...
'ValidationFrequency',30, ...
'MaxEpochs',50, ...
'MiniBatchSize',50, ...
net = trainNetwork(XTrain,YTrain,layers,options);
I am getting error stating Training with validation data is not supported for networks with LSTM layers.Could you please help me to overcome the error.
Katja Mogalle
Katja Mogalle on 1 Jul 2021
Validation of LSTM Networks during training was enabled in MATLAB R20018b. I suspect you have an older version of MATLAB?
So one option would be to upgrade to a newer version of MATLAB. Deep learning is a very active area at MathWorks so you'll see a lot of new capabilities added in every release. The newest release at the moment is R2021a.
To be able to better help you I'd need to know how your data is structured and what task you are trying to solve.
If I'd have to guess ... I've noticed that you aren't using any LSTM layers. Perhaps you have neither image data nor data with a time dimension? Starting in R2020b, there is a featureInputLayer that can better deal with tabular-style data. If you do want to stay in the older MATLAB release, you could try the workaround mentioned here: . The idea is to use an imageInputLayer and reshape your data to be in the format 1-by-1-by-NumFeatures-by-NumObservations. Networks with imageInputLayers (instead of sequenceInputLayers) support validation during training already since R2017b.

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!