This guide covers end-to-end environment setup for the current architecture in this repository.
The setup below does not rely on VIGA at runtime.
Scope:
- Includes
SAM+SAM3D - Excludes
SAM3andinfinigen
Runtime architecture:
- Process 1: public API (
sam3d_server.main_service, port8004) - Process 2: internal SAM service (
sam3d_server.sam_service, port9001) - Process 3: internal SAM3D service (
sam3d_server.sam3d_service, port9002)
- Linux + NVIDIA GPU (SAM3D requires high VRAM).
- NVIDIA driver available (
nvidia-smishould work). gitwith submodule support.conda(Miniconda/Anaconda) for local run.curlavailable in shell.- Optional but recommended: Docker + NVIDIA Container Toolkit.
Check GPU:
nvidia-smiFrom project root (/Users/fishwowater/projects/SAM3DServer):
git submodule update --init --recursive third_party/sam third_party/sam3dCreate two environments:
conda create -n sam python=3.10 -y
conda create -n sam3d-objects python=3.11 -yInstall dependencies:
conda run -n sam --no-capture-output \
pip install -r requirements/requirement_sam.txt
conda run -n sam3d-objects --no-capture-output \
pip install -r requirements/requirement_sam3d-objects.txt
conda run -n sam3d-objects --no-capture-output \
pip install 'huggingface-hub[cli]<1.0'For SAM3D-specific pinned CUDA/PyTorch and third-party build dependencies (without model download), use:
bash scripts/setup_sam3d_env.shSet token for SAM3D checkpoint download (first run only):
export HF_TOKEN="<your_huggingface_token>"Notes:
- SAM checkpoint is public and downloaded automatically.
- SAM3D checkpoint is from Hugging Face model
facebook/sam-3d-objects. - If SAM3D checkpoints already exist locally,
HF_TOKENis not required.
Default model location for local run:
<repo>/models
You can override:
export MODEL_ROOT="/your/custom/models/path"From repo root:
bash scripts/start_sam_http.sh startWhat this script does:
- Ensures model files exist (
scripts/ensure_models.sh). - Starts internal SAM service on
127.0.0.1:9001. - Starts internal SAM3D service on
127.0.0.1:9002. - Starts public API on
0.0.0.0:8004.
Port environment variables (optional, defaults shown):
export SAM_INTERNAL_PORT=9001
export SAM3D_INTERNAL_PORT=9002
export SAM_HTTP_PORT=8004Service management commands:
bash scripts/start_sam_http.sh status
bash scripts/start_sam_http.sh stop
bash scripts/start_sam_http.sh restartOptional startup timeout tuning:
export HEALTH_WAIT_SECONDS=600
bash scripts/start_sam_http.sh startIn another terminal:
curl -s http://127.0.0.1:8004/healthz | python -m json.toolExpected key fields:
sam_service: truesam3d_service: truestatus: "ok"(or"degraded"if one internal service is unavailable)
Put two test images under assets/:
assets/image1.jpgassets/image2.jpg
Run examples:
python examples/client_segment_image.py
python examples/client_reconstruct_scene.pyArtifacts are downloaded to:
output/<job_id>/
Recommended:
export HF_TOKEN="<your_huggingface_token>"
bash scripts/docker_compose_up.sh upEquivalent raw compose commands:
docker compose -f docker-compose.yml pull
docker compose -f docker-compose.yml up -dNotes:
- Default image is
fishwowater/sam3dserver:latest. - Compose exposes ports
9001/9002/8004(SAM/SAM3D/public API). - Models persist in compose volume
sam_models.
Health check after startup:
curl -s http://127.0.0.1:8004/healthz | python -m json.toolHF_TOKEN is not set
- Cause: SAM3D checkpoint missing and token not provided.
- Fix:
export HF_TOKEN=...and restart.
SAM checkpoint not found
- Cause: model download failed or path mismatch.
- Fix: check
MODEL_ROOTandSAM_CHECKPOINT, rerun startup script.
SAM3D config not found
- Cause: SAM3D checkpoints missing or wrong
SAM3D_CONFIG_PATH. - Fix: confirm
<MODEL_ROOT>/sam3d/checkpoints/hf/pipeline.yamlexists.
/healthzreturnsdegraded
- Cause: internal SAM or SAM3D service failed to load.
- Fix: inspect startup logs for
9001/9002loading errors.
- OOM during reconstruction
- Cause: insufficient VRAM for SAM3D model/inference.
- Fix: reduce concurrent external traffic (queue is serial), use larger GPU, or lower workload size.
Main variables used by this project:
HF_TOKEN: Hugging Face token for SAM3D checkpoint download.MODEL_ROOT: root directory for model files.SAM_CHECKPOINT: SAM checkpoint path.SAM3D_CONFIG_PATH: SAM3D pipeline config path.SAM_INTERNAL_PORT: startup script SAM service port (default9001).SAM3D_INTERNAL_PORT: startup script SAM3D service port (default9002).SAM_HTTP_PORT: startup script public API port (default8004).SAM_INTERNAL_BASE_URL: internal SAM service URL (defaulthttp://127.0.0.1:9001).SAM3D_INTERNAL_BASE_URL: internal SAM3D service URL (defaulthttp://127.0.0.1:9002).SAM_HTTP_BASE_URL: public API base URL (defaulthttp://127.0.0.1:8004).SAM_HTTP_JOB_ROOT: job output directory (default/var/lib/sam-http/jobs).SAM_HTTP_JOB_TTL_HOURS: job artifact retention time.HEALTH_WAIT_SECONDS: internal service startup wait time instart_sam_http.sh.