Why CNN gives wrong accuracy

2 visualizaciones (últimos 30 días)
Tehmina Kakar
Tehmina Kakar el 5 de Jul. de 2018
Comentada: Tehmina Kakar el 29 de Mzo. de 2019
I'm working on my project (Pashto OCR). I've done some search and get the example(demo). I've change that example by just changing the name and the training & testing set according to my project. Now i'm confused when I put all the pics in one folder and then run the CNN it gives me 100% accuracy. But when I put different alphabets in different folder it gives me 32% accuracy. Why is it? What have i missed? Can any one help me, please?
%%Train a Convolutional Neural Network Using Data in ImageDatastore
close all; clear variables; clc;
dbstop if error
Load the data as an ImageDatastore object.
digitDatasetPath =
fullfile(matlabroot,'toolbox','nnet','nndemos',...
'nndatasets','alphabets');
digitData = imageDatastore(digitDatasetPath,...
'IncludeSubfolders',true,'LabelSource','foldernames');
% The data store contains 10000 synthetic images of digits 0-9. The images
% are generated by applying random transformations to digit images created
% using different fonts. Each digit image is 28-by-28 pixels.
% Display some of the images in the datastore.
figure;
perm = randperm(1000,10);
for i = 1:10
subplot(2,5,i);
imshow(digitData.Files{perm(i)});
end
%% % Check the number of images in each digit category. digitData.countEachLabel
% The data contains an equal number of images per category.
Divide the data set so that each category in the training set has 750 images and the testing set has the remaining images from each label.
trainingNumFiles = 150;
rng(1) % For reproducibility
[trainAlphabetData,testAlphabetData] = splitEachLabel(digitData,...
trainingNumFiles,'randomize');
% |splitEachLabel| splits the image files in |digitData| into two new datastores,
% |trainDigitData| and |testDigitData|.
numClasses = numel(categories(trainAlphabetData.Labels))
Define the convolutional neural network architecture.
layers = [imageInputLayer([28 28 1]);
convolution2dLayer(2,10);
reluLayer();
maxPooling2dLayer(2,'Stride',2);
fullyConnectedLayer(numClasses);
softmaxLayer();
classificationLayer()];
% Set the options to default settings for the stochastic gradient descent
% with momentum. Set the maximum number of epochs at 20, and start
the
% training with an initial learning rate of 0.001.
options = trainingOptions('sgdm','MaxEpochs',20,...
'InitialLearnRate',0.0001);
% Train the network.
convnet = trainNetwork(trainAlphabetData,layers,options);
% Run the trained network on the test set that was not used to train the
% network and predict the image labels (digits).
YTest = classify(convnet,testAlphabetData);
TTest = testAlphabetData.Labels;
% Calculate the accuracy.
accuracy = sum(YTest == TTest)/numel(TTest)
  2 comentarios
shefali saxena
shefali saxena el 29 de Mzo. de 2019
Have you figured it out??
I need your help!!!!!!
email id: shefali.saxena.ece17@nituk.ac.in
Tehmina Kakar
Tehmina Kakar el 29 de Mzo. de 2019
No i didn't figured that out... I used WEKA for my project at that time....

Iniciar sesión para comentar.

Respuestas (1)

BAVITHRA DEVI KALIAPPAN
BAVITHRA DEVI KALIAPPAN el 9 de Ag. de 2018
In testing accuracy=0 how to clear this error

Etiquetas

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by