FloodDiffusion 是基于 Latent Diffusion Forcing 的**文本到动作(text-to-motion)**扩散模型(Wan2.5-based,humanml3d 动作空间)。给定动作描述文本,生成 3D 人体动作轨迹。
本仓库为 昇腾 NPU 迁移适配版(原模型 ShandaAI/FloodDiffusion,HuggingFace 镜像 id AlayaLab/FloodDiffusion):
npu:0(import torch_npu)。inference.py 双模式:命令行 + FastAPI。model_weights/AlayaLab-FloodDiffusion/,本地优先,缺失自动从 hf-mirror.com 下载。| 项 | 值 |
|---|---|
| 模型 | FloodDiffusion (text-to-motion, Wan2.5-based Diffusion-Forcing) |
| 输入 | 自然语言动作描述(如 "a person walks forward") |
| 输出 | 263 维 HumanML3D 动作特征 + 22×3 关节 3D 轨迹 |
| 编码器 | UMT5-XXL 文本编码器 (bf16, ~11GB) |
| 主干 | Transformer 扩散主干(8 层, dim 1024, 扩散步数 10) |
| 解码器 | 1D 卷积 VAE(latent 4 → 263) |
| 帧率 | 20 FPS(length×4 帧) |
torch torch_npu transformers safetensors diffusers lightning omegaconf ftfy regex fastapi uvicorn python-multipartpip install -i https://pypi.tuna.tsinghua.edu.cn/simple diffusers lightning omegaconf ftfy# 命令行单次推理 (默认文本 "a person walks forward")
python inference.py --text "a person walks forward"
# 指定动作与长度 (length=60 -> 约 240 帧)
python inference.py --text "a person running quickly" --length 60输出 JSON 结构:
{
"model": "ShandaAI/FloodDiffusion",
"text": "a person walks forward",
"format": "humanml3d_263",
"frames": 120,
"dim": 263,
"device": "npu:0",
"num_denoise_steps": 10,
"elapsed_sec": 3.2,
"motion_263": [...], // (frames, 263) HumanML3D 特征
"joints_22x3": [...], // (frames, 22, 3) 3D 关节轨迹
"joints_shape": [120, 22, 3]
}uvicorn inference:app --host 0.0.0.0 --port 8000测试:
curl -s -X POST http://127.0.0.1:8000/predict \
-H 'Content-Type: application/json' \
-d '{"text": "a person walks forward"}'请求字段:{"text": "...", "length": 60, "num_denoise_steps": 10, "output_joints": true},返回动作生成 JSON。
model_weights/AlayaLab-FloodDiffusion/(相对工程根目录,已通过 .gitignore 排除,不提交大权重)。inference.py 会自动从 https://hf-mirror.com/AlayaLab/FloodDiffusion 快照下载(约 12GB,含 UMT5-XXL 编码器)。.cuda() / torch.cuda.* / device='cuda' 调用;新增 torch_npu 初始化与设备校验(失败打印明确原因)。torch.amp.autocast("cuda", ...) → "npu"。scaled_dot_product_attention。cat)。