DEV Community

Diyorbek Umaraliyev
Diyorbek Umaraliyev

Posted on

Building and Deploying an MNIST Digit Recognition App with PyTorch and Streamlit

Handwritten digit recognition is a classic machine learning problem, and in this tutorial, I will talk about how I built a simple yet powerful app to solve it. Using PyTorch for the model and Streamlit for the interface, I have created an app that can recognize handwritten digits in real-time.


What I have done:

  1. Setting Up: Installed the necessary libraries.
  2. Building the Model: Designed a Convolutional Neural Network (CNN).
  3. Training: Trained the model on the MNIST dataset.
  4. Creating the App: Built a user-friendly interface with Streamlit.
  5. Deploying: Hosted the app on Streamlit Cloud.

Why This Project?

Learn by Doing: A hands-on way to understand CNNs and deployment.
Showcase Your Skills: Perfect for your portfolio or resume.
Real-World Application: Demonstrates how machine learning can solve practical problems.


Step 1: Setting Up

I have used PyTorch for the model, Streamlit for the app, and a few other libraries for data processing, installed them with a simple pip install command.


Step 2: Building the Model

My CNN model is straightforward yet effective. It has two convolutional layers for feature extraction and fully connected layers for classification.


Step 3: Training the Model

I have trained the model on the MNIST dataset, which contains 60,000 handwritten digits. After just 10 epochs, the model achieved an impressive 98% accuracy on the test set.


Step 4: Creating the App

Using Streamlit, I have built a clean and intuitive interface. Users can upload an image of a handwritten digit, and the app will display the predicted digit along with the model’s confidence.


Step 5: Deploying the App

Finally, I have deployed the app to Streamlit Cloud, making it accessible to anyone with an internet link. Deployment is quick and hassle-free—perfect for sharing the work with the world.


Conclusion

This project is a fantastic way to dive into machine learning and app development. Whether you’re a beginner or an experienced developer, you’ll learn something new and have fun along the way.


You can find the complete code on GitHub. Feel free to fork the repository, experiment, and share your results!

If you have any questions or feedback, leave a comment below.

API Trace View

How I Cut 22.3 Seconds Off an API Call with Sentry 🕒

Struggling with slow API calls? Dan Mindru walks through how he used Sentry's new Trace View feature to shave off 22.3 seconds from an API call.

Get a practical walkthrough of how to identify bottlenecks, split tasks into multiple parallel tasks, identify slow AI model calls, and more.

Read more →

Top comments (0)

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay