"π¨π€ Doodle-Guesser Game: Draw doodles & let AI guess! Powered by a CNN trained on Google's QuickDraw dataset (1 million+ images and 345 classes), it predicts in real-time and shows the top 5 probabilities with a pie chart π₯§. Built using TensorFlow, Keras, & Streamlit. A fun blend of AI & gaming! π"
Welcome to the Doodle-Guesser Game! This interactive web application allows you to draw a doodle on a canvas, and the AI predicts what you're drawing in real-time. Built using TensorFlow, Keras, and Streamlit, this project merges fun with AI and Machine Learning to bring you an exciting gaming experience. π
- Real-Time Predictions: As you draw, the CNN model predicts your doodle in real-time!
- Top 5 Predictions: View the top 5 possible guesses along with their probabilities.
- Interactive UI: A smooth and engaging user interface created using Streamlit.
- Visualization: A pie chart displays the probabilities of the top 5 classes for easy comparison.
- Frontend: Streamlit for creating the interactive UI.
- Backend: TensorFlow & Keras for the CNN model and training.
- Data Processing: NumPy, Pandas, and OpenCV for image processing and data manipulation.
The model is trained using Google's QuickDraw dataset, which contains millions of doodles across 345 different categories. This dataset helps the CNN model to learn a variety of drawing styles and identify objects in real-time.
- Number of classes: 345
- Number of images: 50 million+
- Image format: PNG (greyscale images)
- Categories: Various categories such as animals, objects, vehicles, and more.
The core of this project is a Convolutional Neural Network (CNN) that is trained to recognize doodles. The model uses multiple layers of convolutional and pooling layers to extract features and classify images into one of 345 classes. The model is trained on the QuickDraw dataset and is optimized for fast, real-time predictions.
Model Architecture:
- Input Layer: 28x28 grayscale images
- Convolutional Layers: Multiple layers with activation functions to extract features.
- Pooling Layers: Max-pooling layers to reduce the spatial dimensions.
- Fully Connected Layer: Final dense layer with 345 neurons corresponding to the number of classes.
- Softmax Activation: To output probabilities for each class.
The CNN model trained on the QuickDraw dataset achieved excellent results:
These results show the model's ability to generalize well, maintaining high accuracy across different data splits. This demonstrates the effectiveness of the architecture and the quality of the dataset used.
The game is deployed using Streamlit, an open-source app framework that allows rapid prototyping of interactive applications. The real-time prediction is displayed as you draw on the canvas. The UI updates live as the CNN model predicts your doodle. The top 5 predictions are shown along with their probabilities in the form of a pie chart.
Here are a few screenshots of the Doodle-Guesser Game:
To run the Doodle-Guesser Game locally, follow these steps:
-
Clone this repository:
git clone https://github.com/yourusername/doodle-guesser-game.git
-
Run the CNN.ipynb: This will create -> train -> download the model in your local system.
-
Run the Streamlit app:
streamlit run app.py
-
Happy doodling! π anytime, anywhere, online or offline.
- Main Program and Main State: Define the main program structure, including the state of the game, user interactions, and transitions between different game phases.
- Substates of Main State: Set up the game states such as initialization, waiting for input, making predictions, and displaying results.
- Game Loop: Build the game loop where the primary logic of the game (drawing, predictions, etc.) is handled.
- User Interface Class: Design a class for managing the user interface that allows interaction with the game, including drawing on the canvas and displaying predictions.
- CNN Class: Create a CNN class to handle the loading and training of the model.
- Loading Datasets: Import three small datasets (car, fish, and snowman) to test and train the CNN model.
- Splitting and Shuffling Data: Split the datasets into training and test data. Shuffle the data to ensure randomness during training.
- CNN Architecture: Construct a sequential CNN model with multiple convolutional and pooling layers.
- Model Layers: Add different layers (convolutional, pooling, dense, etc.) to the CNN model.
- Compile Model: Compile the model with an appropriate optimizer, loss function, and evaluation metrics.
- Fetching Batches: Create a function to fetch batches of data for training and testing.
- Training and Evaluation: Train the CNN model using the training dataset, and evaluate its performance on the test dataset.
- Plotting Graphs: Plot graphs of model loss and accuracy during the training process to visualize the modelβs performance.
- Fetching Sample Data: Fetch batches of sample data to be passed through the trained model.
- Prediction Function: Implement a function to predict the class of the fetched sample data using the trained CNN model.
- Painter Class: Create a Painter class that lets users draw doodles with the mouse.
- Drawing Area and Pencil: Define the drawing area and the pencil object to allow users to draw on the canvas.
- Smoothing Lines: Implement a function to smooth out the lines drawn by users, using quadratic curves to make the drawing appear cleaner.
- Resizing Drawings: Resize the doodle drawing to the required 28x28 pixel size to match the input size expected by the CNN model.
- Normalizing Data: Normalize the pixel values to ensure the data is in a suitable format for the CNN model.
- Making Predictions: Pass the normalized data through the CNN model to predict the doodle class.
- Expanding the Dataset: Add additional doodle categories to the game, increasing the diversity of predictions.
- Model Update: Retrain the CNN model with the new categories to improve its prediction capabilities.
Feel free to contribute to this project by submitting issues or pull requests. Whether you have a bug fix, feature suggestion, or improvement idea, contributions are always welcome! π
To get started:
- Fork the repository.
- Create a new branch for your feature or bug fix.
- Make your changes and commit them.
- Push your changes to your forked repository.
- Open a pull request with a detailed description of your changes.
Happy coding! π