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

Illustration
ytrs-01 - 2021-05-17T15:57:25+00:00
Question: How is it possible to use a validation set with a LSTM?

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 answered . 2025-11-20

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.
 


Not satisfied with the answer ?? ASK NOW

Get a Free Consultation or a Sample Assignment Review!