How is it possible to use a validation set with a LSTM?

Y
ytrs-01 · May 17, 2021 · 1.8K views
Question
When I try to use the Validation set with a LSTM layer, it shows the following error:     options = trainingOptions('adam', ... 'ExecutionEnvironment','gpu', ... 'GradientThreshold',1, ... 'MaxEpochs',maxEpochs, ... 'ValidationData',{XTest,YTest},... 'MiniBatchSize',miniBatchSize, ... 'LearnRateSchedule','piecewise', ... 'SequenceLength','longest', ... 'Shuffle','never', ... 'Verbose',0, ... 'Plots','training-progress'); net = trainNetwork(XTrain,categorical(YTrain),layers,options); Error: Training with validation data is not supported for networks with LSTM layers. Is there another way to use the Validation set during the training of the network?
Expert Answer
Profile picture of John Michell
John Michell PhD Expert
Answered Aug 13, 2026
It's ugly, but if you use Checkpoints, then you can use an OutputFcn to (once per epoch) load the network from a checkpoint and run it against your validation data. It isn't very efficient, but it's okay if you're only doing it once per epoch. You won't get it on the training plot of course.
 
100% Run Guarantee 3-Hour Fast-Track Delivery

Need a Custom Version or Complete Simulation for This Problem?

Our 500+ PhD engineers build, debug, and optimize working MATLAB scripts and Simulink (.slx) models tailored to your exact assignment rubrics with zero plagiarism.

Tested on MATLAB R2024b / R2026a
Turnitin 0% Plagiarism Report
Free 7-Day Revisions Guarantee
Have a different question? Ask here

Get a Free Consultation or a Sample Assignment Review!