1.配置conda环境
下载conda和环境配置请看我的文章。
2.安装Nerfstudio依赖项
- 创建环境
记得以后所有操作都要cd工作文件夹!!!conda create --name nerfstudio -y python=3.8 conda activate nerfstudio python -m pip install --upgrade pip
- Torch 2.1.2 与 CUDA 11.8 (推荐)
pip install torch==2.1.2+cu118 torchvision==0.16.2+cu118 --extra-index-url https://download.pytorch.org/whl/cu118
-
检测Torch的GPU是否识别
import torch print(torch.__version__) print(torch.cuda.is_available())
-
cuda-toolkit
还需要构建必要的 CUDA 扩展。我们建议使用 conda 安装:conda install -c "nvidia/label/cuda-11.8.0" cuda-toolkit
-
小cuda-nn
在 pytorch 和 ninja 之后,安装 tiny-cuda-nn 的 torch 绑定:
pip install ninja git+https://github.com/NVlabs/tiny-cuda-nn/#subdirectory=bindings/torch
-
安装 nerfstudio
pip install nerfstudio
3.安装指令-NeRF2NeRF
pip install git+https://github.com/ayaanzhaque/instruct-nerf2nerf
4.下载官方的数据
放到你的工作文件夹
5.训练bear的NeRF数据集
ns-train nerfacto --data 你的路径/bear/bear
![](https://i-blog.csdnimg.cn/blog_migrate/fbf54dd0dc8f2ebc2cc724b71b6ca1c7.png)
可以通过http://0.0.0.0:7007来查看训练的过程
等到训练完成100%,按ctrl+c结束
6.开始编辑 NeRF 的训练
我的GPU没有那么强,只有12G显存所以用in2n-small
ns-train in2n-small --data 你的路径/bear/bear --load-dir 你的路径/outputs\bear\nerfacto\2024-05-07_111446(替换为你的文件名)\nerfstudio_models --pipeline.prompt "Turn the bear into a polar bear" --pipeline.guidance-scale 7.5 --pipeline.image-guidance-scale 1.5
如果GPU很强还是用in2n比较好
报错,具体信息是连不上huggingface,导致下载不了instruct-pix2pix
我只能在huggingface里一个一个下载到本地,所以点个赞好吗
夸克网盘:https://pan.quark.cn/s/7aed62394df2
然后在这两个文件里改读取路径
C:\Users\cxk520\.conda\envs\nerfstudio\Lib\site-packages\diffusers\schedulers\scheduling_utils.py
C:\Users\cxk520\.conda\envs\nerfstudio\Lib\site-packages\diffusers\pipelines\pipeline_utils.py
scheduling_utils.py,26行修改路径改为本地的路径
pipeline_utils.py,665行修改为本地路径
报错解决
重新训练,训练开始是很慢的要等很久才有能看到过程,开始是30000步起,所以训练到36000步已经很厉害了。
训练好了可以用ns-viewer的指令调出三维编程场景
ns-viewer --load-config outputs/bear/nerfacto/2023-12-17_230904/config.yml
点击render
点击camera type换成Fisheye
然后按照自己的意愿添加摄像头
就像这样
点击生成指令
下完之后在renders/bear/2024-05-09-15-43-51.mp4可以有视频可看
Instruct-NeRF2NeRF视频