Plot validation curve of Neural Network

4 次查看(过去 30 天)
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.

回答(2 个)

Bhartendu
Bhartendu 2018-4-8
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 2017-12-15
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 个评论
sinan salim
sinan salim 2020-4-5
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 ?

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Image Data Workflows 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by