An interactive tool for experimenting with MNIST handwriting recognition models using a custom-built 28x28 drawing grid. This application allows users to draw digits and get real-time predictions from a trained MNIST model.
- Interactive 28x28 drawing grid that matches MNIST input dimensions
- Real-time prediction updates as you draw
- Blur effect to simulate natural handwriting
- Clear canvas functionality
- Grid overlay for precise pixel manipulation
- Support for custom MNIST-compatible models
- Allows for custom conversion and output functions to allow for increased compatability with different model types
- Display neuron activation values in Tkinter window given the drawing grid values
- Clone the repository:
git clone https://github.com/LucaLow/MNIST-Interactive-Model-Analyzer.git
cd MNIST-Interactive-Model-Analyzer
Or install through pip:
pip install -i https://test.pypi.org/simple/ mnist-interactive
- Install the required dependencies:
pip install numpy
pip install tensorflow
- Python >= 3.8
- TensorFlow >= 2.0
- NumPy
- Tkinter (usually comes with Python)
- Basic usage with a pre-trained model:
import mnist_interactive.numberCreatorWindow as mi
import tensorflow as tf
import tkinter as tk
from tkinter import ttk
# Load your pre-trained MNIST model
model = tf.keras.models.load_model('sampleModel.keras')
# create the tkinter window
root = tk.Tk()
# Initialize the interactive grid
grid = mi.NumberCreatorWindow(root, model=model, blur=0.3)
root.mainloop()
- Customize the blur effect:
app = NumberCreatorWindow(root, model=model, blur=0.15) # Adjust blur intensity
- Left Click: Draw
- Right Click: Erase
- Clear Button: Reset the canvas
- Real-time predictions displayed above the canvas
numberCreatorWindow.py
: Main application window and drawing logicutils.py
: Utility functions for predictions and grid operationsexample.py
: Example implementationrequirements.txt
: Required Python packagessetup.py
: Package installation configuration
src/mnist_interactive/
├── backends/
│ ├── __init__.py
│ ├── tensorflow_backend.py
│ ├── pytorch_backend.py
│ └── base_backend.py
├── ui/
│ ├── __init__.py
│ ├── number_creator_window.py
│ ├── canvas.py
│ └── visualization.py
├── utils/
│ ├── __init__.py
│ ├── grid.py
│ └── blur.py
└── examples/
├── tensorflow_example.py
└── pytorch_example.py
NumberCreatorWindow(root, model, blur=0.1, conversion_function, output_function)
Parameters:
root
: Tkinter root windowmodel
: TensorFlow model for digit predictionblur
: Blur intensity for drawing (default: 0.1)conversion_function
: Function receiving a 28×28 NumPy array and returning data in the shape/format the model acceptsoutput function
: Function receiving the model’s raw output (e.g. probability array) and returning a tuple of (prediction int, confidence float)
clear_canvas()
: Clear the drawing gridpredict()
: Get prediction for current drawing
Contributions are welcome! Please feel free to submit a Pull Request.
This project is licensed under the MIT License - see the LICENSE file for details.
Luca Lowndes (Luca@Lowndes.net)
- Built using TensorFlow and MNIST dataset
- Inspired by the need for interactive MNIST model testing tools based upon the models you create