Ready-to-use Core ML conversions of Ultralytics YOLOv8 for object detection on Apple Silicon. The n, s, and m variants are provided as .mlpackage models for use with the CPU, GPU, and Apple Neural Engine.
These models are used by
Hugging Mac, an open-source platform for building and experiencing local AI apps, services, games, plugins, and agents on macOS.
1from pathlib import Path
2
3import coremltools as ct
4from huggingface_hub import snapshot_download
5from PIL import Image, ImageOps
6
7root = Path(snapshot_download(
8 repo_id="hugging-mac/yolov8-coreml",
9 allow_patterns=["yolov8n.mlpackage/**"],
10))
11
12model = ct.models.MLModel(
13 root / "yolov8n.mlpackage",
14 compute_units=ct.ComputeUnit.ALL,
15)
16
17image = Image.open("image.jpg").convert("RGB")
18image = ImageOps.pad(image, (640, 640), color=(114, 114, 114))
19predictions = model.predict({"image": image})["predictions"]
20
21print(predictions.shape) # (1, 84, 8400)
For a complete preprocessing, decoding, and NMS implementation, see the
Hugging Mac YOLOv8 SDK.
The converted models retain the upstream
Ultralytics YOLOv8 licensing terms. They are published under AGPL-3.0. Review Ultralytics licensing requirements before commercial or closed-source use.
Hugging Mac is an independent open-source project and is not affiliated with or endorsed by Ultralytics.