Why CNN gives wrong accuracy

조회 수: 2 (최근 30일)
Tehmina Kakar
Tehmina Kakar 2018년 7월 5일
댓글: Tehmina Kakar 2019년 3월 29일
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
shefali saxena
shefali saxena 2019년 3월 29일
Have you figured it out??
I need your help!!!!!!
email id: shefali.saxena.ece17@nituk.ac.in
Tehmina Kakar
Tehmina Kakar 2019년 3월 29일
No i didn't figured that out... I used WEKA for my project at that time....

댓글을 달려면 로그인하십시오.

답변 (1개)

BAVITHRA DEVI KALIAPPAN
BAVITHRA DEVI KALIAPPAN 2018년 8월 9일
In testing accuracy=0 how to clear this error

태그

Community Treasure Hunt

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

Start Hunting!

Translated by