Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Dog and Cat Image Classifier

A deep learning project to classify images of dogs and cats using a Convolutional Neural Network (CNN) built with the TensorFlow library. This project was a first-time exploration into Python and deep learning, following tutorials and resources to understand the fundamentals of model training and evaluation.\

🚀 Key Features

  • Custom CNN Model: A custom-built neural network architecture for image classification.

  • TensorFlow Implementation: The model is built and trained using the powerful TensorFlow library.

  • Visualized Metrics: The training process is visualized with charts showing the model's accuracy and loss progression using Matplotlib.

  • Pre-trained Model: The final trained model is saved for easy re-use, allowing for quick testing without needing to retrain.

💻 How to Run the Project

  1. Libraries Before you begin, ensure you have the following installed:
  • Python 3.x: The project is developed in Python.
  • TensorFlow: The core deep learning library.
  • Matplotlib: Used for visualizing the training metrics.
  • Numpy: A fundamental package for scientific computing with Python.

You can install the required packages using pip:

pip install tensorflow matplotlib numpy
  1. Dataset The model was trained on the Dogs and Cats Classification Dataset from Kaggle, which contains 24,998 images (12,499 cat images and 12,499 dog images).
  1. Training the model The main script (main.py) trains the CNN
  • Execution: Go to model_training folder and run the following command

    python main.py
  • Output: After training, the model will be saved in the trained_model/ directory.

  • Charts: After the model is trained and saved the following charts are visualized showing the accuracy and loss progression

    drawing drawing
  1. Testing the model To test the trained model on a new image, use the model_test.py script.
  • Prepare your image: Place the image you want to test in a designated folder, or specify the image path in the script.

  • Execution: Run the test script:

    python model_test.py

The script will output the classification result (either "Dog" or "Cat").

drawing

drawing

📈 Model Performance

During training, the model's accuracy and loss were tracked and saved. The final metrics are stored in a JSON file (training_history.json) located in trained_model folder.

  • Accuracy: The graph below shows the model's accuracy on both the training and validation sets over each epoch.
  • Loss: This graph illustrates how the model's loss decreased over the training period.

🧠 Technical Details

  • Model Architecture: The model uses a standard CNN architecture with convolutional layers, max-pooling layers, and a final dense layer for classification.
  • Optimizer: The RMSprop optimizer was chosen for its effectiveness in training neural networks. While other optimizers exist, RMSprop is a solid choice for this type of problem, dynamically adjusting the learning rate for each parameter.
  • Tutorials: This project was developed by learning from these valuable resources:

Tensorboard

By reading the Tensorflow documentation I had found that the TensorFlow provides a powerful visualization tool called TensorBoard that's essential for the machine learning workflow. It helps you track experiment metrics like loss and accuracy, visualize your model graph, project embeddings into a lower-dimensional space, and much more. To use TensorBoard, you need to save log files during model training. Typically, these logs are stored in a designated directory, like logs/fit.

  tensorboard --logdir logs/fit

Unfortunately this command didn't work for me. After some research I have found another command which is this:

  python -m tensorboard.main --logdir logs/fit

By running it I was able to access the TensorBoard on http://localhost:6006/

drawing

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages