Automated Visual Quality Control & Logistics
In modern e-commerce, manual inspection of goods (e.g., at goods receipt or during returns) is a massive time sink. Employees must check: “Is this the right item?”, “Is the label present?”, “Is the packaging damaged?”
This project demonstrates automated visual quality control using AI. By deploying YOLOv8 (You Only Look Once), images can be analyzed in milliseconds to detect, count, and verify objects.
Business Use Cases
Although this project is technically based on an object detection API, the application possibilities in retail are wide-ranging:
- Returns inspection: Automatic comparison of whether the returned item visually matches the description (e.g., “Red shoe” vs. “Blue shoe”).
- Label verification: Checking whether shipping labels or barcodes are correctly attached to packages before they leave the warehouse.
- Stock inventory: Automatic counting of boxes on pallets using cameras, instead of manual counting.
The Technology: YOLOv8 Nano
I use the YOLOv8 Nano model (yolov8n.pt). It is the smallest and fastest version of the YOLO family, optimized for edge devices (like hand scanners or Raspberry Pis in warehouses).
- Size: Only approx. 6 MB
- Speed: Inference in < 500ms on CPU
- RAM usage: < 200 MB
The Backend: FastAPI & Ultralytics
The Python code uses FastAPI for uploads and ultralytics for the AI.
# main.py (extension)
from fastapi import UploadFile, File
from fastapi.responses import StreamingResponse
from ultralytics import YOLO
from PIL import Image
import io
# Load model (downloaded on first run)
model = YOLO("yolov8n.pt")
@app.post("/detect-objects")
async def detect_objects(file: UploadFile = File(...)):
# 1. Read image from upload
image_data = await file.read()
image = Image.open(io.BytesIO(image_data))
# 2. Run YOLO inference
results = model(image)
# 3. Render result image (with boxes)
# plot() returns a numpy array (BGR), we need to convert to RGB
res_plotted = results[0].plot()
res_image = Image.fromarray(res_plotted[..., ::-1]) # BGR to RGB
# 4. Send image back
img_byte_arr = io.BytesIO()
res_image.save(img_byte_arr, format='JPEG')
img_byte_arr.seek(0)
return StreamingResponse(img_byte_arr, media_type="image/jpeg" )
Live Demo: The AI Detective
Upload an image (e.g., a photo of a street, an office, or animals). The server will attempt to detect and mark objects.