You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
55 lines
1.5 KiB
Matlab
55 lines
1.5 KiB
Matlab
2 years ago
|
imds=imageDatastore( ...
|
||
|
'SignsCutted', ...
|
||
|
'IncludeSubfolders',true, ...
|
||
|
'LabelSource','foldernames');
|
||
|
|
||
|
fprintf("Anzahl Bilder: %d\n", length(imds.Labels));
|
||
|
|
||
|
rng(7);
|
||
|
[imdsTrain, idmsValidation] = splitEachLabel(imds,0.7,'randomized');
|
||
|
|
||
|
fprintf("Trainingsmenge Anzahl Elemente: %d Test(Validierungs)menge: %d\n", ...
|
||
|
length(imdsTrain.Labels), length(idmsValidation.Labels));
|
||
|
|
||
|
net=alexnet;
|
||
|
|
||
|
layersTransfer = net.Layers(1:end-3);
|
||
|
numClasses = numel(categories(imdsTrain.Labels));
|
||
|
|
||
|
layers = [
|
||
|
layersTransfer
|
||
|
fullyConnectedLayer(numClasses, ...
|
||
|
'WeightLearnRateFactor',20, ...
|
||
|
'BiasLearnRateFactor',20)
|
||
|
softmaxLayer
|
||
|
classificationLayer
|
||
|
];
|
||
|
|
||
|
options = trainingOptions('sgdm', ...
|
||
|
MiniBatchSize=10, ... % 10
|
||
|
MaxEpochs=6, ... % 6
|
||
|
InitialLearnRate=1e-4, ... % 1e-4
|
||
|
ValidationData=idmsValidation, ...
|
||
|
ValidationFrequency=3, ... % 3
|
||
|
ValidationPatience=10, ... % 5
|
||
|
Verbose=false, ... % false
|
||
|
Plots='training-progress');
|
||
|
|
||
|
netTransfer = trainNetwork(imdsTrain, layers, options);
|
||
|
|
||
|
[yPred, scores] = classify(netTransfer, idmsValidation);
|
||
|
|
||
|
idx=randperm(numel(idmsValidation.Files), 64);
|
||
|
|
||
|
figure
|
||
|
for i=1 : 64
|
||
|
subplot(8,8,i)
|
||
|
I = readimage(idmsValidation, idx(i));
|
||
|
imshow(I)
|
||
|
label = yPred(idx(i));
|
||
|
title(string(label));
|
||
|
end
|
||
|
|
||
|
accuracy = mean(yPred == idmsValidation.Labels);
|
||
|
fprintf("Genauigkeit: %3.2f\n", accuracy*100);
|