GoogLeNet 1.
GoogLeNet
2.
Googlealarm clock hourglass pocket watch wall clock watches5clock zip
3.
70% 30%
unzip(clock.zip);
imds = imageDatastore(clock,
IncludeSubfolders,true,
LabelSource,foldernames);
[imdsTrain,imdsValidation] = splitEachLabel(imds,0.7,randomized);
GoogLeNet
net = googlenet;
lgraph = layerGraph(net);
figure(Units,normalized,Position,[0.1 0.1 0.8 0.8]);
plot(lgraph)
1
net.Layers(1)
ans =
ImageInputLayer with properties:
Name: data
InputSize: [224 224 3]
Hyperparameters
DataAugmentation: none
Normalization: zerocenter
AverageImage: [2242243 single]
lgraph = removeLayers(lgraph, {loss3-classifier,prob,output});
numClasses = numel(categories(imdsTrain.Labels));
newLayers = [
fullyConnectedLayer(numClasses,Name,fc,WeightLearnRateFactor,10,BiasLearnRat
softmaxLayer(Name,softmax)
inputSize = net.Layers(1).InputSize;
2
classificationLayer(Name,classoutput)];
lgraph = addLayers(lgraph,newLayers);
lgraph = connectLayers(lgraph,pool5-drop_7x7_s1,fc);
figure(Units,normalized,Position,[0.3 0.3 0.4 0.4]);
plot(lgraph)
ylim([0,10])
layers = lgraph.Layers;
connections = lgraph.Connections;
edit(fullfile(matlabroot,examples,nnet,main,freezeWeights.m))
layers(1:110) = freezeWeights(layers(1:110));
lgraph = createLgraphUsingConnections(layers,connections);
pixelRange = [-30 30];
imageAugmenter = imageDataAugmenter(
RandXReflection,true,
3
RandXTranslation,pixelRange,
RandYTranslation,pixelRange);
augimdsTrain = augmentedImageDatastore(inputSize(1:2),imdsTrain,
DataAugmentation,imageAugmenter);
augimdsValidation = augmentedImageDatastore(inputSize(1:2),imdsValidation);
options = trainingOptions(sgdm,
MiniBatchSize,10,
MaxEpochs,6,
InitialLearnRate,1e-4,
ValidationData,augimdsValidation,
ValidationFrequency,3,
ValidationPatience,Inf,
Verbose,false ,
Plots,training-progress);
net = trainNetwork(augimdsTrain,lgraph,options);
[YPred,probs] = classify(net,augimdsValidation);
accuracy = mean(YPred == imdsValidation.Labels)
accuracy = 0.8857
4.
4 4
idx = randperm(numel(imdsValidation.Files),4);
figure
for i = 1:4
subplot(2,2,i)
I = readimage(imdsValidation,idx(i));
imshow(I)
label = YPred(idx(i));
title(string(label) + , + num2str(100*max(probs(idx(i),:)),3) + %);
end
wall clockalarm clock45.7% 100%
5.
wall clockalarm clock hourglass pocket watch watches
6.
5
Reviews
There are no reviews yet.