Create and train a PyTorch model for digit classification using the MNIST dataset
Introduction
Prepare a PyTorch Development Environment
Create a PyTorch model for MNIST
About PyTorch Model Training
Perform Training and Save the Model
Deploy the Model for Inference
Learn about Inference on Android
Create an Android Application
Prepare the Test Data
Run the Application
Optimizing Neural Network Models in PyTorch
Create an optimized PyTorch model for MNIST
Run optimization
Update the Android application
Next Steps
Create and train a PyTorch model for digit classification using the MNIST dataset
Introduction
Prepare a PyTorch Development Environment
Create a PyTorch model for MNIST
About PyTorch Model Training
Perform Training and Save the Model
Deploy the Model for Inference
Learn about Inference on Android
Create an Android Application
Prepare the Test Data
Run the Application
Optimizing Neural Network Models in PyTorch
Create an optimized PyTorch model for MNIST
Run optimization
Update the Android application
Next Steps
Who is this for?
This is an advanced topic for software developers interested in learning how to use PyTorch to create and train a feedforward neural network for digit classification, and also software developers interested in learning how to use and apply optimizations to the trained model in an Android application.
What will you learn?
Upon completion of this Learning Path, you will be able to:
- Prepare a PyTorch development environment.
- Download and prepare the MNIST dataset.
- Create and train a neural network architecture using PyTorch.
- Create an Android app and load the pre-trained model.
- Prepare an input dataset.
- Measure the inference time.
- Optimize a neural network architecture using quantization and fusing.
- Deploy an optimized model in an Android application.
Prerequisites
Before starting, you will need the following:
- A machine that can run Python3, Visual Studio Code, and Android Studio.
- For the OS, you can use Windows, Linux, or macOS.
Summary
This summary was drafted with an approved AI-assisted workflow and reviewed by Arm contributors before publication. Human technical review remains part of the process so the final page reflects engineering rigor, accuracy, and Arm editorial standards.
Frequently asked questions
These FAQs were drafted with an approved AI-assisted workflow and reviewed by Arm contributors before publication. Human technical review remains part of the process so the final page reflects engineering rigor, accuracy, and Arm editorial standards.
DataLoader returns batches. With batch_size set to 32, the first batch contains 32 images of 28x28 pixels and corresponding labels from 0–9.