a8nova's picture
nnopt port: YOLO11n-MLX
56fa795 verified
Raw History Blame Contribute Delete
1.72 kB
#!/bin/bash
# Install the YOLO11n MLX port into DEST (this Mac is the device): sources, fused weights, a private venv
# installed offline from build/wheels, run.sh and port.json.
set -euo pipefail
HERE="$(cd "$(dirname "$0")" && pwd)"
DEST="${1:?usage: deploy.sh DEST}"
BUILD="$HERE/build"
[ -f "$BUILD/yolo11n_fused.npz" ] || { echo "deploy.sh: run build.sh first" >&2; exit 1; }
mkdir -p "$DEST"
DEST="$(cd "$DEST" && pwd)"
rm -rf "$DEST/app" "$DEST/venv"
mkdir -p "$DEST/app"
cp "$HERE/src/run.py" "$HERE/src/yolo_mlx.py" "$HERE/src/kernels.py" "$DEST/app/"
cp "$BUILD/yolo11n_fused.npz" "$DEST/app/"
if [ -f "$BUILD/libspin.dylib" ]; then cp "$BUILD/libspin.dylib" "$DEST/app/"; fi
# Same interpreter as the build venv; --copies so the venv survives the kit copying DEST elsewhere.
BASE_PY="$("$BUILD/venv/bin/python" -c 'import sys; print(sys._base_executable)')"
"$BASE_PY" -m venv --copies "$DEST/venv"
"$DEST/venv/bin/python" -m pip install -q --disable-pip-version-check --no-index --find-links "$BUILD/wheels" \
mlx==0.32.4 mlx-metal==0.32.4 numpy==2.5.4 opencv-python-headless==5.0.0.93
cat > "$DEST/run.sh" <<'EOF'
# YOLO11n detection on MLX (Apple GPU). Usage: sh ./run.sh --image IN.jpg [--repeat R] --out OUT.json --metrics M.json
HERE="$(cd "$(dirname "$0")" && pwd)"
export PYTHONNOUSERSITE=1
unset PYTHONPATH PYTHONHOME
exec "$HERE/venv/bin/python" -s "$HERE/app/run.py" --weights "$HERE/app/yolo11n_fused.npz" "$@"
EOF
cat > "$DEST/port.json" <<EOF
{"contract": 1, "model_type": "vision_detection", "runtime": "MLX $("$DEST/venv/bin/python" -c 'import mlx.core as mx; print(mx.__version__)') (Metal GPU)", "precision": "fp16", "external_files": []}
EOF
echo "deploy.sh: installed into $DEST"