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)
Best Answer