Skip to content

Cat or Dog Binary Classifier using CNN. This project is a Convolutional Neural Network (CNN) built with TensorFlow and Keras to classify images of cats and dogs.

License

Notifications You must be signed in to change notification settings

45Harry/Cat_or_Dog_classification_using_CNN

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Cat or Dog Binary Classifier using CNN

This project is a binary image classifier that distinguishes between cats and dogs using a Convolutional Neural Network (CNN) built with TensorFlow and Keras.

Table of Contents

Summary

This project demonstrates how to build and train a CNN model to classify images of cats and dogs. The model is trained on a dataset of cat and dog images and can predict whether a new image contains a cat or a dog.

Installation

  1. Clone the repository:
    git clone https://github.com/45Harry/Cat_or_Dog_classification_using_CNN
    cd Cat_or_Dog_classification_using_CNN
    
     Install the required dependencies:
    
      pip install tensorflow numpy
    

Usage

Prepare the Dataset:

    Organize your dataset into the following structure:
    Copy

    Datasets/
      train/
        cat/
        dog/
      test/
        cat/
        dog/

    Replace the paths in the code with your dataset paths.

Train the Model:

    Run the provided script to train the CNN model:

    python train.py

Make Predictions:

    To predict whether an image contains a cat or a dog, place the image in the Datasets/prediction_data/ folder and run the prediction code.

Dataset

The dataset should contain images of cats and dogs organized into train and test directories. Each directory should have subdirectories for cat and dog images.

Example structure:

Datasets/ train/ cat/ cat1.jpg cat2.jpg dog/ dog1.jpg dog2.jpg test/ cat/ cat3.jpg dog/ dog3.jpg

Model Architecture

The CNN model consists of the following layers:

Two Conv2D layers with ReLU activation.

Two MaxPooling2D layers.

A Flatten layer.

Two Dense layers with ReLU activation.

A final Dense layer with sigmoid activation for binary classification.

Training

The model is trained using the Adam optimizer and binary cross-entropy loss. Data augmentation is applied to the training dataset to improve generalization. Prediction

To predict whether an image contains a cat or a dog:

Place the image in the Datasets/prediction_data/ folder.

Run the prediction code:

img = tf.keras.preprocessing.image.load_img('path_to_image.jpg', target_size=(64, 64))
img = tf.keras.preprocessing.image.img_to_array(img)
img = np.expand_dims(img, axis=0)
prediction = cnn.predict(img)
if prediction[0][0] > 0.5:
    print("Dog")
else:
    print("Cat")

License

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

About

Cat or Dog Binary Classifier using CNN. This project is a Convolutional Neural Network (CNN) built with TensorFlow and Keras to classify images of cats and dogs.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published