Unified Python interface for Meta SAM 3D Body and SAM 3D Objects
Project description
sam3d
sam3d 提供 SAM 3D Body 和 SAM 3D Objects 的统一 Python 接口,目标是下载好模型后可直接调用。
1. 准备模型文件
SAM 3D Body
示例路径约定:
sam-3d-body/checkpoints/sam-3d-body-dinov3/model.ckptsam-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 /healthGET /infoPOST /predict/bodyPOST /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>
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
sam3d-0.1.2.tar.gz
(238.7 kB
view details)
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
sam3d-0.1.2-py3-none-any.whl
(312.4 kB
view details)
File details
Details for the file sam3d-0.1.2.tar.gz.
File metadata
- Download URL: sam3d-0.1.2.tar.gz
- Upload date:
- Size: 238.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.7.16
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8a6a2fdac64b324ee6f6da49bd72c05329a151084b27d27033332672d3a97139
|
|
| MD5 |
f230042fef4d7a5d5a4393696dfb110f
|
|
| BLAKE2b-256 |
dd86c977567869968a5b4a876aee7bf384b696be16591aee9ab2657af82d168d
|
File details
Details for the file sam3d-0.1.2-py3-none-any.whl.
File metadata
- Download URL: sam3d-0.1.2-py3-none-any.whl
- Upload date:
- Size: 312.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.7.16
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8bca2ddfc0946a03ad462c313aa2697c4257e4261983f0ea18375269a4dc081c
|
|
| MD5 |
37fe9840fa2bec9c8cb537d46c1c941a
|
|
| BLAKE2b-256 |
0bfc1abfd3252eebb235241c5bec5120030fce6078fab518e1b42fc49ddb063e
|