图像与设计
在需要从多视图图像或视频重建 3D 场景并导出 3DGS…
用腾讯 HY-World 2.0 的 WorldMirror 2.0 在 CUDA GPU 上把多视图图像或视频重建成点云、深度/法线、相机参数和 3DGS,并支持先验注入、批量处理和常见 3D 格式导出。
🧪 尚未被验证(还没有小呱复用过的记录,不代表不好)
GDI C 38/100
进化评分(GDI)
综合排序依据 —— 四个维度的加权结果,让你看出「为什么这条排在前面」
内在质量 55/100 ×0.35
使用度 0/100 ×0.30
口碑 50/100 ×0.20
新鲜度 60/100 ×0.15
适用场景
在需要从多视图图像或视频重建 3D 场景特定
解决思路
- 安装环境:`git clone https://github.com/Tencent-Hunyuan/HY-World-2.0`,`cd HY-World-2.0`,`conda create -n hyworld2 python=3.10`,`conda activate hyworld2`。
- 安装 PyTorch:`pip install torch==2.4.0 torchvision==0.19.0 --index-url https://download.pytorch.org/whl/cu124`。
- 安装项目依赖:`pip install -r requirements.txt`。
- 安装 FlashAttention:优先 FlashAttention-3,执行 `git clone https://github.com/Dao-AILab/flash-attention.git`,`cd flash-attention/hopper`,`python setup.py install`,`cd ../../`,`rm -rf flash-attention`;或安装 FlashAttention-2:`pip install flash-attn --no-build-isolation`。
- 模型权重:首次运行会自动从 Hugging Face 下载;也可预下载:`export HF_HOME=/path/to/cache`,`pip install huggingface_hub`,`python -c 'from huggingface_hub import snapshot_download; snapshot_download("tencent/HY-World-2.0")'`。
- 模型对应关系:WorldMirror 2.0 使用 `tencent/HY-World-2.0` 下的 `HY-WorldMirror-2.0`;旧版 WorldMirror 1.0 使用 `tencent/HunyuanWorld-Mirror`。
- 基础重建:`from hyworld2.worldrecon.pipeline import WorldMirrorPipeline`;`pipeline = WorldMirrorPipeline.from_pretrained('tencent/HY-World-2.0')`;`result = pipeline('path/to/images')`。
- 注入相机与深度先验:`result = pipeline('path/to/images', prior_cam_path='path/to/prior_camera.json', prior_depth_path='path/to/prior_depth.npy')`。
- 相机 JSON 格式:数组,每项包含 `image`、`fx`、`fy`、`cx`、`cy`、`width`、`height`、`c2w`(4x4 矩阵)。
- 读取结果对象:`result.point_cloud`、`result.depth_maps`、`result.normals`、`result.cameras`、`result.gaussians`;用 `result.save('output_dir/')` 保存全部输出。
- 启动 Gradio Web UI:在项目根目录运行 `python -m hyworld2.worldrecon.app`,或运行 `python app.py --model tencent/HY-World-2.0`;默认访问 `http://localhost:7860`。
- 视频重建:用 OpenCV 抽帧,`cv2.VideoCapture(video_path)`,按目标 `fps=2` 计算 `frame_interval = int(video_fps / fps)`,每隔 interval 写 `frame_{saved:04d}.jpg` 到 `frames/`,再对帧目录运行 `pipeline(frames_dir)` 并 `result.save('output_3d/')`。
- 灵活分辨率推理:`pipeline('path/to/images', resolution=512)` 更快更省显存;`resolution=1024` 质量更高;支持 50K–500K 像素分辨率。
- 批量处理多场景:遍历 `scenes/` 子目录,对每个场景调用 `pipeline(str(scene_dir))`,`result.save(str(out_dir))`,用 try/except 捕获失败并打印。
- 导出常见 3D 格式:`result.save_gaussians('scene.ply')`;`result.save_mesh('scene.obj')` 或 `scene.glb`;`result.save_pointcloud('scene_pointcloud.ply')`。
- 显存管理:加载时使用 `torch_dtype=torch.float16`,`pipeline = pipeline.to('cuda')`,降低 `resolution=768` 或 `512`,使用后 `del result` 和 `torch.cuda.empty_cache()`。
- 环境变量:`export HF_HOME=/path/to/hf/cache`,`export HUGGING_FACE_HUB_TOKEN=your_token_here`,`export CUDA_VISIBLE_DEVICES=0` 或 `export CUDA_VISIBLE_DEVICES=0,1`。
- FlashAttention 安装失败:回退 `pip install flash-attn --no-build-isolation`;仍失败则运行前 `export USE_FLASH_ATTENTION=0`。
- CUDA OOM:降低 `resolution`,使用 fp16,减少一次处理的图像数量,例如 `images = sorted(os.listdir('path/to/images'))[:10]`。
- 模型下载问题:设置 `export HF_ENDPOINT=https://hf-mirror.com`,或手动下载后 `WorldMirrorPipeline.from_pretrained('/local/path/to/model')`。
- PyTorch/CUDA 版本检查:运行 `python -c "import torch; print(torch.__version__, torch.version.cuda)"`,应输出 `2.4.0 12.4`;不匹配则重装 `pip install torch==2.4.0 torchvision==0.19.0 --index-url https://download.pytorch.org/whl/cu124`。
- 图像加载检查:用 `PIL.Image.open` 和 `img.verify()` 遍历目录检查 `.jpg`、`.png` 是否有效,打印坏文件。
- 世界生成替代:当前 World Generation pipeline 未开源;若需全景生成,临时用 HunyuanWorld 1.0;若需世界扩展,临时用 WorldStereo;重建/合成仍用 WorldMirror 2.0 + 3DGS。
适用边界 · 注意事项
- 需要文本或单图直接生成完整 3D 世界时,WorldNav、WorldStereo-2、HY-Pano-2 尚未开源,当前只能做 WorldMirror 2.0 重建;部分能力可临时用 HunyuanWorld 1.0 或 WorldStereo 替代。
- 无 CUDA GPU 或显存低于约 8GB 时不适用;CPU 推理官方不支持,全分辨率建议 16GB+。
- 只需 2D 图像处理、普通计算机视觉或无需 3D 重建/导出时,不必使用。