Skip to content

mahadhsn/Digit-Recognizer

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 

Repository files navigation

Digit-Recognizer

Project Description

In this project, I decided to utilize the mnist dataset to create a Convolutional Neural Network (CNN) with 8 layers leading to a 99.3% accuracy in recognizing digits ranging from 0-9. For data visualization , I implemented Matplotlib.

As my first ever AI program, I would say it was a success as it gave me a good understanding of how to use Tensorflow, Matplotlib and much more.

Libraries

  • Tensorflow: To create the 8 layered CNN
  • Numpy: Mainly to M manipulate the mnist dataset and make it easy to work with
  • Matplotlib: For data visualization
  • Random: To display random results from our testing set

Code Structure

Since this program was written in Jupyter Notebook , no classes were used. However, the code is divided in an organized manner allowing for ease of use. (Most of the code is also commented making it very easy to understand.)

  • AI : This program uses Tensorflow as its AI library allowing it to create an 8 layered CNN which trains and tests the dataset. The way it does this is surprisingly simple:

    Firstly, we should understand the structure of the MNIST dataset. It is an array of numbers ranging from 0-255 (0 being black and 255 being white) (as seen in the second cell). The first thing we do is divide the MNIST dataset by 255 which is what we call normalizing the data. This transforms all the data into a range of float numbers between 0-1 (e.x. 0.478).

    Once the data is ready for training and testing, we start creating the actual CNN. Going line by line, we have

    • 3 Conv2D layers : Convolutional layers simply use math and filters to make certain parts of an image stand out more than other parts.

    • 2 MaxPooling2D layers : These layers cut down the size of an image allowing the NN to use less compute

    • 1 Flatter layer : This just turns the 2D vector into a 1D

    • 2 Dense layers : This compresses the output resulting in just the 10 numbers we need which are the probabilities for the image being each numebr from 0-9

    Next, we actually compile the model by training it on the dataset using multiple Epochs. (Epochs are the amount of runs the models goes through before completing its training). Once this is done, we get a final accuracy report of the model and we can see how accurate it is based on the 10,000 test images and 60,000 train images.

  • Data Visualization : This part of the program uses Matplotlib's PyPlot to display our results in the form of a bar graph showing the models exact thought process.

    The bar graph is created using the plot_value_array() function and the actual number is displayed using plot_image(). Cell 14 is a very easy way to see any of the model's guesses. Cell 15 displays 9 different guesses at once.

Reflection

This project was a milestone for me as I stepped foot into the actual AI world for the first time. It gave me a very good understanding of how Tensorflow uses statistics and ALOT of math to create an AI that can guess what a number is ranging from 0-9. Fun fact: ChatGPT can't actually think of anything as it basically just guesses what it should say and goes with the best guess. Learn more here: https://youtu.be/-4Oso9-9KTQ?si=-jrjyqMdGsBYsg5N

It also gave me a very good understanding of data visualization and processing. The MNIST dataset has a total of 80,000 images which were not easy to handle as a first timer. Learning about Tensors and CNNs was not easy either but that's what life is all about. Take a challenge, then spend a month learning and mastering it.

Future Plans

I would love to learn SQL next and work on a password manager with python and SQL but I was having trouble finding a reasonable GUI so that's still up for debate. I also really want to create a CNN WITHOUT any form of AI libraries. Just using pure python, numpy, and hopes and dreams. There are many sources online to learn more about these so hopefully that won't be an issue. Lastly, I really want to make a portfolio website for myself. This would require me to advance my JavaScript skills and learn about network and how websites actually work which is a long task but I am hopeful that I will have most of these done within a month or two.

About

Digit Recognizer using TensorFlow

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors