Object Detection (YOLOv8 / YOLOv11)
Build on-device object detection with YOLOv8/YOLOv11 using ZETIC Melange.
Build a real-time on-device object detection application using YOLOv8 or YOLOv11 with ZETIC Melange. This tutorial walks you through exporting the model, deploying it to Melange, and running inference on Android and iOS.
We provide the source code for the YOLOv11 demo application for both Android and iOS. If the input model key is changed to YOLOv8, you can experience YOLOv8 as well.
What You Will Build
An on-device object detection application that identifies and localizes objects in real-time camera frames using YOLOv8 or YOLOv11 models accelerated by NPU hardware.
Prerequisites
- A ZETIC Melange account with a Personal Key (sign up at melange.zetic.ai)
- Python 3.8+ with
ultralytics,opencv-python, andnumpyinstalled - Android Studio or Xcode for mobile deployment
What is YOLOv11?
YOLOv11 is the latest version of the acclaimed real-time object detection and image segmentation model by Ultralytics.
- Official documentation: YOLOv11 Docs
- Currently, only detector mode is supported. Additional features will be supported later.
Step 1: Export the Model
We prepared a model key for you: Steve/YOLOv11_comparison. You can skip to Step 3 if you want to use our pre-configured model.
Export the YOLOv11 model to ONNX format. You will get yolo11n.onnx after running this script:
from ultralytics import YOLO
import torch
model = YOLO("yolo11n.pt")
model.export(format="onnx", opset=12, simplify=True, dynamic=False, imgsz=640)Step 2: Prepare Input Sample
Prepare your input from an image file:
import cv2
import numpy as np
def preprocess_image(image_path, target_size=(640, 640)):
img = cv2.imread(image_path)
img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
img = cv2.resize(img, target_size)
img = img.astype(np.float32) / 255.0
img = np.transpose(img, (2, 0, 1))
img = np.expand_dims(img, axis=0)
return imgStep 3: Generate Melange Model
Upload the model and inputs via the Melange Dashboard or use the CLI:
zetic gen -p $PROJECT_NAME -i images.npy yolo11n.onnxStep 4: Implement ZeticMLangeModel
Initialize the Melange model in your mobile application and run inference.
For detailed application setup, please follow the Android Integration Guide guide.
// (1) Load model
val model = ZeticMLangeModel(this, PERSONAL_KEY, MODEL_NAME)
// (2) Prepare model inputs
val inputs: Array<Tensor> = // Prepare your inputs
// (3) Run and get output tensors of the model
val outputs = model.run(inputs)For detailed application setup, please follow the iOS Integration Guide guide.
// (1) Load model
let model = try ZeticMLangeModel(personalKey: PERSONAL_KEY, name: MODEL_NAME, version: VERSION)
// (2) Prepare model inputs
let inputs: [Tensor] = [] // Prepare your inputs
// (3) Run and get output tensors of the model
let outputs = try model.run(inputs)Step 5: Use the YOLOv8 Pipeline
We provide a YOLOv8 feature extractor as an Android and iOS module. This feature extractor works with both YOLOv8 and YOLOv11 models.
We are using the Melange extension module here.
val model = ZeticMLangeModelWrapper(this, PERSONAL_KEY, MODEL_NAME)
val pipeline = ZeticMLangePipeline(
feature = YOLOv8(this, model = model),
inputSource = CameraSource(this, preview.holder, preferredSize),
)
pipeline.loop { result ->
// visualize YOLO result here
}import ZeticMLange
import ext
let model = try ZeticMLangeModelWrapper(PERSONAL_KEY, MODEL_NAME)
let pipeline = ZeticMLangePipeline(feature: model, inputSource: CameraSource())
pipeline.startLoop()
while true {
let frame = pipeline.latestResult
// visualize YOLO result here
}
pipeline.stopLoop()Conclusion
With ZETIC Melange, you can build on-device AI object detection applications with NPU acceleration in minutes. We continuously upload models to our examples and HuggingFace page.
Please stay tuned and contact us for collaborations!