MATLAB Answers

How to index Neural Network for loop

7 ビュー (過去 30 日間)
Justin Hayes
Justin Hayes 2020 年 8 月 1 日
コメント済み: Justin Hayes 2020 年 8 月 7 日
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)

  0 件のコメント

サインインしてコメントする。

採用された回答

Anshika Chaurasia
Anshika Chaurasia 2020 年 8 月 6 日
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 件のコメント

Justin Hayes
Justin Hayes 2020 年 8 月 7 日
Thank you very much!

サインインしてコメントする。

その他の回答 (0 件)

Community Treasure Hunt

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

Start Hunting!

Translated by