Skip to content

Classifying Images using Keras on a pre-trained model with 1,000 categories.

License

Notifications You must be signed in to change notification settings

benstanbury/Image_Classification_Keras

Repository files navigation

Image Classification with Keras

A deep learning project that demonstrates image classification using a pre-trained VGG16 model with Keras and TensorFlow. The model can classify images into 1,000 different categories using the ImageNet dataset.

Overview

This project uses the VGG16 convolutional neural network architecture, pre-trained on the ImageNet dataset, to classify various images. The model achieves high accuracy on a wide range of object categories.

Features

  • Pre-trained VGG16 model for image classification
  • Support for 1,000 ImageNet categories
  • Visual probability distribution for top 10 predictions
  • Interactive Jupyter Notebook with example classifications
  • Easy-to-use prediction function

Requirements

  • Python 3.6+
  • Keras
  • TensorFlow
  • NumPy
  • Pandas
  • Matplotlib
  • Seaborn
  • Jupyter Notebook

See requirements.txt for detailed dependencies.

Installation

  1. Clone this repository:
git clone https://github.com/benstanbury/Image_Classification_Keras.git
cd Image_Classification_Keras
  1. Install dependencies:
pip install -r requirements.txt

Note: On first run, the model will download pre-trained weights (~500MB), which may take a few minutes.

Usage

Jupyter Notebook

Open and run the interactive notebook:

jupyter notebook Image_Classification_with_Keras.ipynb

The notebook includes examples of classifying various images including:

  • Animals (cheetah)
  • Objects (guitar)
  • Complex scenes (self-driving car, multiple fruits)
  • People

Python Script

You can also use the VGG16 model directly in your Python code:

from keras.preprocessing import image as image_utils
from imagenet_utils import decode_predictions, preprocess_input
from vgg16 import VGG16
import numpy as np

# Load and preprocess image
img = image_utils.load_img('your_image.jpg', target_size=(224, 224))
img_array = image_utils.img_to_array(img)
img_array = np.expand_dims(img_array, axis=0)
img_array = preprocess_input(img_array)

# Make prediction
model = VGG16(weights="imagenet")
predictions = model.predict(img_array)
results = decode_predictions(predictions, top=5)

print(results)

Project Structure

Image_Classification_Keras/
├── Image_Classification_with_Keras.ipynb  # Main interactive notebook
├── vgg16.py                                # VGG16 model implementation
├── imagenet_utils.py                       # ImageNet utilities and preprocessing
├── requirements.txt                        # Project dependencies
├── README.md                               # Project documentation
├── LICENSE                                 # MIT License
├── *.jpg                                   # Example images for classification
└── .gitignore                              # Git ignore rules

Model Details

The VGG16 model is a deep convolutional neural network that consists of:

  • 16 weight layers (13 convolutional + 3 fully connected)
  • Input size: 224x224 RGB images
  • Output: 1,000 class probabilities
  • Pre-trained on ImageNet dataset

For more details, see the original paper: Very Deep Convolutional Networks for Large-Scale Image Recognition

Example Results

The notebook demonstrates classification on several example images with visualization of the top 10 predictions and their probabilities.

Credits and References

This project was built using the following resources:

License

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

Contributing

Contributions, issues, and feature requests are welcome! Feel free to check the issues page.

Author

Ben Stanbury

Acknowledgments

  • Thanks to the Keras team for the excellent deep learning framework
  • ImageNet for providing the comprehensive dataset
  • The VGG team at Oxford for the model architecture

About

Classifying Images using Keras on a pre-trained model with 1,000 categories.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published