Files
james.maesandClaude Opus 4.7 0d46971563 Swap YOLOv3 (80 classes) for YOLOv8x-OIV7 (601 classes)
Replaces the bundled detector with Ultralytics' YOLOv8x trained on
Open Images V7 — 601 object classes including coffee cup, mug, wine
glass, mobile phone, computer monitor, sunglasses, laptop, plus body
parts (human face / hand / eye / arm / leg). Substantially better
"is that a coffee mug" detection than the 80-class COCO model.

Conversion
- Ultralytics' yolov8x-oiv7.pt → Core ML mlpackage via
  ultralytics.YOLO(...).export(format="coreml", nms=True). Output is a
  Vision-friendly pipeline (preprocessing + model + NMS), so
  VNCoreMLRequest continues to return [VNRecognizedObjectObservation]
  directly with no manual decoding.
- scripts/convert-yolo-oiv7.py is the conversion entry point.
- scripts/fetch-model.sh rewritten as a no-LFS fallback that
  bootstraps a Python venv, installs coremltools + ultralytics, runs
  the conversion, and drops the result into Sources/Resources/Models/.

Bundling
- yolov8x-oiv7.mlpackage is a directory (~131 MB weight.bin + small
  model.mlmodel descriptor + Manifest.json).
- .gitattributes adds LFS tracking for **/weight.bin and
  **/model.mlmodel inside Sources/Resources/Models so the contents go
  to LFS without the surrounding directory metadata pretending to be
  binary.
- Old YOLOv3.mlmodel removed from the repo (still in LFS history if
  needed).

Theme
- Theme.Performance.detectorModelName updated to "yolov8x-oiv7" (the
  detector falls back to mlpackage extension automatically via the
  existing Bundle.main.url lookup).

README + scripts updated to reflect the new model and 601-class
vocabulary.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-05-16 15:12:51 -05:00

58 lines
1.8 KiB
Bash
Executable File

#!/usr/bin/env bash
# Fallback for environments without Git LFS. Re-runs the YOLO conversion
# from Ultralytics' published Open Images V7 weights — produces a Core ML
# mlpackage with 601 object classes in Sources/Resources/Models/.
#
# Run once after cloning, if `git lfs pull` is unavailable or didn't fetch
# the model:
# ./scripts/fetch-model.sh
#
# Requirements:
# - python3.12 or python3.13 (3.14 isn't supported by coremltools yet)
# - ~3 GB free disk for the venv (PyTorch + ultralytics + coremltools)
# - ~250 MB network for the pretrained weights
set -euo pipefail
ROOT="$(cd "$(dirname "$0")/.." && pwd)"
MODELS_DIR="$ROOT/Sources/Resources/Models"
MODEL_NAME="yolov8x-oiv7"
DEST="$MODELS_DIR/$MODEL_NAME.mlpackage"
VENV="${VPOC_VENV:-/tmp/visionpoc-venv}"
mkdir -p "$MODELS_DIR"
if [[ -d "$DEST" ]] && [[ -f "$DEST/Data/com.apple.CoreML/weights/weight.bin" ]]; then
size=$(stat -f%z "$DEST/Data/com.apple.CoreML/weights/weight.bin")
if [[ "$size" -gt 10000000 ]]; then
echo "$MODEL_NAME.mlpackage already present and looks valid. Skipping rebuild."
exit 0
fi
fi
PY_BIN=""
for cand in python3.13 python3.12; do
if command -v "$cand" >/dev/null 2>&1; then
PY_BIN="$cand"
break
fi
done
if [[ -z "$PY_BIN" ]]; then
echo "Need python3.12 or python3.13. Install via: brew install python@3.13" >&2
exit 1
fi
if [[ ! -d "$VENV" ]]; then
echo "Creating Python venv at $VENV…"
"$PY_BIN" -m venv "$VENV"
fi
echo "Installing coremltools + ultralytics into $VENV (this takes a couple of minutes)…"
"$VENV/bin/pip" install --quiet --upgrade pip
"$VENV/bin/pip" install --quiet coremltools ultralytics
echo "Running conversion…"
"$VENV/bin/python" "$ROOT/scripts/convert-yolo-oiv7.py"
echo "Done. Set Theme.Performance.detectorModelName to \"$MODEL_NAME\" (default)."