Skip to content

This project uses deep learning and transfer learning to classify images from the CIFAR-10 dataset into 10 categories (such as airplane, car, bird, etc.) using Convolutional Neural Networks (CNNs). It includes a custom CNN built from scratch and a MobileNetV2-based transfer learning approach. The repository contains all code.

Notifications You must be signed in to change notification settings

enriest/Image-Classification-with-CNN-on-CIFAR-10

Repository files navigation

logo_ironhack_blue 7

Project I | Deep Learning: Image Classification with CNN

Task Description

Students will build a Convolutional Neural Network (CNN) model to classify images from a given dataset into predefined categories/classes.

Datasets (pick one!)

  1. The dataset for this task is the CIFAR-10 dataset, which consists of 60,000 32x32 color images in 10 classes, with 6,000 images per class. You can download the dataset from here.
  2. The second dataset contains about 28,000 medium quality animal images belonging to 10 categories: dog, cat, horse, spyder, butterfly, chicken, sheep, cow, squirrel, elephant. The link is here.

Assessment Components

  1. Data Preprocessing

    • Data loading and preprocessing (e.g., normalization, resizing, augmentation).
    • Create visualizations of some images, and labels.
  2. Model Architecture

    • Design a CNN architecture suitable for image classification.
    • Include convolutional layers, pooling layers, and fully connected layers.
  3. Model Training

    • Train the CNN model using appropriate optimization techniques (e.g., stochastic gradient descent, Adam).
    • Utilize techniques such as early stopping to prevent overfitting.
  4. Model Evaluation

    • Evaluate the trained model on a separate validation set.
    • Compute and report metrics such as accuracy, precision, recall, and F1-score.
    • Visualize the confusion matrix to understand model performance across different classes.
  5. Transfer Learning

    • Evaluate the accuracy of your model on a pre-trained models like ImagNet, VGG16, Inception... (pick one an justify your choice)
      • You may find this link helpful.
      • This is the Pytorch version.
    • Perform transfer learning with your chosen pre-trained models i.e., you will probably try a few and choose the best one.
  6. Code Quality

    • Well-structured and commented code.
    • Proper documentation of functions and processes.
    • Efficient use of libraries and resources.
  7. Report

    • Write a concise report detailing the approach taken, including:
      • Description of the chosen CNN architecture.
      • Explanation of preprocessing steps.
      • Details of the training process (e.g., learning rate, batch size, number of epochs).
      • Results and analysis of models performance.
      • What is your best model. Why?
      • Insights gained from the experimentation process.
    • Include visualizations and diagrams where necessary.
  8. Model deployment

    • Pick the best model
    • Build an app using Flask - Can you host somewhere other than your laptop? +5 Bonus points if you use Tensorflow Serving
    • User should be able to upload one or multiples images get predictions including probabilities for each prediction

Evaluation Criteria

  • Accuracy of the trained models on the validation set. 30 points
  • Clarity and completeness of the report. 20 points
  • Quality of code implementation. 5 points
  • Proper handling of data preprocessing and models training. 30 points
  • Demonstration of understanding key concepts of deep learning. 5 points
  • Model deployment. 10 points

Passing Score is 70 points.

Submission Details

  • Deadline for submission: end of the week or as communicated by your teaching team.
  • Submit the following:
    1. Python code files (*.py, ipynb) containing the model implementation and training process.
    2. A data folder with 5-10 images to test the deployed model/app if hosted somewhere else other than your laptop (strongly recommended! Not a must have)
    3. A PDF report documenting the approach, results, and analysis.
    4. Any additional files necessary for reproducing the results (e.g., requirements.txt, README.md).
    5. PPT presentation

Additional Notes

  • Students are encourage to experiment with different architectures, hyper-parameters, and optimization techniques.
  • Provide guidance and resources for troubleshooting common issues during model training and evaluation.
  • Students will discuss their approaches and findings in class during assessment evaluation sessions.

Deployment (Railway) - Quick Start

This repository now includes a minimal Flask inference API (app.py) serving predictions for CIFAR-10 using best_model_cifar10.pth.

Added Deployment Files

File Purpose
app.py Flask server with /health and /predict
requirements.txt Runtime dependencies
Procfile Process definition (web)
railway.toml Railway deploy config
.gitignore Ignore notebooks, data, venv

1. Local Run

python3 -m venv .venv
source .venv/bin/activate  # macOS/Linux
pip install --upgrade pip
pip install -r requirements.txt
python app.py
# Test
curl http://localhost:8000/health
curl -X POST -F "file=@some_image.png" http://localhost:8000/predict

2. Model Saving Format

If your checkpoint is only a state_dict:

torch.save({'state_dict': model.state_dict()}, 'best_model_cifar10.pth')

The loader also accepts a full model object (saved via torch.save(model, path)).

3. Deploy to Railway

  1. Push repo to GitHub (include model file if small; if large, store externally + download in a build step).
  2. In Railway: New Project -> Deploy from GitHub.
  3. Railway installs requirements.txt and runs python app.py (from Procfile).
  4. Open the generated URL:
    • /health returns { "status": "ok" }.
    • /predict expects multipart form-data with key file.

Example request after deploy:

curl -X POST -F "file=@some_image.png" https://YOUR-SUBDOMAIN.up.railway.app/predict

4. Environment Variables

Set MODEL_PATH if the model filename/location changes.

5. Improvements To Consider

  • Add authentication (API key header)
  • Add Swagger UI docs
  • Batch prediction endpoint
  • Caching repeated images (hash + Redis)
  • Transfer learning endpoints (load different models via query)

Deployment scaffold included to satisfy the Model Deployment assessment component.

CNN-Project

About

This project uses deep learning and transfer learning to classify images from the CIFAR-10 dataset into 10 categories (such as airplane, car, bird, etc.) using Convolutional Neural Networks (CNNs). It includes a custom CNN built from scratch and a MobileNetV2-based transfer learning approach. The repository contains all code.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published