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:
- Flask API – Allows users to send an image via a POST request and get a predicted class.
- Streamlit UI – Provides an interactive web interface where users can upload images and view the prediction.
- Project Overview
- Dataset
- Model Architecture and Training
- Flask API Implementation
- Streamlit App Implementation
- Installation and Setup
- How to Run the Project
- File Structure
- Future Enhancements
- 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.
- 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.
The CNN model consists of:
- Convolutional layers with ReLU activation.
- MaxPooling layers for downsampling.
- Fully connected (Dense) layers.
- Softmax activation for multi-class classification.
- Optimizer: Adam
- Loss Function: Sparse Categorical Crossentropy
- Evaluation Metric: Accuracy
- Data Augmentation: (Optional) To improve generalization
- 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.
- Implemented in
app.pyusing Flask. - Loads the pretrained model and class names on startup.
- Exposes an API endpoint:
POST /predict: Accepts an image and returns the predicted class.
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/.
curl -X POST -F "file=@path_to_image.jpg" http://127.0.0.1:5000/predict- 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.
streamlit run streamlit-app/app.py- Open the URL displayed in the terminal (usually
http://localhost:8501). - Upload an image and view the prediction.
Ensure you have:
- Python (>=3.7) installed
- pip
- A virtual environment (optional but recommended)
- Clone the repository
git clone <repository_link>
cd <repository_folder>- Create and activate a virtual environment (optional but recommended)
python -m venv venv
source venv/bin/activate # On Windows: venv\Scripts\activate- Install dependencies
pip install -r requirements.txt- Ensure the model and class names files exist
model/cifar10_model.kerasmodel/class_names.pklIf not, retrain the model usingCIFAR_10_Image_Classification_with_CNN.ipynb.
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.
streamlit run streamlit-app/app.py- Upload an image via the UI and get predictions.
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
- 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.