Get Appointment

ImageClassifierAPI

End-to-End Image Classification with FastAPI and P

T An end-to-end image classification system using FastAPI and PyTorch. You can upload images, train a model from scratch or continue training with new data, and predict from both the browser and API.

Category
Terminal Code
Source Code
View
Published
Aug. 14, 2025

Project Summery

An end-to-end image classification system using FastAPI and PyTorch. You can upload images, train a model from scratch or continue training with new data, and predict from both the browser and API.

🚀 Features

  • ✅ Upload labeled images via API
  • ✅ Upload ZIP dataset with folder/class structure
  • ✅ Automatic train/val split
  • ✅ Incremental training: retrains only with new data if model already exists
  • ✅ Live predictions via API or browser UI
  • ✅ Auto-saves model + class labels

🧱 Project Structure

Root Directory

  • main.py – FastAPI server entrypoint
  • requirements.txt – Required Python packages
  • mobilenet_custom.pth – Saved model weights (after training)
  • class_names.txt – Text file storing class names (one per line)
  • README.md – Project documentation

/app/ – Core Application Code

  • __init__.py – Makes app a Python package
  • api.py – Defines all FastAPI API routes
  • config.py – Central configuration (paths, hyperparameters, etc.)
  • data_utils.py – Functions for saving images, unpacking ZIPs, data splits
  • model_utils.py – Model loading, training, prediction logic
  • templates/index.html – Jinja2 HTML template for web image prediction

/data/ – Image Dataset Directory

  • raw/ – Uploaded images, organized by class
  • train/ – Auto-generated training images
  • val/ – Auto-generated validation images

🚀 Features

  • Upload labeled images or ZIP dataset
  • Automatic train/validation split
  • Train with existing model or from scratch
  • Predict image class via API or Web UI
  • View prediction confidence
  • Real-time browser interface
  • MobileNetV2 transfer learning (ImageNet pretrained)

🛠️ Setup

git clone https://github.com/yourusername/image_classifier_api.git
cd image_classifier_api
python -m venv venv
source venv/bin/activate  # or venv\Scripts\activate on Windows
pip install -r requirements.txt
uvicorn main:app --reload

Output

Server Started

alt text

Add Image

alt text

Train

alt text

Result

alt text

Share