Home > Software engineering >  Matlab handwriting identification code errors, don't know where is wrong?
Matlab handwriting identification code errors, don't know where is wrong?

Time:11-15

Download the code and data sets, only change the path, but while the 22 samples, each folder inside 10 picture,

But

when numTrainFiles=17 ; Each number is % 22 samples, take 17 samples as training data
Error using matlab. IO. Datastore. ImageDatastore/splitEachLabel (line 211)
Percentage value (17) should not exceed the sum has the least number of files (10) in the tag file number,
Please use COUNTEACHLABEL and MIN for the number of file (s) associated with the tag,

Error newff0312 (line 15)

[imdsTrain, imdsValidation]=splitEachLabel (imds, numTrainFiles, 'randomize')

modify numTrainFiles=9,
Error using trainNetwork (line 170)
Invalid training data, the output of the last layer size (10) and the number of classes (22) do not match,
Error newff0312 (line 55)
Net=trainNetwork (imdsTrain, the layers, the options). % training data, design of neurons, training parameter

modify digitDatasetPath=fullfile (' D: \ \ 201910 CT \ ', '/train1/');
Read this path is DCM figure, but there is an error

Error using imageDatastore (line 125)
Input folder or file contains non-standard file extensions,

Use FileExtensions name and value to the group to include non-standard file extensions,

Error newff0315 (line 7)
Imds=imageDatastore (digitDatasetPath,...



% % import dataDigitDatasetPath=fullfile (' D: \ \ 201910 CT \ ', '/hwDataset/');
Imds=imageDatastore (digitDatasetPath,...
'IncludeSubfolders' true' LabelSource ', 'foldernames'); % the folder name as a data tag
%, 'ReadFcn' @ mineRF

% data set picture number
CountEachLabel (imds)

NumTrainFiles=9; Each number is % 22 samples, take 17 samples as training data
[imdsTrain, imdsValidation]=splitEachLabel (imds, numTrainFiles, "randomize");
The size of the % review images
Img=readimage (imds, 1);
The size (img)

Convolution of the neural network structure defined % %
The layers=[
% input layer
ImageInputLayer (28 28 [1]) % input image size for 28 * 28, grayscale image channel 1
% convolution layer (feature map size calculation of 32-5 + 1=28)
Convolution2dLayer (5, 6, 'Padding', 2) % convolution kernels 5 * 5, 6 kinds of feature extracting mapping,
BatchNormalizationLayer % padding around the image after zero padding to keep or the convolution feature mapping 28 * 28, 28-5 + 4 + 1
ReluLayer

MaxPooling2dLayer (2, 'stride, 2) % under sampling nuclear 2 * 2

Convolution2dLayer (5, 16)
BatchNormalizationLayer
ReluLayer

MaxPooling2dLayer (2, 2 'stride')

Convolution2dLayer (5, 120)
BatchNormalizationLayer
ReluLayer

% final layerFullyConnectedLayer (10)
SoftmaxLayer
ClassificationLayer];


% % training neural network
% set training parametersThe options=trainingOptions (SGDM,...
% optimization method'maxEpochs, 50,... % repetitions
'ValidationData, imdsValidation,... % of validation data
'ValidationFrequency', 5,...
% validation frequency'Verbose, false,... Whether to display the intermediate results %
'Plots',' training - progress '); % according to training schedule

% training neural networks, save the web
Net=trainNetwork (imdsTrain, the layers, the options). % training data, design of neurons, training parameter
The save 'CSNet. Mat' net

% % tag data (file name way, constructs)
MineSet=imageDatastore (' D: \ \ 201910 CT \ hwDataset \ hw9 \ ', 'FileExtensions',' JPG ',...
'IncludeSubfolders, false); % %, 'ReadFcn' @ mineRF
MLabels=cell (size (mineSet Files, 1), 1);
For I=1: size (mineSet Files, 1)
[filepath, name, ext]=fileparts (char (mineSet. Files {I}));
MLabels {I, 1}=char (name);
End
MLabels2=categorical (mLabels);
MineSet. Labels=mLabels2;


% % use the network to classify and calculate the accuracy
% handwritten data
YPred=the classify (.net, mineSet);
YValidation=mineSet. Labels;
% calculation accuracy
Accuracy=sum (YPred==YValidation)/numel (YValidation);
Prediction of % map
figure;
NSample=10;
Ind=randperm (size (YPred, 1), nSample);
For I=1: nSample

Subplot (2, fix ((nSample + 1)/2), I)
Imshow (char (mineSet Files (ind (I))))
The title ([' prediction: 'char (YPred (ind (I)))))
If char (YPred (ind) (I))==char (YValidation (ind (I)))
Xlabel ([' real: 'char (YValidation (ind (I)))))
The else
Xlabel ([' real: 'char (YValidation (ind (I)))],' color ', 'r')
End

End

% telescopic + color
% function data=https://bbs.csdn.net/topics/mineRF (filename)
% img=imread (filename);
% data=https://bbs.csdn.net/topics/uint8 (255 - rgb2gray (imresize (img, [28] 28)));
%
% end

% binarization
% function data=https://bbs.csdn.net/topics/mineRF (filename)
% img=imread (filename);
% data=https://bbs.csdn.net/topics/imbinarize (img);
%
% end

get the wrong results
Ans=

22 x 2 table

Label the Count
_____ _____

Hw1 10
The hw10 10
Hw11 10
Hw12 10
Hw13 10
Hw14 10
Hw15 10
Hw16 10
Hw17 10
Hw18 10
Hw19 10
Hw2 10
Hw20 10
Hw21 10
Hw23 10
Hw3 10
Hw4 10
Hw5 10
Hw6 10
Hw7 10
Hw8 10
Hw9 10


Ans=

28 28

Error using trainNetwork (line 170)
Invalid training data, the output of the last layer size (10) and the number of classes (22) do not match,

Error newff0312 (line 55)
Net=trainNetwork (imdsTrain, the layers, the options). % training data, design of neurons, training parameter

>
  • Related