Develop a neural network that can correctly classify images of handwritten digits. Training using the MNIST dataset.
Clone the repo:
git clone https://github.com/jacar-javi/handigit-ai.git
To launch application run:
pip install -r requirements.txt
python handigit-ai.py
We will use a Keras library based secuential Artificial Neural Network with 3 layers:
- Flattening Layer: Converts 28x28 pixel 2D images to a 784 element 1D vector.
- Dense Hidden Layer: With 128 neurons and ReLU (Rectified Linear Unit) activation function. This layer is responsible for learning the relevant features of the images for digit classification.
- Dense Output Layer: With 10 neurons and Softmax activation function. This layer generates the probabilities that the input image belongs to each of the 10 possible classes (digits 0 to 9).
The model is compiled by specifying the optimizer (in this case 'adam'), the loss function (in this case 'categorical_crossentropy'), and the evaluation metric (in this case 'accuracy').
Step 2: Train NN with MNIST dataset and evaluate its accuracy.
- Load the MNIST dataset and split it into two subsets: training and testing.
- The pixel values of the images are normalized so that they are in the range of 0 to 1.
- Labels are converted to one-hot encoding so that they can be used in the neural network.
The model is trained using the training dataset (x_train, y_train) and validating it on the test dataset (x_test, y_test). Training is performed for a specified number of epochs (in this case, 10) and with a specified batch_size (in this case, 32).
Model performance during training is visualized using graphs showing accuracy and loss as a function of the number of epochs. These graphs allow you to assess how the model learns over time and detect potential overfitting or underfitting issues.
After model training is complete, the model's performance is evaluated on the test dataset for loss and accuracy.
Trained model saved as trained-model.h5