Skip to content

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

1 watching

Forks

Latest commit

 

History

1 Commit

Folders and files

Repository files navigation

CIFAR-10 Image Classification with CNN, Flask API, and Streamlit UI

This project implements a Convolutional Neural Network (CNN) trained on the CIFAR-10 dataset to classify images into 10 different categories. The model is deployed in two ways:

  1. Flask API – Allows users to send an image via a POST request and get a predicted class.
  2. Streamlit UI – Provides an interactive web interface where users can upload images and view the prediction.

📌 Table of Contents

  1. Project Overview
  2. Dataset
  3. Model Architecture and Training
  4. Flask API Implementation
  5. Streamlit App Implementation
  6. Installation and Setup
  7. How to Run the Project
  8. File Structure
  9. Future Enhancements

🚀 Project Overview

  • The project is built using TensorFlow/Keras for training a CNN model.
  • The trained model is deployed using Flask as a REST API.
  • A Streamlit web application allows users to upload images and classify them interactively.
  • The model is trained on the CIFAR-10 dataset, which contains 60,000 images categorized into 10 classes.

📂 Dataset

  • The CIFAR-10 dataset contains 10 classes:
['airplane', 'automobile', 'bird', 'cat', 'deer', 'dog', 'frog', 'horse', 'ship', 'truck']
  • Each image is 32x32 pixels with 3 color channels (RGB).
  • The dataset is preprocessed by normalizing pixel values.

🏗 Model Architecture and Training

Model Structure

The CNN model consists of:

  • Convolutional layers with ReLU activation.
  • MaxPooling layers for downsampling.
  • Fully connected (Dense) layers.
  • Softmax activation for multi-class classification.

Training Details

  • Optimizer: Adam
  • Loss Function: Sparse Categorical Crossentropy
  • Evaluation Metric: Accuracy
  • Data Augmentation: (Optional) To improve generalization

Saving the Model

  • After training, the model is saved as cifar10_model.keras.
  • The class labels are stored in class_names.pkl.
  • Training is performed in CIFAR_10_Image_Classification_with_CNN.ipynb.

🔥 Flask API Implementation

  • Implemented in app.py using Flask.
  • Loads the pretrained model and class names on startup.
  • Exposes an API endpoint:
    • POST /predict: Accepts an image and returns the predicted class.

Running Flask API

python app.py
  • The server runs on http://127.0.0.1:5000.
  • To test if it’s running, open a browser and visit http://127.0.0.1:5000/.

Making a Prediction with CURL

curl -X POST -F "file=@path_to_image.jpg" http://127.0.0.1:5000/predict

🎨 Streamlit App Implementation

  • Implemented in streamlit-app/app.py.
  • Provides a user-friendly web UI for image classification.
  • Allows users to upload an image and get the model’s prediction.

Running the Streamlit App

streamlit run streamlit-app/app.py
  • Open the URL displayed in the terminal (usually http://localhost:8501).
  • Upload an image and view the prediction.

🛠 Installation and Setup

Prerequisites

Ensure you have:

  • Python (>=3.7) installed
  • pip
  • A virtual environment (optional but recommended)

Setup Instructions

  1. Clone the repository
git clone <repository_link>
cd <repository_folder>
  1. Create and activate a virtual environment (optional but recommended)
python -m venv venv
source venv/bin/activate  # On Windows: venv\Scripts\activate
  1. Install dependencies
pip install -r requirements.txt
  1. Ensure the model and class names files exist
  • model/cifar10_model.keras
  • model/class_names.pkl If not, retrain the model using CIFAR_10_Image_Classification_with_CNN.ipynb.

▶️ How to Run the Project

1️⃣ Run Flask API

python app.py
  • The server runs at http://127.0.0.1:5000

  • Use Postman to send an image and get predictions.

  • Open Postman.

  • Set request type to POST.

  • Enter URL: http://127.0.0.1:5000/predict

  • Go to Body → Select form-data.

  • Add a key named file and upload an image.

  • Click Send.

  • The response should return the predicted class.

2️⃣ Run Streamlit App

streamlit run streamlit-app/app.py
  • Upload an image via the UI and get predictions.

📂 File Structure

project_root/
│── model/
│   ├── cifar10_model.keras       # Trained model file
│   ├── class_names.pkl           # Class names mapping
│── notebook/
│   ├── CIFAR_10_Image_Classification_with_CNN.ipynb  # Model training notebook
│── app/
│   ├── app.py                    # Flask API implementation
│── streamlit-app/
│   ├── app.py                    # Streamlit UI for local deployment
│── requirements.txt               # List of dependencies
│── README.md
│── sample-images/
│   ├── airplane.jpeg       
│   ├── bird.jpeg      
│   ├── frog.jpeg       
│   ├── ship.jpeg                 

🔮 Future Enhancements

  • Improve model accuracy with hyperparameter tuning and data augmentation.
  • Implement authentication for API security.
  • Deploy the model on cloud platforms (AWS, Google Cloud, or Render).
  • Extend the Streamlit app with visualizations like Grad-CAM.
  • Support batch predictions via API.

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages