3D 场景补全扩散模型 businesslion/scaffdiff 的昇腾 Ascend NPU 推理适配。
vae_v3/best_point_vae.pth).to('npu:0'),推理在 torch.no_grad() 下进行,加载后 model.eval()。init_npu() 以 try-except 捕获 torch_npu import 失败或 npu:0 不可用的异常,打印清晰中文错误并优雅退出。./model_weights/businesslion__scaffdiff/,启动优先加载本地缓存,命中则跳过下载;未命中才经 hf-mirror.com 下载。--scene(而非模板中的 --img,本模型不是图像模型)。原完整 teacher 扩散管线为「冻结的 Sonata / Point Transformer V3 编码器(108M 参数)+ 8.9M 参数量去噪器」,
依赖 facebook/sonata、spconv 等重型包,且原训练代码不随 HF 权重发布(仅在 GitHub sonata_ws 仓库中,依赖 GPU 专有生态)。
本仓库按官方 README 与上游 sonata_ws 源码,忠实还原并跑通其可独立运行的组件: multi-token Gaussian VAE(SMC 2026 论文《CloudDiffusion》核心模型)。
vae_v3/best_point_vae.pth(85MB,7,107,523 参数)严格加载成功(missing=0 / unexpected=0)。pip install -r requirements.txt -i https://mirrors.aliyun.com/pypi/simple/铁律:严禁重装/升级/降级
torch、torch-npu、numpy、transformers。已实测torch 2.9.0+cpu+torch_npu 2.9.0.post1+transformers 4.57.6环境正常。
# 使用已有点云 (支持 .npy/.json/.txt/.xyz/.pts, 形状 (N,3))
python3 inference.py --scene sample_scene.npy
# 不传输入: 自动生成合成 scene (模拟含地面/墙体/立柱的局部场景)
python3 inference.py
# 采样重建 (默认使用 mu 确定性重建, 更稳定)
python3 inference.py --scene scene.json --sample输出推理 JSON 包含:device(npu:0)、input_points、output_points(8000)、latent_tokens(32)、latent_dim(1024)、
归一化参数、recon_bbox、recon_mean、完整 recon_points(8000×3) 与 latency_sec。
[env] torch 2.9.0+cpu, torch_npu 已加载
[env] NPU device_count=2, is_available=True
[env] device_name=Ascend910_9362
[env] 使用设备: npu:0
[input] 加载 scene: sample_scene.npy (4000 点)
[result] {
"model": "businesslion/scaffdiff",
"component": "multi_token_gaussian_vae",
"device": "npu:0",
"task": "3d_scene_completion",
"input_points": 4000,
"output_points": 8000,
"latent_tokens": 32,
"token_dim": 32,
"latent_dim": 1024,
...
"recon_bbox": [[-7.03, -6.41, -0.14], [6.08, 6.47, 3.06]],
"latency_sec": 0.12
}uvicorn inference:app --host 0.0.0.0 --port 8003GET / 服务信息POST /predict — JSON body:{"scene": [[x,y,z], ...], "use_mean": true},返回推理 JSON(含 8000 点重建)。POST /predict/upload — multipart 上传 .npy / .json / .txt 点云文件,返回推理 JSON。curl -s -X POST http://127.0.0.1:8003/predict \
-H "Content-Type: application/json" \
-d '{"scene": [[0.5,0.5,0.0],[0.6,0.5,0.0],[0.5,0.6,0.0],[-0.5,-0.5,0.0],[-0.6,-0.5,1.0],[0.0,0.0,2.0]]}'{
"model": "businesslion/scaffdiff",
"device": "npu:0",
"task": "3d_scene_completion",
"input_points": 6,
"output_points": 8000,
"latent_tokens": 32,
"latent_dim": 1024,
"recon_bbox": [[-0.239, -0.384, 0.167], [0.462, 0.469, 0.337]],
"recon_mean": [0.168, 0.159, 0.228],
"recon_points": [[0.296, 0.210, 0.181], ...],
"latency_sec": 0.15
}| 文件 | 大小 | 说明 |
|---|---|---|
model_weights/businesslion__scaffdiff/vae_v3/best_point_vae.pth | 85MB | multi-token Gaussian VAE 权重(7.1M 参数) |
下载源为 hf-mirror.com(huggingface.co 在本环境直连不可达)。启动时若本地缓存存在则直接加载。
scaffdiff-npu/
├── inference.py # 双模式推理 (CLI + FastAPI)
├── requirements.txt # Python 依赖
├── README.md
├── .gitignore # 忽略 model_weights/ logs/ __pycache__/
├── sample_scene.npy # 示例点云 (可选)
├── logs/ # 真实运行日志
└── assets/ # 终端截图