Plot validation curve of Neural Network

2 vues (au cours des 30 derniers jours)
Jacky Liu
Jacky Liu le 13 Nov 2017
Commenté : sinan salim le 5 Avr 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.

Réponses (2)

Bhartendu
Bhartendu le 8 Avr 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 le 15 Déc 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 commentaire
sinan salim
sinan salim le 5 Avr 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 ?

Connectez-vous pour commenter.

Catégories

En savoir plus sur Deep Learning Toolbox dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by