Total Pageviews

Monday, August 31, 2026

🔢 ANN Handwritten Digit Recognition Example: Recognizing handwritten digits 0–9 using a 16 × 10 pixel image.

🔢 ANN Handwritten Digit Recognition

Example: Recognizing handwritten digits 0–9 using a 16 × 10 pixel image.

1. What Are We Trying to Do?

Suppose a handwritten digit is converted into a small image. For this demonstration, the image contains:

Image Height = 16 pixels
Image Width = 10 pixels

Total Pixels = 16 × 10
Total Pixels = 160

Therefore, the ANN receives 160 input values. Each pixel is represented by a number.

Black pixel = 1
White pixel = 0

Thus, the image becomes a vector:

160 pixels ↓ x₁, x₂, x₃, ... , x₁₆₀

2. ANN Architecture for Digit Recognition

16 × 10
Pixel Image
160
Input Neurons
Hidden
Layer
10 Output
Neurons
Digit
0–9
Input Layer = 160 neurons
Hidden Layer = Example: 32 neurons
Output Layer = 10 neurons

Output neurons:
N₀ → Digit 0
N₁ → Digit 1
N₂ → Digit 2
...
N₉ → Digit 9

3. Understanding the 16 × 10 Pixel Image

The following grid contains 16 rows × 10 columns. A dark cell represents a pixel containing 1. A white cell represents a pixel containing 0.

16 rows × 10 columns = 160 pixels
Example of first few pixels:

x₁ = 1
x₂ = 0
x₃ = 0
x₄ = 1
...
x₁₆₀ = 0

4. Select a Digit to See the ANN Example

🔵 Digit 0

The digit 0 generally has a closed loop. The ANN learns this pattern from the 160 pixels.

Example output scores:

Digit 0 → 0.92
Digit 1 → 0.03
Digit 2 → 0.01
...
Digit 9 → 0.02

1 Input

160 pixel values
x₁, x₂, ..., x₁₆₀

2 Weighted Sum

z₀ = w₀₁x₁ + w₀₂x₂ + ... + w₀₁₆₀x₁₆₀ + b₀

3 Activation

a₀ = Activation(z₀)

a₀ = 0.92
Predicted Digit = 0

🟢 Digit 1

Digit 1 normally contains a vertical stroke. The ANN learns the location and shape of this stroke.

Example output:

Digit 0 → 0.02
Digit 1 → 0.95
Digit 2 → 0.01
Digit 3 → 0.01
...
Digit 9 → 0.01

1 Weighted Sum

z₁ = w₁₁x₁ + w₁₂x₂ + ... + w₁₁₆₀x₁₆₀ + b₁

2 Activation

a₁ = Activation(z₁)
a₁ = 0.95
Predicted Digit = 1

🟠 Digit 2

Digit 2 contains a curved top, diagonal section and lower horizontal stroke.

Example output:

Digit 0 → 0.02
Digit 1 → 0.03
Digit 2 → 0.94
Digit 3 → 0.01
...
Digit 9 → 0.01

1 Weighted Sum

z₂ = Σ(w₂ᵢxᵢ) + b₂

i = 1 to 160

2 Activation

a₂ = Activation(z₂)
a₂ = 0.94
Predicted Digit = 2

🔴 Digit 3

Digit 3 contains two curved sections, one above another.

Example output:

Digit 0 → 0.01
Digit 1 → 0.01
Digit 2 → 0.02
Digit 3 → 0.96
Digit 4 → 0.00
...

1 Weighted Sum

z₃ = w₃₁x₁ + w₃₂x₂ + ... + w₃₁₆₀x₁₆₀ + b₃

2 Activation

a₃ = Activation(z₃)
a₃ = 0.96
Predicted Digit = 3

🟣 Digit 4

Digit 4 generally contains vertical and diagonal strokes forming a recognizable cross-like structure.

Example output:

Digit 0 → 0.01
Digit 1 → 0.02
Digit 2 → 0.01
Digit 3 → 0.01
Digit 4 → 0.95
...

1 Weighted Sum

z₄ = Σ(w₄ᵢxᵢ) + b₄
i = 1...160

2 Activation

a₄ = Activation(z₄)
a₄ = 0.95
Predicted Digit = 4

🟤 Digit 5

Digit 5 usually contains an upper horizontal stroke, a vertical section and a curved lower portion.

