added script for training alexnet
parent
29d422e3ab
commit
cdb8ee20e8
@ -0,0 +1,54 @@
|
|||||||
|
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);
|
Loading…
Reference in New Issue