🔢 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 Width = 10 pixels
Total Pixels = 16 × 10
Total Pixels = 160
Therefore, the ANN receives 160 input values. Each pixel is represented by a number.
White pixel = 0
Thus, the image becomes a vector:
2. ANN Architecture for Digit Recognition
Pixel Image
Input Neurons
Layer
Neurons
0–9
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.
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.
Digit 0 → 0.92
Digit 1 → 0.03
Digit 2 → 0.01
...
Digit 9 → 0.02
1 Input
x₁, x₂, ..., x₁₆₀
2 Weighted Sum
3 Activation
a₀ = 0.92
🟢 Digit 1
Digit 1 normally contains a vertical stroke. The ANN learns the location and shape of this stroke.
Digit 0 → 0.02
Digit 1 → 0.95
Digit 2 → 0.01
Digit 3 → 0.01
...
Digit 9 → 0.01
1 Weighted Sum
2 Activation
a₁ = 0.95
🟠 Digit 2
Digit 2 contains a curved top, diagonal section and lower horizontal stroke.
Digit 0 → 0.02
Digit 1 → 0.03
Digit 2 → 0.94
Digit 3 → 0.01
...
Digit 9 → 0.01
1 Weighted Sum
i = 1 to 160
2 Activation
a₂ = 0.94
🔴 Digit 3
Digit 3 contains two curved sections, one above another.
Digit 0 → 0.01
Digit 1 → 0.01
Digit 2 → 0.02
Digit 3 → 0.96
Digit 4 → 0.00
...
1 Weighted Sum
2 Activation
a₃ = 0.96
🟣 Digit 4
Digit 4 generally contains vertical and diagonal strokes forming a recognizable cross-like structure.
Digit 0 → 0.01
Digit 1 → 0.02
Digit 2 → 0.01
Digit 3 → 0.01
Digit 4 → 0.95
...
1 Weighted Sum
i = 1...160
2 Activation
a₄ = 0.95
🟤 Digit 5
Digit 5 usually contains an upper horizontal stroke, a vertical section and a curved lower portion.
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
i = 1...160
2 Activation
a₅ = 0.94
🟢 Digit 6
Digit 6 contains a curved loop in the lower part and an upper stroke that connects into the loop.
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
i = 1...160
2 Activation
a₆ = 0.96
🔵 Digit 7
Digit 7 commonly contains a horizontal top stroke followed by a diagonal stroke.
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
i = 1...160
2 Activation
a₇ = 0.97
🟠 Digit 8
Digit 8 contains two connected loops, one above the other.
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
i = 1...160
2 Activation
a₈ = 0.96
🔴 Digit 9
Digit 9 normally contains an upper loop followed by a descending stroke.
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
i = 1...160
2 Activation
a₉ = 0.95
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 |
argmax(Outputs) = N₈
Therefore:
Predicted Digit = 8
6. Complete Mathematical Flow
↓
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₉)
No comments:
Post a Comment