I wanted to write and implement a convolutional neural network using PyTorch that would be able to classify handwriting data using a train, valid, test approach. The following shows my exploration and process to implement this successfully. This was a fun exercise, and I got to learn a lot more about convolutional neural networks. I hope you enjoy!
![image](https://private-user-images.githubusercontent.com/65328557/306485605-846a485b-b016-4f25-a276-2158a53ad270.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MjQwMDcxNDYsIm5iZiI6MTcyNDAwNjg0NiwicGF0aCI6Ii82NTMyODU1Ny8zMDY0ODU2MDUtODQ2YTQ4NWItYjAxNi00ZjI1LWEyNzYtMjE1OGE1M2FkMjcwLnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNDA4MTglMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjQwODE4VDE4NDcyNlomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPTFhNDc2ZmIyOTBjODVkOGY0MmM3NWE3ZWFjZjExNGJkZTZhZDBhMjQ2ZDlkN2E5NjE2ZDVhZThkZjMzNzUxZmEmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0JmFjdG9yX2lkPTAma2V5X2lkPTAmcmVwb19pZD0wIn0.vPv7n550kk11x7Bv5WnqTMd2hrBsulxa4rYs_EFP-0k)
Figure 1. Torchvision MNIST Dataset
I used the Torchvision MNIST Dataset for my model (sample seen above). The data consists of grayscale images of handwritten single digit numerical characters in the range 0 through 9. This dataset is from the MNIST (Modified National Institute of Standards and Technology) and is highly coveted as a machine-learning-friendly human handwriting dataset. To learn a little more about the dataset, see more.
I implemented a convolutional neural network with two hidden layers, L2 norm regularization, and a learning rate of 0.001 and got the following results. You can view the deployed model in a Jupyter Notebook here.
I will now present the results of my model:
![image](https://private-user-images.githubusercontent.com/65328557/306492706-3fe49552-a5d9-4e3c-8568-fba6c7b2b482.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MjQwMDcxNDYsIm5iZiI6MTcyNDAwNjg0NiwicGF0aCI6Ii82NTMyODU1Ny8zMDY0OTI3MDYtM2ZlNDk1NTItYTVkOS00ZTNjLTg1NjgtZmJhNmM3YjJiNDgyLnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNDA4MTglMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjQwODE4VDE4NDcyNlomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPWMwMjRmYTAxZDA1OTk1MGJhNmRjMzViOTRlOTRiYTQ3MzQ3Mzg0OGVjMDI3NWNlYjAyMjE3YTNhYjZkMzYzYzcmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0JmFjdG9yX2lkPTAma2V5X2lkPTAmcmVwb19pZD0wIn0.SNJG8NlBw1oo-Xvry4uaidsjVPtC_rO36D7hFZQ9Pe4)
Figure 2. Model Output
![image](https://private-user-images.githubusercontent.com/65328557/306492801-f31378ec-bfdb-4265-a3a8-c64ca58408ca.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MjQwMDcxNDYsIm5iZiI6MTcyNDAwNjg0NiwicGF0aCI6Ii82NTMyODU1Ny8zMDY0OTI4MDEtZjMxMzc4ZWMtYmZkYi00MjY1LWEzYTgtYzY0Y2E1ODQwOGNhLnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNDA4MTglMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjQwODE4VDE4NDcyNlomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPTNmMGI4OGM5NTZiMmE2MDY2ZjlkZWM1N2YzMjc0NTM4Nzg2MzU1NTgxMjEyMGZiYzc0ZWUwN2JhNjliYjMxYjUmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0JmFjdG9yX2lkPTAma2V5X2lkPTAmcmVwb19pZD0wIn0.e6MnZbWnkNOqLL0xYu143HdDXWmyiffUt3zTCT3orqo)
Figure 3. Prediction Accuracy Performance
![image](https://private-user-images.githubusercontent.com/65328557/306492893-718003e8-c5bf-4024-b287-15f1370f2ce9.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MjQwMDcxNDYsIm5iZiI6MTcyNDAwNjg0NiwicGF0aCI6Ii82NTMyODU1Ny8zMDY0OTI4OTMtNzE4MDAzZTgtYzViZi00MDI0LWIyODctMTVmMTM3MGYyY2U5LnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNDA4MTglMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjQwODE4VDE4NDcyNlomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPTM4YjdjZGQ1NWEyNWZhNTg3ZTdlMDJmYjI3MzBjZmFjZjg5OThmOThhNDI5ZGIyNzcwMGE1NzU4ZThjODVmM2EmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0JmFjdG9yX2lkPTAma2V5X2lkPTAmcmVwb19pZD0wIn0.d0h3dMU6ACAl9xbp6-V5aLlASRF01e6BfxJLGQ5pwO0)
Figure 4. Prediction Loss Performance
My model boasted test high accuracy that converged around 98 to 99 percent (Figure 2). This high test accuracy was coupled with low test cross-entropy loss that converged at around 0.025 to 0.035 (Figure 2). My model performed well on the unseen test and valid data, as seen in both accuracy and loss curves (Figures 3, 4), further showing the success of the model.
Seeing that I was able to implement a successful model using numerical data, I would now like to further expand into more complex data such as alphabetical.
Thanks for checking out my project!