This is a simple neural network application that allows users to draw digits (0-9) on a 5x5 grid and predict the digit using a trained neural network. The application is built using Python's Tkinter library for the GUI and NumPy for numerical computations.
- Draw digits on a 5x5 canvas.
- Predict the drawn digit using a neural network.
- Train the neural network with user-defined labels for continuous learning.
- Clear the canvas for new drawings.
To run this application, you need to have Python 3 installed along with the following packages:
numpy
tkinter
(usually comes pre-installed with Python)
You can install NumPy using pip if you haven't already:
pip install numpy
-
Run the Application: Execute the script to start the application.
python draw_number.py
-
Drawing: Use the mouse to draw a digit on the canvas. Click and drag to fill in the grid.
-
Label Input: Enter the correct label (0-9) for the drawn digit in the entry box.
-
Training: Click the "Train" button to train the neural network with the drawn digit and its corresponding label.
-
Prediction: Click the "Predict" button to let the neural network predict the drawn digit based on its current training.
-
Clear Canvas: Use the "Clear" button to reset the canvas for a new drawing.
-
NeuralNetwork Class: Implements a basic feedforward neural network with one hidden layer.
- Methods:
forward(x)
: Performs a forward pass and returns the network's output.train(x, y, learning_rate, epochs)
: Trains the network using backpropagation.
- Methods:
-
DrawApp Class: Manages the Tkinter GUI and handles user interactions.
- Methods:
paint(event)
: Handles drawing on the canvas.clear()
: Clears the canvas.predict()
: Predicts the digit using the current neural network weights.train()
: Trains the network with the provided label.
- Methods:
Below are the 5x5 patterns used to train the model. Each row shows the digit, the grid pattern representing it, and the model's expected prediction.
For optimal performance, it's crucial to ensure that data fragmentation is less than 50%. Data fragmentation refers to a situation where the training data does not adequately represent the diversity of input patterns that the model may encounter. When the model is trained on a fragmented dataset, it may learn biases or fail to generalize well, leading to inaccurate predictions.
Data fragmentation can occur in various forms:
-
Underrepresentation of Classes: If certain digits are drawn much less frequently than others in the training set, the model may struggle to accurately recognize those digits.
-
Insufficient Variety in Drawings: If the same patterns of digits are repeated without variation, the model may not learn to recognize different ways the same digit can be represented.
-
Lack of Noise or Distortions: In real-world scenarios, digits might be drawn with variations such as different sizes, rotations, or noise. If the training set lacks such diversity, the model may fail to recognize distorted inputs.
- The neural network is initialized with random weights and requires training to improve its accuracy.
- The training epochs can be adjusted to fine-tune the learning process.
- The model's performance may vary based on the training data and the complexity of the drawings.
This project is licensed under the MIT License. See the LICENSE file for details.
- This project utilizes the NumPy library for efficient numerical calculations.
- Tkinter is used for creating the graphical user interface.
- Save this content in a file named
README.md
in the same directory as your Python script. - Adjust any sections as needed to better fit your project's specifics or any additional features you may want to highlight.