Example output:

Digit 0 → 0.01
Digit 1 → 0.01
Digit 2 → 0.02
Digit 3 → 0.01
Digit 4 → 0.01
Digit 5 → 0.94
...

1 Weighted Sum

z₅ = Σ(w₅ᵢxᵢ) + b₅
i = 1...160

2 Activation

a₅ = Activation(z₅)
a₅ = 0.94
Predicted Digit = 5

🟢 Digit 6

Digit 6 contains a curved loop in the lower part and an upper stroke that connects into the loop.

Example output:

Digit 0 → 0.03
Digit 1 → 0.01
Digit 2 → 0.01
Digit 3 → 0.02
Digit 4 → 0.01
Digit 5 → 0.01
Digit 6 → 0.96
...

1 Weighted Sum

z₆ = Σ(w₆ᵢxᵢ) + b₆
i = 1...160

2 Activation

a₆ = Activation(z₆)
a₆ = 0.96
Predicted Digit = 6

🔵 Digit 7

Digit 7 commonly contains a horizontal top stroke followed by a diagonal stroke.

Example output:

Digit 0 → 0.01
Digit 1 → 0.01
Digit 2 → 0.01
Digit 3 → 0.01
Digit 4 → 0.01
Digit 5 → 0.01
Digit 6 → 0.01
Digit 7 → 0.97
...

1 Weighted Sum

z₇ = Σ(w₇ᵢxᵢ) + b₇
i = 1...160

2 Activation

a₇ = Activation(z₇)
a₇ = 0.97
Predicted Digit = 7

🟠 Digit 8

Digit 8 contains two connected loops, one above the other.

Example output:

Digit 0 → 0.02
Digit 1 → 0.01
Digit 2 → 0.01
Digit 3 → 0.02
Digit 4 → 0.01
Digit 5 → 0.01
Digit 6 → 0.02
Digit 7 → 0.01
Digit 8 → 0.96
Digit 9 → 0.02

1 Weighted Sum

z₈ = Σ(w₈ᵢxᵢ) + b₈
i = 1...160

2 Activation

a₈ = Activation(z₈)
a₈ = 0.96
Predicted Digit = 8

🔴 Digit 9

Digit 9 normally contains an upper loop followed by a descending stroke.

Example output:

Digit 0 → 0.02
Digit 1 → 0.01
Digit 2 → 0.01
Digit 3 → 0.01
Digit 4 → 0.01
Digit 5 → 0.01
Digit 6 → 0.02
Digit 7 → 0.01
Digit 8 → 0.02
Digit 9 → 0.95

1 Weighted Sum

z₉ = Σ(w₉ᵢxᵢ) + b₉
i = 1...160

2 Activation

a₉ = Activation(z₉)
a₉ = 0.95
Predicted Digit = 9

5. Final ANN Output Layer

The ANN has 10 output neurons, one for each digit. The neuron with the highest activation is selected.

Output Neuron Represents Example Activation
N₀ Digit 0 0.02
N₁ Digit 1 0.01
N₂ Digit 2 0.03
N₃ Digit 3 0.01
N₄ Digit 4 0.02
N₅ Digit 5 0.01
N₆ Digit 6 0.02
N₇ Digit 7 0.01
N₈ Digit 8 0.96
N₉ Digit 9 0.01
Maximum Activation = 0.96

argmax(Outputs) = N₈

Therefore:
Predicted Digit = 8
🔢 FINAL PREDICTION = DIGIT 8

6. Complete Mathematical Flow

Step 1: 16 × 10 Image



Step 2: 16 × 10 = 160 Pixels



Step 3: Convert pixels into numbers
0 = White
1 = Black



Step 4: Input Vector
X = [x₁,x₂,x₃,...,x₁₆₀]



Step 5: Hidden Layer
z = WX + b



Step 6: Activation Function
a = Activation(z)



Step 7: 10 Output Neurons
N₀,N₁,N₂,...,N₉



Step 8: Choose Maximum Activation
Prediction = argmax(N₀...N₉)

7. Important ANN Terms

Pixel 16 × 10 Image 160 Inputs Input Layer Hidden Layer Output Layer Weight Bias Weighted Sum Activation Neuron Classification Digit Recognition Prediction argmax

No comments:

Post a Comment