An open API service indexing awesome lists of open source software.

https://github.com/45harry/cat_or_dog_classification_using_cnn

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.
https://github.com/45harry/cat_or_dog_classification_using_cnn

Last synced: about 1 year ago
JSON representation

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.

Awesome Lists containing this project

README

          

# 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](#Summary)
- [Installation](#installation)
- [Usage](#usage)
- [Dataset](#dataset)
- [Model Architecture](#model-architecture)
- [Training](#training)
- [Prediction](#prediction)
- [License](#license)

## 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:
```bash
git clone https://github.com/your-username/cat-dog-classifier.git
cd cat-dog-classifier

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.