An industrial-grade Deep Learning solution for Coffee Particle Size Distribution (PSD) analysis. This project transforms a traditional OpenCV-based tool into a modern, containerized AI service capable of high-precision grind size measurement using YOLOv8 segmentation.
- AI Inference Engine: Integrates YOLOv8-segmentation for precise particle detection and size calculation.
- Microservices Architecture: Separate containers for API (FastAPI), Task Queue (Celery), and In-memory Store (Redis).
- Asynchronous Processing: Handles heavy AI inference tasks in the background to ensure a smooth UI experience.
- Manual Calibration Tool: Built-in canvas-based scaling tool in React to convert pixels to real-world millimeters (mm).
- Dockerized Environment: Fully containerized deployment with optimized CPU-only PyTorch builds.
Note
The diagram above shows the full microservices flow. If your viewer doesn't render the Mermaid code below, please refer to the image.
graph LR
A[React Frontend] -->|Upload + Calibration| B[FastAPI API]
B -->|Dispatch Task| C[Redis Queue]
C -->|Fetch Task| D[Celery AI Worker]
D -->|YOLOv8 Prediction| D
D -->|Calc PSD| D
D -->|Store Result| C
B ---|Poll Result| C
api/: Backend core logic.main.py: RESTful API endpoints.worker.py: AI inference and PSD calculation logic.
frontend/: Modern React + Vite + Tailwind CSS dashboard.synthetic_data/: Scripts and utilities for generating AI training data.Dockerfile&docker-compose.yml: Container orchestration.
Ensure you have Docker Desktop installed.
-
Clone and Build:
docker-compose up --build -d
-
Access the Services:
- Frontend: http://localhost:5173
- API Docs (Swagger): http://localhost:8000/docs
If you wish to run or develop the frontend separately without Docker:
- Prerequisites: Node.js installed.
- Install Dependencies:
cd frontend npm install - Run Development Server:
npm run dev
- Access: http://localhost:5173
Important
Manual frontend requires the Backend (Docker) to be running on http://localhost:8000.
To get accurate results, follow these steps:
- Upload: Select a top-down clear photo of your coffee grounds. Place a reference object (like a coin) next to them.
- Calibrate:
- Click and drag a line over the reference object (e.g., the diameter of a NT$10 coin).
- Enter the real-world length (e.g.,
26mm for a 10-dollar coin).
- Analyze: Click "Run AI Analysis".
- Result: The AI will identify all particles and calculate their average diameter in millimeters.
The system includes an automatic cleanup mechanism:
- Uploaded images are automatically deleted from the server immediately after AI analysis is complete to prevent storage accumulation.
Ricepaste/coffeegrindsize (Modernized Version) Enhanced with Deep Learning and Microservices for Future Resume Enhancement.
