How mohanramasamy2005-eng/ai-pcba-board-detection works
Purpose and entry points
This repository is an electronic-component/PCBA visual-inspection system built around YOLOv8 object detection. It supports interactive webcam inference, HTTP image prediction, model training, PostgreSQL detection logging, and a Streamlit monitoring view.
Primary launch points are:
• Webcam detector: app/main.py
• FastAPI service: app/api.py
• Training workflow: train.py
• Monitoring UI: dashboard.py
Model assets and inference boundary
YOLOv8 is the central ML runtime. The repository includes a PyTorch base/model artifact and an ONNX artifact:
• yolov8n.pt
• yolov8n.onnx
• models/.gitkeep
Inference-facing applications are expected to load an exported ONNX model (the README describes models/best.onnx as the trained output). ONNX forms the portability/efficient-inference boundary; PyTorch/Ultralytics is used for training and potentially local model handling.
Real-time inspection path
app/main.py is the local operational path for live quality inspection. It captures frames from a webcam through OpenCV, runs detector inference, and presents detections in real time. This path is intended for operator-facing manufacturing inspection rather than serving HTTP clients.
Relevant path:
• app/main.py
REST prediction service
app/api.py exposes the FastAPI application, with POST /predict accepting an uploaded image. The API boundary converts multipart image input into model inference results suitable for integration with external manufacturing or quality-control systems.
Relevant path:
• app/api.py
The service is run with Uvicorn (uvicorn app.api:app), binding application logic to an ASGI server/runtime.
Training and dataset contract
train.py drives YOLOv8 detector training. Dataset layout, split locations, class count, and labels are defined by:
• train.py
• data/data.yaml
The documented detection taxonomy has five classes: OK, Missing_Part, Scratch, Bent_Pin, and Soldering_Issue. Training outputs are expected to be exported for deployment, notably as ONNX artifacts consumed by inference paths.
Detection persistence and monitoring
Detection events are persisted to PostgreSQL through:
• log.py
The expected record contract is timestamp, detected class, and confidence score. dashboard.py is a Streamlit application that reads these stored detection records and presents a live-updating monitoring table:
• dashboard.py
• log.py
This creates a separate observability path: detector/API inference → PostgreSQL log records → Streamlit dashboard.
Deployment and infrastructure
The runtime is containerized by:
• Dockerfile
Cloud deployment guidance targets Google Cloud Run:
• gcp_deploy.md
Material external dependencies are Ultralytics YOLOv8, OpenCV, FastAPI/Uvicorn, PostgreSQL, Streamlit, Docker, and Google Cloud Run. Python dependency resolution is defined in requirements.txt.
Main entry points: api.py Prediction API · train.py Training workflow · log.py Detection logger · main.py Live webcam inspection
Components 14
ML lifecycle
- Dataset contract · Defines splits and five defect classes.
data/data.yaml - Training workflow
train.py - PyTorch base model
yolov8n.pt - ONNX inference model · Trained deployment output is expected as models/best.onnx.
yolov8n.onnx
Inspection interfaces
- YOLOv8 runtime
- Live webcam inspection
app/main.py - Prediction API · Accepts uploaded images at POST /predict.
app/api.py - ASGI server
- External QC systems
Observability
- Detection logger · Records timestamp, class, and confidence.
log.py - Detection records
- Monitoring dashboard · Shows live-updating detection records.
dashboard.py
Deployment
- Container image
Dockerfile - Cloud Run
gcp_deploy.md
Connections 14
- Dataset contract → Training workflow: defines training data
- PyTorch base model → Training workflow: initializes
- Training workflow → ONNX inference model: exports
- ONNX inference model → YOLOv8 runtime: loaded for inference
- Live webcam inspection → YOLOv8 runtime: submits camera frames
- ASGI server → Prediction API: serves
- External QC systems → Prediction API: POST /predict image
- Prediction API → YOLOv8 runtime: runs image inference
- Live webcam inspection → Detection logger: logs detections
- Prediction API → Detection logger: logs predictions
- Detection logger → Detection records: writes records
- Monitoring dashboard → Detection records: reads detection records
- Container image → Prediction API: packages service
- Container image → Cloud Run: deployed to