This project is an image classification system built using Convolutional Neural Networks (CNN) and Streamlit. It allows users to upload images or select from sample images to identify whether the image contains a cat or a dog. The application features a user-friendly interface, real-time predictions, and interactive elements like balloons animation on successful prediction. The model is trained on a large dataset of cat and dog images and achieves high accuracy in distinguishing between the two pets.
Try out the Cat or Dog Recognizer! 👉🏻
Below is a preview of the app in action. Upload an image or select a sample to see the prediction! 👇🏻
I developed this project to explore deep learning and computer vision while creating something fun and practical. Here’s a snapshot of my journey:
-
Inspiration:
As a pet lover and AI enthusiast, I wanted to create a practical application that combines both interests. The challenge of distinguishing between cats and dogs, which can be tricky even for humans in some cases, seemed like a perfect project to tackle with deep learning. -
Why I Made It:
I aimed to build a system that could accurately classify pet images while learning about CNNs, image processing, and web deployment. This project served as a hands-on way to understand the complete machine learning pipeline from data preparation to model deployment. -
Challenges Faced:
- Data Preprocessing: Handling corrupt images and ensuring consistent input formats was a significant challenge.
- Model Architecture: Finding the right balance of layers and parameters to prevent overfitting while maintaining accuracy.
- Image Augmentation: Implementing effective augmentation techniques to improve model generalization.
- Web Integration: Creating a seamless user experience with Streamlit while handling various image formats and sizes.
-
What I Learned:
- Deep Learning: Practical experience with CNN architecture and training.
- Image Processing: Techniques for handling and preprocessing image data.
- Data Augmentation: Methods to increase dataset diversity and improve model robustness.
- Web Development: Building an interactive web interface using Streamlit.
- Features
- Installation
- Usage
- Technologies Used
- Dataset
- Data Preprocessing
- Model Training
- Results
- Directory Structure
- Contributing
- License
- Contact
-
Accurate Classification:
Utilizes a CNN to reliably differentiate between cats and dogs. -
Interactive Interface:
Upload your own image or select from sample images for quick predictions. -
Real-Time Predictions:
Get immediate results along with confidence scores. -
Responsive Design:
Seamless experience on both desktop and mobile devices.
-
Clone the Repository:
git clone https://github.com/hk-kumawat/Cat-or-Dog-Recognizer.git cd Cat-or-Dog-Recognizer
-
Create & Activate a Virtual Environment (optional but recommended):
python -m venv venv source venv/bin/activate # On Windows: venv\Scripts\activate
-
Install Required Packages:
pip install -r requirements.txt
-
Run the Application:
streamlit run app.py
-
Run the Streamlit App:
streamlit run app.py
-
Choose Input Method:
- Upload your own image
- Select from sample images
-
View Results:
- See the uploaded/selected image
- Get instant prediction
- Enjoy the celebration animation!
To explore the model development process:
- Open the Notebook:
jupyter notebook "Dog_vs_Cat_Image_Classification.ipynb"
- Execute the cells to follow the complete model development pipeline.
- Programming Language: Python
- Libraries:
tensorflow
keras
numpy
opencv-python
streamlit
matplotlib
(for visualizations)
- Modeling Framework: Keras (for CNN model)
The Dogs vs. Cats dataset is a widely used computer vision dataset for classifying images as either containing a dog or a cat. Developed in partnership between Petfinder.com and Microsoft, this dataset is a subset of a much larger collection of 3 million manually annotated images.
- Download Size: 824 MB
- Total Images: 24,961 images
- Cat Images: 12,491
- Dog Images: 12,470
The dataset is organized into the following structure:
kagglecatsanddogs_3367a
├── readme[1].txt
├── MSR-LA - 3467.docx
└── PetImages
├── Cat (Contains 12,491 images)
└── Dog (Contains 12,470 images)
- Kaggle Dogs vs Cats Dataset: This is the dataset used for training the model, containing labeled images of cats and dogs.
The notebook performs several steps to prepare the data:
-
Loading Libraries & Dataset:
- Uses libraries such as pandas, numpy, matplotlib, and Keras for image processing.
- Iterates through the dataset folders to collect image paths and assign labels (0 for cats, 1 for dogs).
-
Creating a DataFrame:
- Combines image file paths and labels into a shuffled DataFrame for organized processing.
-
Cleaning Data:
- Identifies and removes invalid or non-image files (e.g., system files like Thumbs.db).
-
Visualization & Class Distribution:
- Displays grids of sample images and uses count plots to verify class balance.
The Cat or Dog Classifier project uses a Convolutional Neural Network (CNN) to classify images as either a cat or a dog. The model is trained with techniques aimed at improving its accuracy and robustness.
-
Model Architecture: A Convolutional Neural Network (CNN) is used for image classification, which is effective in capturing spatial hierarchies in images.
-
Data Augmentation: To enhance the model’s generalization and prevent overfitting, data augmentation techniques such as:
- Flipping (horizontal and vertical)
- Zooming (random zoom in/out)
- Rotating (random rotations)
These techniques help create variations of the original dataset, increasing model robustness.
-
Evaluation: The model is evaluated based on its accuracy, with additional attention given to minimizing overfitting through validation and test splits.
cat_dog_model.h5
: The trained model saved as an H5 file, which can be used to predict whether an uploaded image contains a cat or a dog.
- Training Accuracy: ~95%
- Validation Accuracy: ~93%
- Features:
- Fast inference time (<1s)
- Robust to various image sizes
- Handles different image formats
- Average Response Time: <2s
- Supported Image Formats: JPG, JPEG, PNG
- Memory Usage: ~200MB
- Concurrent Users: 50+
hk-kumawat-cat-or-dog-recognizer/
├── README.md # Project documentation
├── Dog_vs_Cat_Image_Classification.ipynb # Jupyter Notebook for training and evaluation
├── LICENSE # License information
├── app.py # Streamlit application for image classification
├── requirements.txt # List of dependencies
├── Sample Images of Cat and Dog/ # Folder containing sample images
│ ├── Cats/ # Sample images of cats
│ └── Dogs/ # Sample images of dogs
└── model/ # Saved models and related files
└── cat_dog_model.h5 # Trained CNN model
Contributions make the open source community such an amazing place to learn, inspire, and create. 🙌 Any contributions you make are greatly appreciated! 😊
Have an idea to improve this project? Go ahead and fork the repo to create a pull request, or open an issue with the tag "enhancement". Don't forget to give the project a star! ⭐ Thanks again! 🙏
-
Fork the repository.
-
Create a new branch:
git checkout -b feature/YourFeatureName
-
Commit your changes with a descriptive message.
-
Push to your branch:
git push origin feature/YourFeatureName
-
Open a Pull Request detailing your enhancements or bug fixes.
This project is licensed under the MIT License - see the LICENSE file for details.
I’d love to connect and discuss further:
💻 — Explore my projects and contributions.
🌐 — Let’s connect professionally.
📧 — Send me an email for discussions and queries.
"Every pet deserves to be recognized, even by AI!" - Anonymous