MATLAB Answers

0

I am getting: Error using nnet.inter​​nal.cnn.u​t​il.Netwo​rk​DataVal​ida​tor/as​sert​Corre​ctRes​pons​eSizeF​orO​utputLa​ye​r (line 285) Invalid validation data. The output size (118) of the last layer doesn't match the number of classes (79).How to match??

Asked by chandra kala on 18 May 2018 at 5:44
Latest activity Commented on by Image Analyst
on 18 May 2018 at 11:42

unzip('Character-Dataset.zip'); characterds = imageDatastore('Character-Dataset','IncludeSubfolders',true,'LabelSource','foldernames'); [characterdsTrain,characterdsValidation] = splitEachLabel(characterds,0.7,'randomized'); numTrainImages = numel(characterdsTrain.Labels); idx = randperm(numTrainImages,16); figure for i = 1:16 subplot(4,4,i) I = readimage(characterdsTrain,idx(i)); imshow(I) end net = alexnet; inputSize = net.Layers(1).InputSize layersTransfer = net.Layers(1:end-3); numClasses = numel(categories(characterdsTrain.Labels)) layers = [ layersTransfer fullyConnectedLayer(numClasses,'WeightLearnRateFactor',20,'BiasLearnRateFactor',20) softmaxLayer classificationLayer]; pixelRange = [-30 30]; imageAugmenter = imageDataAugmenter( ... 'RandXReflection',true, ... 'RandXTranslation',pixelRange, ... 'RandYTranslation',pixelRange); augimdsTrain = augmentedImageDatastore(inputSize(1:2),characterdsTrain, ... 'DataAugmentation',imageAugmenter); augimdsValidation = augmentedImageDatastore(inputSize(1:2),characterdsValidation); options = trainingOptions('sgdm', ... 'MiniBatchSize',10, ... 'MaxEpochs',6, ... 'InitialLearnRate',1e-4, ... 'ValidationData',augimdsValidation, ... 'ValidationFrequency',3, ... 'ValidationPatience',Inf, ... 'Verbose',false, ... 'Plots','training-progress'); netTransfer = trainNetwork(augimdsTrain,layers,options);

0 Answers

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today