How to index Neural Network for loop

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

采纳的回答

Anshika Chaurasia
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

更多回答(0 个)

类别

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