Automated Visual Quality Control & Logistics
01 Challenge
Manual visual inspection at goods receipt and in returns – right item, label present, packaging intact? – is a massive time sink.
02 Approach
A FastAPI endpoint accepts images, has them analyzed by the compact YOLOv8 Nano model and returns the image with the detected objects marked.
03 Result
A working object detection API with a live demo that detects and marks objects – lean enough for edge devices in the warehouse.
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.
- Model size
- ~6 MB
- YOLOv8 Nano (yolov8n.pt)
- Inference
- < 500 ms
- on CPU
- RAM usage
- < 200 MB
- edge-ready
- Use cases
- 3
- Returns · Labels · Inventory
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.
Manual visual inspection
- Staff check every item by eye
- Boxes on pallets are counted by hand
- Missing labels are noticed late
- Effort grows linearly with volume
AI-assisted visual control
- Camera plus YOLO model analyzes the image
- Objects are detected and counted automatically
- Checks happen before goods leave the warehouse
- Analysis in milliseconds per image
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). With a model size of about 6 MB, inference under 500 ms on CPU and less than 200 MB of RAM, it needs no GPU infrastructure.
Architecture: FastAPI & Ultralytics
The Python code uses FastAPI for uploads and ultralytics for the AI. A single endpoint handles the entire flow – from upload to the annotated result image.
- 01UploadImage arrives via POST requestUploadFile
- 02DecodeBytes are opened as an imagePillow
- 03InferenceYOLO detects objects in the imageyolov8n
- 04RenderDraw bounding boxes, BGR → RGBplot()
- 05ResponseResult image back to the browserJPEG stream
# 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.
Test Object Detection
Next Steps
The demo uses the pre-trained standard model and therefore detects general everyday objects. For the retail use cases described above, the logical extensions would be:
- Train custom classes: Fine-tune the Nano model on company-specific objects such as shipping labels, barcodes or box types.
- Structured output: Return detected classes and counts as JSON alongside the annotated image – the basis for counting and automated inspection rules.
- Edge deployment: Run the model directly on hand scanners or Raspberry Pis in the warehouse instead of sending images to a central server.