Great Deal! Get Instant $10 FREE in Account on First Order + 10% Cashback on Every Order Order Now

digit recognition on MATLABDesign a fully convolutional neural network for digit classifi cation and train it on the MNIST dataset. MNIST provides images of the digits 0 to 9 of size 28  28, together...

1 answer below »
digit recognition on MATLABDesign a fully convolutional neural network for digit classifi cation and train it on the MNIST dataset. MNIST provides images of the digits 0 to 9 of size 28  28, together with the label for which digit is shown in a given image. Your fully convolutional neutral should be trained to produce the correct label for the center of the output of your last layer. MNIST provides training and validation data that you should use for training your neural network. Try out different architectures until you achieve at least 97% accuracy on the test set. Since MNIST is a relatively easy dataset, a few layers should be sufficient for this.Once you have trained your network, you can apply it on one of the evaluation images provided. Use non-maximum suppression and thresholding to obtain your digit predictions and write out the detected digits (no particular order required) on MATLAB's output line. Note that you will need to detect digits at multiple scales.
Answered Same Day Apr 22, 2021

Solution

Kshitij answered on May 01 2021
159 Votes
DIGIT/checkToolboxes.m
function ret = checkToolboxes(req)
% reqToolboxes = {'Neural Network Toolbox'};
% checkToolboxes(reqToolboxes)
info = ver;
s=size(info);
flg = zeros(size(req));
eqSize = size(req,2);
for i=1:s(2)
for j=1:reqSize
if( strcmpi(info(1,i).Name,req{1,j}) )
flg(1,j)=1;
end
end
end
et = prod(flg);
DIGIT/computer_generated.png
DIGIT/computer_generated_rotated.png
DIGIT/datasets/load_dataset.m
function [XTrain, YTrain, XTest, YTest] = load_dataset( name, dir )
if( ~exist( 'dir', 'var' ) )
dir = [fileparts(mfilename('fullpath')),'/'];
end
if( dir(end) ~= '/' )
dir = [dir, '/'];
end
if( strcmpi( name, 'mnist' ) )
[XTrain, YTrain, XTest, YTest] = load_mnist( dir );
elseif( strcmpi( name, 'cifar10' ) )
[XTrain, YTrain, XTest, YTest] = load_cifar10( dir );
else
msg = sptrinf( 'Could not find: %s', name );
e
or(msg);
end
end
DIGIT/datasets/load_mnist.m
function [XTrain, YTrain, XTest, YTest] = load_mnist( dir )
url = 'http:
yann.lecun.com/exd
mnist/';
datasetfile = 'mnist.mat';
if( ~exist( 'dir', 'var' ) )
dir = [fileparts(mfilename('fullpath')),'/'];
end
if( dir(end) ~= '/' )
dir = [dir, '/'];
end
if( isfile( [dir, datasetfile] ) )
load( [dir, datasetfile] );
else
fprintf( 'Downloading mnist dataset. It may takes several minitus.\n' );
filename = 'train-images-idx3-ubyte';
websave([dir,filename,'.gz'], [url,filename, '.gz']);
gunzip([dir,filename, '.gz']);
XTrain = readMnistX([dir,filename]);
filename = [ dir, filename, '*' ];
delete(filename);

filename = 'train-labels-idx1-ubyte';
websave([dir,filename,'.gz'], [url,filename, '.gz']);
gunzip([dir,filename, '.gz']);
YTrain = readMnistY([dir,filename]);
filename = [ dir, filename, '*' ];
delete(filename);

filename = 't10k-images-idx3-ubyte';
websave([dir,filename,'.gz'], [url,filename, '.gz']);
gunzip([dir,filename, '.gz']);
XTest = readMnistX([dir,filename]);
filename = [ dir, filename, '*' ];
delete(filename);
filename = 't10k-labels-idx1-ubyte';
websave([dir,filename,'.gz'], [url,filename, '.gz']);
gunzip([dir,filename, '.gz']);
YTest = readMnistY([dir,filename]);
filename = [ dir, filename, '*' ];
delete(filename);

save([dir,datasetfile], 'XTrain', 'YTrain', 'XTest', 'YTest');
end

XTrain = double(XTrain) / 255.0;
YTrain = categorical(YTrain);
XTest = double(XTest) / 255.0;
YTest = categorical(YTest);
end
function X = readMnistX( filename )
fid = fopen(filename, 'r', 'b');
header = fread(fid, 1, 'int32');
if header ~= 2051
e
or('Invalid image file header');
end
count = fread(fid, 1, 'int32');
h = fread(fid, 1, 'int32');
w = fread(fid, 1, 'int32');

X = fread(fid, h*w*count, 'uint8');
X = reshape( X, [h,w,1,count] );
X = permute( X, [2,1,3,4] );

X = uint8(X);
fclose(fid);
end
function Y = readMnistY( filename )
fid = fopen(filename, 'r', 'b');
header = fread(fid, 1, 'int32');
if header ~= 2049
e
or('Invalid image file header');
end
count = fread(fid, 1, 'int32');

Y = fread(fid, count, 'uint8');
Y = reshape( Y, [count,1] );
Y = uint8(Y);

fclose(fid);
end
DIGIT/datasets/load_train1000.m
function [XTrain, YTrain, XTest, YTest] = load_train1000( name, dir )
if( ~exist( 'dir', 'var' ) )
dir = [fileparts(mfilename('fullpath')),'/'];
end
if( dir(end) ~= '/' )
dir = [dir, '/'];
end
if( strcmpi( name, 'mnist' ) )
[XTrain0, YTrain0, XTest, YTest] = load_mnist( dir );
[XTrain, YTrain] = extract(XTrain0, YTrain0, 10, 100);
elseif( strcmpi( name, 'cifar10' ) )
[XTrain0, YTrain0, XTest, YTest] = load_cifar10( dir );
[XTrain, YTrain] = extract(XTrain0, YTrain0, 10, 100);

else
msg = sptrinf( 'Could not find: %s', name );
e
or(msg);
end
end
function [X, Y] = extract(X0, Y0, nb_classes, nb_per_class)
s = size(X0);
X = X0(:,:,:,1:nb_classes*nb_per_class);
Y = Y0(1:nb_classes*nb_per_class,:);

k = 1;
n = zeros(nb_classes,1);
for i=1:size(X0,1)
c = int32(Y0(i,1));
if( n(c) < nb_classes )
X(:,:,:,k) = X0(:,:,:,i);
Y(k,:) = Y0(i,:);
n(c) = n(c) + 1;
k = k + 1;
if( k > nb_classes*nb_per_class )

eak;
end
end
end
end
DIGIT/datasets/mnist.mat
XTrain:[4D uint8 a
ay]
YTrain:[60000x1 uint8 a
ay]
XTest:[4D uint8 a
ay]
YTest:[10000x1 uint8 a
ay]
DIGIT/Digit classification.docx
Digit classification and recognition using convolution neural network using MNISt dataset , We have trained the data using CNN with manipulation of training options to get desired training option. NOn-maximum suppression and thresholding is implementation to obtain digit predictions, MNIST dataset of 60,000 small square 28×28 pixel grayscale images of handwritten single digits between 0 and 9.
Method:-
Convolution neural network could considered as gradable NN which generally works in extraction of features of images by choosing options of convolving input with the help gaggle of kernel filters. After that the process of pooling of obtained feature is executed and filter resolution of next layer following, Now implementing convolution neural network algorithm.
Above given condition tells us about the lth...
SOLUTION.PDF

Answer To This Question Is Available To Download

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here