I am getting error says parse error
Show older comments
% program to recognize digits using Deep CNN
%Giving path to dataset folder
digitDatasetPath='C:\Users\CYRIL REDDY\MATLAB\Projects\cyril digit recognition';
%Reading Digit Images from Image Database Folder
digitimages=imageDatastore(digitDatasetPath,'IncludeSubfolders',true,'LabelSource','foldernames');
%Distributing Images in the set of Training and Testing
numTrainFiles=750; %numTrainFiles=0.75 (75%)
[TrainImages,TestImages]=splitEachLabel(digitimages,numTrainFiles,'randomize');
%------------------------Building CNN---------------
layers=[
imageInputLayer([28,28,1],'Name','Input')
convolution2dLayer(3,8,'Padding','same','Name','Conv_1')
batchNormalizationLayer('Name','BN_1')
reluLayer('Name','Relu_1')
maxPooling2dLayer(2,'Stride',2,'Name','Maxpool_1')
convolution2dLayer(3,16,'Padding','same','Name','Conv_2')
batchNormalizationLayer('Name','BN_2')
reluLayer('Name','Relu_2')
maxPooling2dLayer(2,'Stride',2,'Name','MaxPool_2')
convolution2dLayer(3,32,'Padding','same','Name','Conv_3')
batchNormalizationLayer('Name','BN_3')
reluLayer('Name','Relu_3')
maxPooling2dLayer(2,'Stride',2,'Name','Maxpool_3')
convolution2dLayer(3,64,'Padding','same','Name','Conv_4')
batchNormalizationLayer('Name','BN_4')
reluLayer('Name','Relu_4')
fullyConnectedLayer(10,'Name','FC')
softmaxLayer('Name','SoftMax');
classificationLayer('Name','Output Classification');
];
lgraph=layerGraph(layers);
plot(lgraph); %Plotting Network Structure
%------Training Options-----------------------------------------
options =
trainingOptions('sgdm','InitialLearnRate',0.01,'MaxEpochs',4,'Shuffle','every-epoch','ValidationData',TestImages,'ValidationFrequency',30,'Verbose',false,'Plots','training-progress');
net = trainNetwork(TrainImages,layers,options); %Network Training
YPred = classify(net,TestImages); %Recognizing digits
YValidation = TestImages.Labels; %Getting Labels
accuracy = sum(YPred == YValidation)/numel(YValidation); %Finding %age accuracy
This is my code and it shows error regarding 7th line fron the bottom.
Answers (1)
I guess, that the line before is the problem:
options =
Remember to append a ... as line continuation.
This is no valid Matlab syntax also:
layers=[
imageInputLayer([28,28,1],'Name','Input')
convolution2dLayer(3,8,'Padding','same','Name','Conv_1')
...
classificationLayer('Name','Output Classification');
];
Append ... here also after the first line and in the empty lines. Relying on the implicit insertion of semicolons is fragile. Compare
a = [5
6
7];
with the bulletproof
a = [5; ...
6; ...
7];
Categories
Find more on Text Detection and Recognition in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!