Plot validation curve of Neural Network

2 ビュー (過去 30 日間)
Jacky Liu
Jacky Liu 2017 年 11 月 13 日
コメント済み: sinan salim 2020 年 4 月 5 日
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 Center および File ExchangeDeep Learning Toolbox についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by