Skip to main content

sam3d

sam3d 提供 SAM 3D Body 和 SAM 3D Objects 的统一 Python 接口,目标是下载好模型后可直接调用。

1. 准备模型文件

SAM 3D Body

示例路径约定:

  • sam-3d-body/checkpoints/sam-3d-body-dinov3/model.ckpt
  • sam-3d-body/checkpoints/sam-3d-body-dinov3/assets/mhr_model.pt

SAM 3D Objects

示例路径约定:

  • sam-3d-objects/checkpoints/hf/pipeline.yaml

你也可以传入自定义绝对路径(SAM3DConfig)。

2. 安装

cd /Users/sun/Projects/embody/sam3d
pip install -e .

3. 使用

import numpy as np
from sam3d import SAM3D

sam3d = SAM3D.from_defaults(
    workspace_dir="/Users/sun/Projects/embody/sam3d",
    device="cuda",
)

# 4.1 人体重建
body_result = sam3d.predict(
    task="body",
    image="/path/to/person.jpg",
)
print(len(body_result["instances"]))

# 4.2 物体重建
mask = np.zeros((1024, 1024), dtype=bool)  # 你的物体 mask
obj_result = sam3d.predict(
    task="objects",
    image="/path/to/object.png",
    mask=mask,
    seed=42,
)
obj_result["gaussian_splat"].save_ply("object.ply")

4. 接口设计说明

  • 统一入口:SAM3D.predict(task=...)
  • 任务拆分:predict_body(...) 和 predict_objects(...)
  • 懒加载:首次调用对应任务时才初始化模型,减少启动负担
  • 与官方实现兼容:底层直接复用 Meta 仓库里的推理入口

5. 第三方源码

当前包已 vendoring 下列源码(仅包含统一接口所需部分):

  • sam_3d_body(来自 facebookresearch/sam-3d-body)
  • sam3d_objects(来自 facebookresearch/sam-3d-objects)

6. HTTP API 服务模式

安装服务依赖:

pip install "sam3d[service]"

启动服务:

sam3d-http --workspace-dir ~/.spwm/models --device cuda --host 0.0.0.0 --port 8000

接口:

  • GET /health
  • GET /info
  • POST /predict/body
  • POST /predict/objects

7. 模型下载脚本(HF / ModelScope)

安装下载依赖:

pip install "sam3d[download]"

默认(body/objects 从 ModelScope,moge 从 HuggingFace):

sam3d-download --workspace-dir ~/.spwm/models

可分别指定来源:

sam3d-download \
  --workspace-dir ~/.spwm/models \
  --body-source modelscope \
  --objects-source modelscope \
  --moge-source huggingface

可覆盖模型 ID(例如全部走 HuggingFace):

sam3d-download \
  --workspace-dir ~/.spwm/models \
  --body-source huggingface \
  --objects-source huggingface \
  --body-model-id <hf-body-model-id> \
  --objects-model-id <hf-objects-model-id>

Metadata

Release files for sam3d 0.1.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for sam3d 0.1.2
File Size Uploaded Provenance Actions
sam3d-0.1.2.tar.gz 238.7 kB Without provenance Details for sam3d-0.1.2.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for sam3d 0.1.2
File Interpreter ABI Platform Actions
sam3d-0.1.2-py3-none-any.whl Python 3 none any Details for sam3d-0.1.2-py3-none-any.whl

Total release size: 551.2 kB

Release files / sam3d-0.1.2.tar.gz

Download URL sam3d-0.1.2.tar.gz
Size 238.7 kB
Tags Source
SHA-256 checksum
How to use checksums
8a6a2fdac64b324ee6f6da49bd72c05329a151084b27d27033332672d3a97139
BLAKE2b-256 checksum
How to use checksums
dd86c977567869968a5b4a876aee7bf384b696be16591aee9ab2657af82d168d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.7.16

Release files / sam3d-0.1.2-py3-none-any.whl

Download URL sam3d-0.1.2-py3-none-any.whl
Size 312.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
8bca2ddfc0946a03ad462c313aa2697c4257e4261983f0ea18375269a4dc081c
BLAKE2b-256 checksum
How to use checksums
0bfc1abfd3252eebb235241c5bec5120030fce6078fab518e1b42fc49ddb063e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.7.16

Security for sam3d 0.1.2

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page