KHKT27: Zero-Cloud YOLOv8n INT8 on ESP32-S3
Edge-AI Agricultural Ripeness & Disease Sorting System · ViSEF 2027 → Regeneron ISEF
Author: Lê Hải Thiên Phúc (Im-xRay, born 2010) · Trường THPT Bà Rịa
English · Tiếng Việt · Live Project Site · Pipeline Guide · Hardware BOM

Real-time produce & leaf-disease classification (2.73 ms INT8 1T on PC CPU) driving the 3-bin servo sorting controller.
Overview
KHKT27 runs a 15-class full-integer INT8 YOLOv8n (192×192 RGB) object detector directly on an ESP32-S3 microcontroller—with zero cloud, PC, or Raspberry Pi dependency at runtime:
- Capture:
OV2640 acquires QVGA (320×240) RGB565 frames and resizes to 192×192 RGB888 in PSRAM (108 KB).
- Detect: TensorFlow Lite Micro executes the
3.20 MiB INT8 graph with -DESP_NN SIMD acceleration and on-device Greedy NMS.
- Actuate: Drives a 50 Hz PWM servo (
GPIO 2) into Unripe (45°), Ripe (90°), or Diseased (135°) chutes.
Model, Size & RAM Specs
| Component |
Measured Specification |
Notes |
| Detector |
YOLOv8n (192×192×3 RGB, 15 classes) |
3,141,405 params (130 layers) · 0.79 GFLOPs (11.1× less compute vs 8.77 @ 640px) |
| Model Compression |
6.17 MiB .pt → 3.20 MiB INT8 .tflite |
-48.1% size (3,356,200 B) · 325 INT8 + 88 INT32 (413 tensors, 261 ops) |
| OPI PSRAM Budget |
2.90 MiB / 8.00 MiB (36.2% used) |
2.50 MiB Tensor Arena + 0.29 MiB QVGA double FB + 0.11 MiB RGB888 |
| Internal SRAM |
512 KB preserved for system stack |
Camera DMA, FreeRTOS, servo PWM & Serial remain in SRAM |
| MCU & Firmware |
ESP32-S3 (240 MHz, qio_opi, -DESP_NN) |
Embedded Flash C-array model_data.h · PlatformIO C++ |
15-Class Taxonomy & 3-Bin Servo Routing Rules
| Chute Bin |
Servo Angle |
Classes (configs/classes.yaml) |
Unripe (unripe) |
45° |
mango_unripe, dragonfruit_unripe, tomato_unripe, guava_unripe, banana_unripe |
Ripe (ripe) |
90° |
mango_ripe, dragonfruit_ripe, durian_ripe, tomato_ripe, guava_ripe, banana_ripe |
Diseased (diseased) |
135° |
disease_anthracnose, disease_algal_spot, disease_pink_fungus, disease_powdery_mildew |
| Benchmark |
Measured Result |
Scope & Environment |
| Baseline Checkpoint |
39.5% mAP@50 · 27.0% mAP@50-95 · 56.1% Recall |
Best Epoch 27/47 (models/yolov8n_agri_192.pt, CPU Otsu baseline) |
CLIP-Curated Set (506 clean) |
39.6% mAP@50 · 22.8% mAP@50-95 · 56.7% Precision |
Best Epoch 47/67 (dataset_builder, ViT-H-14-378 dfn5b, 1604 train / 420 val) |
Sample Val (30 imgs) |
66.1% mAP@50 · 80.0% FP32 (16/20) · 86.7% INT8 (13/15) |
data/sample_yolo/images/val · 100% (14/14) FP32–INT8 bin agreement |
| PC Throughput (Steady-State) |
PyTorch CPU: 6.64 ms (150.5 FPS) · GPU: 3.27 ms (306.0 FPS) INT8 1T: 2.73 ms (365.7 FPS) · 4T: 2.00 ms (500.3 FPS) |
Intel Core i5-14600KF (ai-edge-litert XNNPACK) & NVIDIA RTX 5060 Ti (192×192, 20-iter warmup) |
| ESP32-S3 HIL Latency |
Pending HIL (out_ms, arena_used_bytes) |
Serial benchmark instrumented in main.cpp for ViSEF 2027 |
Visual Detection Showcase
Real detections on visually verified, CLIP (ViT-H-14-378) curated agricultural produce and leaf disease samples with 3-bin chute routing (45° Unripe, 90° Ripe, 135° Diseased):
Both the embedded baseline (models/yolov8n_agri_192_int8.tflite) and the CLIP-curated GPU training run (dataset_builder/) currently rely on single-contour Otsu auto-bounding boxes. Upgrading auto-labeling to zero-shot box detection and capturing on-device ESP32-S3 HIL timing (out_ms) are active milestones for ViSEF 2027.
Quick Start
# 1. Install package & run offline evaluation / simulation on included sample data
pip install -e .
python -m agrisort eval-tflite --model models/yolov8n_agri_192_int8.tflite --images data/sample_yolo/images/val
python -m agrisort simulate --weights models/yolov8n_agri_192.pt
# 2. Optional: run CLIP ViT-H-14-378 dataset curation pipeline (dataset_builder/)
python -u dataset_builder/pipeline.py
# 3. Build & flash ESP32-S3 firmware (PlatformIO)
cd firmware && pio run --target upload && pio device monitor
Full CLI stages (collect → clean → label → train → export → header) and wiring diagrams:
评论