Created
July 4, 2019 03:19
-
-
Save smzn/cb85de7e2c89d0241803dc3a07301ed7 to your computer and use it in GitHub Desktop.
改良コード
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
imds = imageDatastore('/Users/mizuno/Documents/MATLAB/deeplearning/SimpleDeepLearning/trainingSet/','IncludeSubfolders',true,'LabelSource','foldernames'); | |
labelCount = countEachLabel(imds) | |
perm = randperm(40000,20); | |
montage(imds, 'Indices', perm); | |
img = readimage(imds,1); | |
size(img) | |
[imdsTrain,imdsValidation] = splitEachLabel(imds,0.8); | |
layers = [imageInputLayer([28 28 1]) | |
convolution2dLayer(3,8,'Padding','same') | |
reluLayer | |
maxPooling2dLayer(2,'Stride',2) | |
convolution2dLayer(3,16,'Padding','same') | |
batchNormalizationLayer | |
reluLayer | |
maxPooling2dLayer(2,'Stride',2) | |
convolution2dLayer(3,32,'Padding','same') | |
batchNormalizationLayer | |
reluLayer | |
fullyConnectedLayer(10) | |
softmaxLayer | |
classificationLayer]; | |
options = trainingOptions('sgdm', ... | |
'InitialLearnRate',0.001, ... | |
'MaxEpochs',4, ... | |
'Shuffle','every-epoch', ... | |
'ValidationData',imdsValidation, ... | |
'ValidationFrequency',30, ... | |
'Verbose',false, ... | |
'Plots','training-progress'); | |
net = trainNetwork(imdsTrain,layers,options); | |
YPred = classify(net,imdsValidation); | |
YValidation = imdsValidation.Labels; | |
accuracy = sum(YPred == YValidation)/numel(YValidation) | |
[numberconf, numbernames] = confusionmat(YValidation, YPred); | |
heatmap(numbernames, numbernames, numberconf); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment