Effacer les filtres
Effacer les filtres

How to index Neural Network for loop

2 vues (au cours des 30 derniers jours)
Justin Hayes
Justin Hayes le 1 Août 2020
Commenté : Justin Hayes le 7 Août 2020
I would like to run this loop 4 times for the InitialLearnRate values of 0.0001, 0.001, 0.01, and 0.1. I would like to index the loop as well so I can compare the fracCorrect for each loop. Thank you!
InitialLearnRate = [0.0001,0.001,0.01,0.1]
augmentedDS_test = zeros(1,length(InitialLearnRate))
predictions = zeros(1,length(InitialLearnRate))
fracCorrect = zeros(1,length(InitialLearnRate))
for i = InitialLearnRate
imageDS = imageDatastore('deeplearning_course_files','IncludeSubfolders',true,'LabelSource','foldernames');
[wormTrain,wormTest] = splitEachLabel(imageDS,0.2); % takes x images from
augmentedDS_train = augmentedImageDatastore([227 227],wormTrain,'ColorPreprocessing','gray2rgb')
augmentedDS_test = augmentedImageDatastore([227 227],wormTest,'ColorPreprocessing','gray2rgb')
net = alexnet;
layers = net.Layers
fc = fullyConnectedLayer(2);
layers(end-2) = fc;
layers(end) = classificationLayer;
options = trainingOptions('sgdm','InitialLearnRate',i,'Momentum',0.1,'MaxEpochs',15)
[wormnet,info] = trainNetwork(augmentedDS_train,layers,options);
predictions = classify(wormnet,augmentedDS_test);
wormActual = wormTest.Labels;
numCorrect = nnz(predictions == wormActual);
fracCorrect = numCorrect/numel(predictions)
end
confusionchart(wormTest.Labels,predictions)
plot(info.TrainingLoss)

Réponse acceptée

Anshika Chaurasia
Anshika Chaurasia le 6 Août 2020
You can consider trying indexing as given below:
for i = 1:length(InitialLearnRate)
....
options = trainingOptions('sgdm','InitialLearnRate',InitialLearnRate(i),'Momentum',0.1,'MaxEpochs',15)
....
fracCorrect(i) = numCorrect/numel(predictions)
...
end
  1 commentaire
Justin Hayes
Justin Hayes le 7 Août 2020
Thank you very much!

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Image Data Workflows 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