Train a PyTorch MNIST digit classifier on Arm
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
Train a PyTorch MNIST digit classifier on Arm
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
Review 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.
Confirm that the training and test splits download without errors and that the
DataLoader returns batches. With batch_size set to 32, the first batch contains 32 images of 28x28 pixels and corresponding labels from 0–9.Monitor the loss and confirm that it decreases over epochs. Evaluate on the test data periodically to check whether predictions align with the true labels more often.
Use the model file produced during training and provide its path when loading. Recreate the same model architecture before loading the saved parameters.
Apply the training preprocessing, including normalization and tensor conversion, then run a prediction. The output maps to a digit from 0–9. Compare it with a known test-set label.
Measure inference time with the original model, then repeat the measurement after quantization and fusing with identical inputs and conditions. Use the timings to choose the model for the Android application.