Skip to content

🐱🐶 An ML-powered image classifier to distinguish between cats and dogs, providing fast, accurate results with a user-friendly interface.

License

Notifications You must be signed in to change notification settings

hk-kumawat/Cat-or-Dog-Recognizer

Repository files navigation

🐱🐶 Cat or Dog Recognizer 🖼️

Cat or Dog Image

Overview

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.


Live Demo

Try out the Cat or Dog Recognizer! 👉🏻 Experience It! 🌟


Below is a preview of the app in action. Upload an image or select a sample to see the prediction! 👇🏻


Learning Journey 🗺️

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.

Table of Contents

  1. Features
  2. Installation
  3. Usage
  4. Technologies Used
  5. Dataset
  6. Data Preprocessing
  7. Model Training
  8. Results
  9. Directory Structure
  10. Contributing
  11. License
  12. Contact

Features🌟

  • 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.


Installation🛠

  1. Clone the Repository:

    git clone https://github.com/hk-kumawat/Cat-or-Dog-Recognizer.git
    cd Cat-or-Dog-Recognizer
  2. Create & Activate a Virtual Environment (optional but recommended):

    python -m venv venv
    source venv/bin/activate       # On Windows: venv\Scripts\activate
  3. Install Required Packages:

    pip install -r requirements.txt
  4. Run the Application:

    streamlit run app.py

Usage🚀

  1. Run the Streamlit App:

    streamlit run app.py
  2. Choose Input Method:

    • Upload your own image
    • Select from sample images
  3. View Results:

    • See the uploaded/selected image
    • Get instant prediction
    • Enjoy the celebration animation!

Using the Jupyter Notebook

To explore the model development process:

  1. Open the Notebook:
    jupyter notebook "Dog_vs_Cat_Image_Classification.ipynb"
  2. Execute the cells to follow the complete model development pipeline.

Technologies Used💻

  • Programming Language: Python
  • Libraries:
    • tensorflow
    • keras
    • numpy
    • opencv-python
    • streamlit
    • matplotlib (for visualizations)
  • Modeling Framework: Keras (for CNN model)

Dataset📊

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.

Dataset Details:

  • 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)

Source:


Data Preprocessing🔄:

The notebook performs several steps to prepare the data:

  1. 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).
  2. Creating a DataFrame:

    • Combines image file paths and labels into a shuffled DataFrame for organized processing.
  3. Cleaning Data:

    • Identifies and removes invalid or non-image files (e.g., system files like Thumbs.db).
  4. Visualization & Class Distribution:

    • Displays grids of sample images and uses count plots to verify class balance.

Model Training🧠

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.

Key Aspects of Model Training:

  • 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.

Final Model Artifacts:

  • 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.

Results🏆

Model Performance

  • Training Accuracy: ~95%
  • Validation Accuracy: ~93%
  • Features:
    • Fast inference time (<1s)
    • Robust to various image sizes
    • Handles different image formats

System Performance

  • Average Response Time: <2s
  • Supported Image Formats: JPG, JPEG, PNG
  • Memory Usage: ~200MB
  • Concurrent Users: 50+

Directory Structure📁

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

Contributing🤝

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! 🙏


  1. Fork the repository.

  2. Create a new branch:

    git checkout -b feature/YourFeatureName
  3. Commit your changes with a descriptive message.

  4. Push to your branch:

    git push origin feature/YourFeatureName
  5. Open a Pull Request detailing your enhancements or bug fixes.


License📝

This project is licensed under the MIT License - see the LICENSE file for details.


Contact

📬 Get in Touch!

I’d love to connect and discuss further:

  • GitHub 💻 — Explore my projects and contributions.
  • LinkedIn 🌐 — Let’s connect professionally.
  • Email 📧 — Send me an email for discussions and queries.

Thanks for checking out the Cat or Dog Recognizer! 🐱🐶

"Every pet deserves to be recognized, even by AI!" - Anonymous

(back to top)

About

🐱🐶 An ML-powered image classifier to distinguish between cats and dogs, providing fast, accurate results with a user-friendly interface.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published