Skip to main content
Navigation
HomeTechnical ReferenceJournalGitHubGitHub
Sidebar — toggle document categories via the logo
FastAPI ML Project — Car Damage Assessment Platform

FastAPI ML Project — Car Damage Assessment Platform

November 19, 2023

Overview

FastAPI ML Project (also branded as "Accident-AI") is a machine learning microservices platform that automates vehicle damage assessment from car accident images. Users upload photos of damaged vehicles, and the system's ML models — powered by Detectron2 (Facebook Research) on an NVIDIA GPU — detect and classify damage across different car parts using blueprint mask overlays.

The platform is split across five containerized services: a FastAPI backend for business logic and case management, a GPU-accelerated ML worker running Detectron2 models, a Flask server-rendered frontend, a React (CoreUI) admin dashboard, and MongoDB for persistent storage. Celery with Redis handles asynchronous task distribution.


Key Features

  • Automated damage detection: Detectron2-based computer vision models process car images and identify damaged areas using 18 car-part blueprint masks (bumper, fender, door, headlamp, etc.)
  • Two ML model versions: model_service_v1.py and model_service_v2.py (~2,500 lines each) — support for multiple detection architectures
  • Parallel image processing: ThreadPoolExecutor with 8 workers for concurrent image analysis
  • Full case management API: CRUD for accident cases, vehicle addition, top-view generation, and PDF report generation
  • JWT authentication: HS256-signed JWT tokens with bearer authentication and API key support
  • S3 storage integration: Images and reports stored in AWS S3 bucket (accident-ai-uploads)
  • Dual frontends: Flask (server-rendered Jinja2 + Bootstrap Creative) and React (CoreUI Free Admin Template)
  • GPU-accelerated Docker worker: NVIDIA CUDA 11.0.3 base image with Detectron2 compiled from source
  • Celery task queue: Asynchronous job distribution for long-running ML inference tasks

Architecture

┌──────────────┐
│ MongoDB │ (accident_ai_app)
└──────┬───────┘

┌───────────────────┼───────────────────┐
│ │ │
┌────▼────────┐ ┌───────▼────────┐ ┌───────▼──────────┐
│ API Svc │ │ Worker Svc │ │ Flask Frontend │
│ :5000 │◄─┤ :4000 │ │ :3000 │
│ FastAPI │ │ FastAPI + ML │ │ Jinja2 + Bootstrap│
│ JWT Auth │ │ Detectron2 │ │ │
└─────────────┘ │ GPU Inference │ └───────────────────┘
└────────────────┘
┌───────────────────┐
│ React Frontend │
│ :3001 │
│ CoreUI Admin │
└────────┬──────────┘

┌────────▼──────────┐
│ Nginx :80 │
└───────────────────┘

Tech Stack

LayerTechnology
API FrameworkFastAPI, Uvicorn
ML FrameworkDetectron2 (Facebook Research), PyTorch 1.11
Computer VisionOpenCV, NumPy, Pytesseract (OCR)
GPU RuntimeNVIDIA CUDA 11.0.3
DatabaseMongoDB (MongoEngine ODM)
Task QueueCelery + Redis
AuthJWT (HS256), bcrypt password hashing
StorageAWS S3 (boto3)
Frontend (Flask)Flask, Jinja2, Bootstrap Creative
Frontend (React)React 18, Redux, CoreUI Admin Template, Chart.js
PDF Generationwkhtmltopdf (PDFKit)
ContainerDocker Compose (5 services), Nginx, NVIDIA GPU
LicenseMIT