Skip to content

Commit c5ceab7

Browse files
committed
feat(depth-estimation): add deploy.sh for platform-aware install
macOS: installs coremltools + common deps only (fast ~10s), auto-downloads DepthAnythingV2SmallF16.mlpackage from HF. Other: full PyTorch stack via requirements.txt.
1 parent debf56b commit c5ceab7

File tree

1 file changed

+91
-0
lines changed
  • skills/transformation/depth-estimation

1 file changed

+91
-0
lines changed
Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
#!/bin/bash
2+
# deploy.sh — Platform-aware dependency install for Depth Estimation
3+
#
4+
# macOS: CoreML only (fast ~10s install, Neural Engine inference)
5+
# Other: Full PyTorch stack (torch + torchvision + depth-anything-v2)
6+
#
7+
# The Aegis deployment agent calls this instead of raw pip install.
8+
9+
set -e
10+
11+
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
12+
VENV_DIR="$SCRIPT_DIR/.venv"
13+
MODELS_DIR="$HOME/.aegis-ai/models/feature-extraction"
14+
COREML_VARIANT="DepthAnythingV2SmallF16"
15+
COREML_HF_REPO="apple/coreml-depth-anything-v2-small"
16+
17+
echo "=== Depth Estimation (Privacy) — Setup ==="
18+
echo "Platform: $(uname -s) / $(uname -m)"
19+
20+
# ── Create venv ──────────────────────────────────────────────────────
21+
if [ ! -d "$VENV_DIR" ]; then
22+
echo "Creating virtual environment..."
23+
python3 -m venv "$VENV_DIR"
24+
fi
25+
26+
PIP="$VENV_DIR/bin/pip"
27+
PYTHON="$VENV_DIR/bin/python"
28+
29+
# Upgrade pip
30+
"$PIP" install --upgrade pip --quiet
31+
32+
# ── Platform detection ───────────────────────────────────────────────
33+
if [ "$(uname -s)" = "Darwin" ]; then
34+
echo ""
35+
echo "=== macOS detected — CoreML backend (Neural Engine) ==="
36+
echo "Installing CoreML dependencies only (fast)..."
37+
"$PIP" install --quiet \
38+
"coremltools>=8.0" \
39+
"huggingface_hub>=0.20.0" \
40+
"numpy>=1.24.0" \
41+
"opencv-python-headless>=4.8.0" \
42+
"Pillow>=10.0.0" \
43+
"matplotlib>=3.7.0"
44+
45+
echo "✅ CoreML dependencies installed"
46+
47+
# ── Download CoreML model if not present ─────────────────────────
48+
MODEL_PATH="$MODELS_DIR/$COREML_VARIANT.mlpackage"
49+
if [ -d "$MODEL_PATH" ]; then
50+
echo "✅ CoreML model already present: $MODEL_PATH"
51+
else
52+
echo "Downloading CoreML model: $COREML_VARIANT from $COREML_HF_REPO..."
53+
mkdir -p "$MODELS_DIR"
54+
"$PYTHON" -c "
55+
from huggingface_hub import snapshot_download
56+
snapshot_download(
57+
'$COREML_HF_REPO',
58+
local_dir='$MODELS_DIR',
59+
allow_patterns=['$COREML_VARIANT.mlpackage/**'],
60+
)
61+
print('✅ CoreML model downloaded')
62+
"
63+
fi
64+
65+
# Verify
66+
"$PYTHON" -c "
67+
import coremltools, cv2, numpy, PIL
68+
from pathlib import Path
69+
model_path = Path('$MODEL_PATH')
70+
assert model_path.exists(), f'Model not found: {model_path}'
71+
print(f'✅ Verified: coremltools={coremltools.__version__}, model={model_path.name}')
72+
"
73+
74+
else
75+
echo ""
76+
echo "=== Non-macOS — PyTorch backend ==="
77+
echo "Installing full PyTorch dependencies..."
78+
"$PIP" install --quiet -r "$SCRIPT_DIR/requirements.txt"
79+
80+
echo "✅ PyTorch dependencies installed"
81+
82+
# Verify
83+
"$PYTHON" -c "
84+
import torch, cv2, numpy, PIL
85+
from depth_anything_v2.dpt import DepthAnythingV2
86+
print(f'✅ Verified: torch={torch.__version__}, CUDA={torch.cuda.is_available()}')
87+
"
88+
fi
89+
90+
echo ""
91+
echo "=== Setup complete ==="

0 commit comments

Comments
 (0)