logo
ZODOC
Published on

Classification of handwritten digit with CNN

Authors
  • tesar-tech

Model in onnx format was trained on MNIST dataset with 99.29 % accuracy.

mnist_net = importONNXNetwork('MNIST_99.29.onnx','OutputLayerType','classification','ClassNames',{'0','1','2','3','4','5','6','7','8','9'}); %Import MNIST cnn

A = rgb2gray(imread('single_handwritten_digit.png'));%Load an image and covert to grayscale
A_resized = imresize(A,[28 28]);%Resize to [28x28] to match cnn input layer

[label, score] = classify(mnist_net,A_resized,'ExecutionEnvironment','cpu');
A_withText = insertText(A,[1 1], cellstr("classified as " +  string(label)+newline+ "("+ num2str(max(score)*100,'%0.2f %%)')) ,'FontSize',28); % add text with classifiaction results
imshow(A_withText)