Developer Jason Hee has published a technical breakdown of 'fruitlens,' a client-side machine learning application that detects and classifies fruit using WebGPU. The project, hosted at fruitlens.app, serves as a practical case study in fine-tuning YOLO for detection and MobileNet for classification, with a heavy emphasis on local inference privacy. By keeping all processing on the device, the app avoids sending image data to external servers, a significant advantage for privacy-conscious users.
The Two-Stage Pipeline Architecture
Heeβs architecture splits the vision task into two distinct models to optimize for both speed and accuracy. The first stage uses a YOLO-based detector to identify the presence of fruit in a video frame, ignoring identity. If a fruit is detected, a second stage invokes a MobileNet classifier to determine the specific type. This separation allows the system to handle real-time video feeds at approximately 10 frames per second for detection, while the UI drawing loop runs at 60 fps. The detector was fine-tuned on a mixed corpus of labeled public photos, crowded group shots, and negative examples like balls and hands to reduce false positives.
Quantization and Augmentation Gotchas
The most instructive part of the write-up concerns model optimization and data handling. Hee discovered that uniform fp16 quantization degraded performance significantly when applied to all layers. The solution was to leave the initial stem layer and the final head layer in higher precision, as these are sensitive to rounding errors, while quantizing the intermediate layers. Furthermore, standard data augmentation techniques proved dangerous for fruit recognition. Because color is a primary feature for distinguishing items like green versus red apples, aggressive color jittering during training taught the model incorrect classifications. Careful tuning of augmentation parameters was required to maintain classification accuracy.
Benchmarking Against a Manual Evaluation Set
Rather than relying on massive automated benchmarks, Hee constructed a manual evaluation set of 20 real-world photos with precise bounding box annotations. This small dataset allowed for qualitative analysis of mistakes, such as missed detections or misclassifications. The detector achieved a mean Average Precision (mAP) of 0.33, a recall of 65%, and a precision of 74%, with 2.4 false positives per image. The classifier reached 81% accuracy and an F1 score of 0.74. These metrics, while modest compared to state-of-the-art server-side models, are competitive for a lightweight, client-side implementation running on consumer hardware.
Key Takeaways
- Layer-specific quantization is critical for maintaining accuracy in edge-deployed models.
- Color augmentation must be restricted when color is a primary class identifier.
- A small, manually annotated evaluation set enables effective qualitative debugging.
- Client-side WebGPU inference offers viable privacy-preserving alternatives to cloud APIs.
The Bottom Line
This project is a refreshing reminder that ML engineering is as much about avoiding pitfalls like over-augmentation and bad quantization as it is about picking the right architecture. For developers building edge-AI apps, Heeβs lessons on layer sensitivity and data nuance are worth more than another benchmark leaderboard.