Plot validation curve of Neural Network

4 Ansichten (letzte 30 Tage)
Jacky Liu
Jacky Liu am 13 Nov. 2017
Kommentiert: sinan salim am 5 Apr. 2020
I just download and run the sample code "Deep Learning Example: Training from scratch using CIFAR-10 Dataset" Demo_TrainingFromScratch.mlx
I could get the accuracy plot by adding
'Plots','training-progress'
into trainingOptions.
However, this only plot training accuracy.
How can I modify this example to also plot validation accuracy like this page ?
When I execute
[net, info] = trainNetwork(imds_Train.Files,imds_Train.Labels, layers, opts);
It print out error message:
Error using trainNetwork (line 140)
Invalid training data. X must be a 4-D array of images, an ImageDatastore, or a table.

Antworten (2)

Bhartendu
Bhartendu am 8 Apr. 2018
1. For Validation accuracy and it's plot:
  • Perform CV partition as follows:
X = imds_Train.Files
Y = imds_Train.Labels
num_images = size(X,4);
% Precentage of split
Percent = 30
idx = randperm(num_images,Percent/100*num_images);
X_val = X(:,:,:,idx);
X(:,:,:,idx) = [];
Y_val = Y(idx);
Y(idx) = [];
disp(['Training samples: ', length(Y), ' Validation samples: ', length(Y_val)])
  • Modify for ValidationData in the options like:
options = trainingOptions('sgdm',...
'MaxEpochs', 50 ,...
'ValidationData',{X_val,Y_val} ,...
'MiniBatchSize', 64 ,...
'InitialLearnRate', 1e-4 ,...
'ValidationPatience', 10,...
'Verbose', 1 ,...
'Plots','training-progress');
2. For Error using trainNetwork: Check my answer here

Maria Duarte Rosa
Maria Duarte Rosa am 15 Dez. 2017
Hi Jacky,
When you work with imageDatastore you do not need to pass the files and labels separately into trainNetwork and also into the 'ValidationData' argument of trainingOptions. You can simply do:
[net, info] = trainNetwork(imds_Train, layers, opts);
And (in 'trainingOptions'):
'ValidationData',imds_Validation,...
I hope this helps.
Please see here for more details: trainNetwork, trainingOptions
  1 Kommentar
sinan salim
sinan salim am 5 Apr. 2020
how can find the imds_Validation,,if i will put the imds-Train instedt of the validation data ,will give low validation accuraccy ,else without mention the validation ,,its will plot the curve but will not show the validation of accuracy just will refer to NaN
so what will be the solution ?

Melden Sie sich an, um zu kommentieren.

Community Treasure Hunt

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

Start Hunting!

Translated by