Download validate/gpu_validate.sh from eoinedge/sam3edge-mini: direct link, hf CLI and curl.
- Browser
- Download file 2.84 kB
-
https://huggingface.co/eoinedge/sam3edge-mini/resolve/main/validate/gpu_validate.sh
- Command line
-
hf download hf://eoinedge/sam3edge-mini/validate/gpu_validate.sh
-
curl -L -o gpu_validate.sh https://huggingface.co/eoinedge/sam3edge-mini/resolve/main/validate/gpu_validate.sh
2.84 kB
| # Check sam3edge-mini (and, optionally, sam3edge-micro and another publisher's SAM 3) on this machine. | |
| # | |
| # bash gpu_validate.sh cuda an NVIDIA GPU (Ubuntu, driver 525 or newer) | |
| # bash gpu_validate.sh cpu the CPU only | |
| # | |
| # Anything after the first word is passed to validate.py, for example: | |
| # bash gpu_validate.sh cuda --micro fast-672,quality-336 --other tepirale/sam3-ONNX | |
| # | |
| # It makes a Python environment in ~/sam3edge-validate, installs ONNX Runtime with the CUDA libraries it | |
| # needs (no system CUDA install is used or changed), downloads the public files and writes the results to | |
| # ~/sam3edge-validate/kit/results/. Nothing outside that folder is touched. | |
| set -euo pipefail | |
| PROVIDER="${1:-cuda}" | |
| shift || true | |
| DIR="${SAM3EDGE_DIR:-$HOME/sam3edge-validate}" | |
| case "$PROVIDER" in cpu|cuda) ;; *) echo "first argument must be cuda or cpu"; exit 2 ;; esac | |
| command -v python3 >/dev/null || { echo "python3 is missing: sudo apt install python3 python3-venv"; exit 1; } | |
| MINOR=$(python3 -c 'import sys; print(sys.version_info.minor)') | |
| MAJOR=$(python3 -c 'import sys; print(sys.version_info.major)') | |
| if [ "$MAJOR" -ne 3 ] || [ "$MINOR" -lt 10 ]; then | |
| echo "Python 3.10 or newer is needed; this is $(python3 --version)"; exit 1 | |
| fi | |
| if [ "$PROVIDER" = "cuda" ]; then | |
| command -v nvidia-smi >/dev/null || { echo "nvidia-smi is missing: install the NVIDIA driver first"; exit 1; } | |
| nvidia-smi --query-gpu=name,driver_version,memory.total --format=csv,noheader | |
| DRIVER=$(nvidia-smi --query-gpu=driver_version --format=csv,noheader | head -1 | cut -d. -f1) | |
| if [ "$DRIVER" -lt 525 ]; then | |
| echo "NVIDIA driver $DRIVER is older than 525, which the CUDA 12 libraries need. Update the driver."; exit 1 | |
| fi | |
| # ONNX Runtime builds that use CUDA 12 (any driver from 525 on): 1.23 still supports Python 3.10 | |
| if [ "$MINOR" -ge 11 ]; then ORT='onnxruntime-gpu[cuda,cudnn]==1.26.0'; else ORT='onnxruntime-gpu[cuda,cudnn]==1.23.2'; fi | |
| else | |
| ORT='onnxruntime' | |
| fi | |
| mkdir -p "$DIR" | |
| if [ ! -x "$DIR/venv/bin/python" ]; then | |
| python3 -m venv "$DIR/venv" || { echo "could not make a virtual environment: sudo apt install python3-venv"; exit 1; } | |
| fi | |
| PY="$DIR/venv/bin/python" | |
| "$PY" -m pip install --quiet --upgrade pip | |
| "$PY" -m pip install --quiet "$ORT" numpy pillow huggingface_hub tokenizers | |
| "$PY" - "$DIR/kit" <<'PYCODE' | |
| import sys | |
| from huggingface_hub import snapshot_download | |
| snapshot_download("eoinedge/sam3edge-mini", allow_patterns=["sam3edge_mini/*", "validate/*"], local_dir=sys.argv[1]) | |
| PYCODE | |
| if [ "$PROVIDER" = "cuda" ]; then | |
| "$PY" - <<'PYCODE' | |
| import onnxruntime as ort | |
| if hasattr(ort, "preload_dlls"): | |
| ort.preload_dlls() | |
| print("onnxruntime", ort.__version__, "providers:", ort.get_available_providers()) | |
| PYCODE | |
| fi | |
| exec "$PY" "$DIR/kit/validate/validate.py" --provider "$PROVIDER" "$@" | |