Skip to content

Commit a19f06f

Browse files
authored
Merge pull request #3072 from madeline-underwood/py
Enhance documentation for PyTorch digit classification project with d…
2 parents 9edeb4b + c29cb77 commit a19f06f

8 files changed

Lines changed: 14 additions & 12 deletions

File tree

content/learning-paths/cross-platform/pytorch-digit-classification-arch-training/_index.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ title: Create and train a PyTorch model for digit classification using the MNIST
33

44
minutes_to_complete: 160
55

6+
description: Learn how to create and train a PyTorch neural network for MNIST digit classification, optimize it with quantization and fusing, and deploy it in an Android application with performance measurement.
7+
68
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.
79

810
learning_objectives:

content/learning-paths/cross-platform/pytorch-digit-classification-arch-training/app.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@ To run the app in Android Studio using an emulator, follow these steps:
3030

3131
Once the application starts, click the **Load Image** button. It loads a randomly-selected image. Then, click **Run Inference** to recognize the digit. The application displays the predicted label and the inference time as shown below:
3232

33-
![img alt-text#center](figures/05.png "Figure 7. Digit Recognition 1")
33+
![Screenshot of Android application showing a handwritten digit image with the Load Image and Run Inference buttons, displaying the model's prediction and inference time in milliseconds below the digit#center](figures/05.png "Digit recognition result showing prediction")
3434

35-
![img alt-text#center](figures/06.png "Figure 8. Digit Recognition 2")
35+
![Screenshot of Android application displaying a different handwritten digit with the inference result, showing how the model correctly identifies the digit and reports the inference time for performance evaluation#center](figures/06.png "Another digit recognition example with timing")
3636

3737
In the next step of this Learning Path, you will learn how to further optimize the model.

content/learning-paths/cross-platform/pytorch-digit-classification-arch-training/datasets-and-training.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ Make sure to replace 'x' with the version number of Python that you have install
7272

7373
After running the code, you will see output similar to Figure 5:
7474

75-
![image alt-text#center](figures/01.webp "Figure 5. Output")
75+
![Screenshot of Jupyter Notebook output showing the MNIST dataset loading confirmation, displaying the number of training and test samples loaded along with the dataset structure information#center](figures/01.webp "MNIST dataset loading output")
7676

7777
## Train the Model
7878

@@ -134,7 +134,7 @@ for t in range(epochs):
134134

135135
After running the code, you see the following output showing the training progress, as displayed in Figure 2.
136136

137-
![image alt-text#center](figures/02.webp "Figure 2. Output 2")
137+
![Screenshot of Jupyter Notebook showing training progress output with epoch numbers, loss values, and test accuracy metrics updating as the model trains on the MNIST dataset#center](figures/02.webp "Model training progress output")
138138

139139
Once the training is complete, you see output similar to:
140140

content/learning-paths/cross-platform/pytorch-digit-classification-arch-training/inference.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ This code demonstrates how to use a saved PyTorch model for inference and visual
108108

109109
After running the code, you should see results similar to the following figure:
110110

111-
![image](figures/03.webp "Figure 6. Results Displayed")
111+
![Visualization showing a grid of MNIST handwritten digits with the model's predictions displayed above each digit, allowing you to visually verify the model's classification accuracy across multiple test samples#center](figures/03.webp "Model inference results on test digits")
112112

113113
### What have you learned?
114114

content/learning-paths/cross-platform/pytorch-digit-classification-arch-training/intro.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ To ensure everything is set up correctly, follow these next steps:
117117

118118
4. Select the Python kernel you created earlier, `pytorch-env`. To do so, click **Kernels** in the top right-hand corner. Then, click **Jupyter Kernel...**, and you will see the Python kernel as shown below:
119119

120-
![img1 alt-text#center](figures/1.webp "Figure 1: Python kernel.")
120+
![Screenshot of Visual Studio Code showing the Jupyter Kernel selection dialog with the pytorch-env Python kernel listed and highlighted for selection#center](figures/1.webp "Python kernel selection in VS Code")
121121

122122
5. In your Jupyter notebook, run the following code to verify PyTorch is working correctly:
123123

@@ -127,6 +127,6 @@ print(torch.__version__)
127127
```
128128

129129
It will look as follows:
130-
![img2 alt-text#center](figures/2.webp "Figure 2: Jupyter Notebook.")
130+
![Screenshot of Jupyter Notebook in Visual Studio Code showing the executed cell with the torch import statement and version output, confirming PyTorch is installed and working correctly#center](figures/2.webp "Jupyter Notebook with PyTorch version output")
131131

132132
Now you have set up your development environment, you can move on to creating a PyTorch model.

content/learning-paths/cross-platform/pytorch-digit-classification-arch-training/intro2.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ Gradients represent the rate of change of the loss with respect to each of the m
3535

3636
An epoch refers to one complete pass through the entire training dataset. During each epoch, the model sees every data point once and updates its parameters accordingly. Multiple epochs are typically required to train a model effectively because, during each epoch, the model learns and fine-tunes its parameters based on the data it processes. The number of epochs is a hyperparameter that you set before training, and increasing it can improve the model's performance, but too many epochs may lead to overfitting, where the model performs well on training data but poorly on new, unseen data.
3737

38-
Backpropagation is a fundamental algorithm used in training neural networks to optimize their parametersweights and biasesby minimizing the loss function. It works by propagating the error backward through the network, calculating the gradients of the loss function with respect to each parameter, and updating these parameters accordingly.
38+
Backpropagation is a fundamental algorithm used in training neural networks to optimize their parameters, weights and biases, by minimizing the loss function. It works by propagating the error backward through the network, calculating the gradients of the loss function with respect to each parameter, and updating these parameters accordingly.
3939

4040
### Training a model in PyTorch
4141

content/learning-paths/cross-platform/pytorch-digit-classification-arch-training/mobile-app.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -228,9 +228,9 @@ This optimization showcases the benefits of quantization and layer fusion for mo
228228

229229
This would allow the model to take full advantage of the device's computational capabilities, potentially further reducing the inference time.
230230

231-
![fig alt-text#center](figures/07.jpg "Figure 9.")
231+
![Screenshot of Android application running the optimized PyTorch model, showing a handwritten digit with the inference result and significantly improved inference time compared to the non-optimized version#center](figures/07.jpg "Optimized model inference result")
232232

233-
![fig alt-text#center](figures/08.jpg "Figure 10.")
233+
![Screenshot of Android application demonstrating the optimized model's performance on another handwritten digit, displaying the prediction accuracy and reduced inference time achieved through quantization and layer fusion#center](figures/08.jpg "Optimized model performance example")
234234

235235
### What have you learned?
236236

content/learning-paths/cross-platform/pytorch-digit-classification-arch-training/model.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ layout: "learningpathall"
99

1010
You can create and train a feedforward neural network to classify handwritten digits from the MNIST dataset. This dataset contains 70,000 images, comprising 60,000 training images and 10,000 testing images of handwritten numerals (0-9), each with dimensions of 28x28 pixels. Some representative MNIST digits with their corresponding labels are shown in Figure 3:
1111

12-
![img3 alt-text#center](figures/3.png "Figure 3: MNIST Digits and Labels.")
12+
![Grid showing sample handwritten digits from the MNIST dataset, displaying examples of digits 0 through 9 with their corresponding numeric labels underneath each image, demonstrating the variety of handwriting styles the model will need to classify#center](figures/3.png "Sample MNIST digits with labels")
1313

1414
The neural network begins with an input layer containing 28x28 = 784 input nodes, with each node accepting a single pixel from a MNIST image.
1515

@@ -94,7 +94,7 @@ summary(model, (1, 28, 28))
9494

9595
After running the notebook, you will see the output as shown in Figure 4:
9696

97-
![img4 alt-text#center](figures/4.webp "Figure 4: Notebook Output.")
97+
![Screenshot of Jupyter Notebook output showing the PyTorch model summary with layer-by-layer details including the input shape, output shape, and number of parameters for each layer in the neural network architecture#center](figures/4.webp "Model architecture summary output")
9898

9999
You will see a detailed summary of the NeuralNetwork model's architecture, including the following information:
100100

0 commit comments

Comments
 (0)