本教程使用的環(huán)境及版本
- 操作系統(tǒng):Ubuntu 18.04.5(無(wú)GUI)
- GPU:RTX 3090
- cuda:11.3
- cmake:3.24
- GCC:7.5
- G++:7.5
- python:3.9
- OptiX:7.5
- COLMAP
Instant-ngp linux環(huán)境部署
參考地址:http://www.reibang.com/p/02c3d3cce99b
Instant-ngp官方文檔地址
https://github.com/NVlabs/instant-ngp/blob/master/docs/nerf_dataset_tips.md
目的
- linux 完成自有數(shù)據(jù)集訓(xùn)練及模型導(dǎo)出
問(wèn)題說(shuō)明
- 非GUI環(huán)境下,執(zhí)行以下命令后,訓(xùn)練不會(huì)停止薛耻,需要手動(dòng)取消坚洽。
./build/testbed --no-gui --scene data/nerf/fox
- 非GUI環(huán)境下愕乎,繼續(xù)后續(xù)步驟斗这。生成 obj 或 ply 格式文件導(dǎo)出事扭,用于后續(xù)使用
自有圖片數(shù)據(jù)集訓(xùn)練思路
- 拿到圖片斤寇,跑colmap先做稀疏重建桶癣,拿到相機(jī)信息和一些圖片的位姿信息,得到一個(gè)transform.json文件
- 使用transform.json進(jìn)行訓(xùn)練
安裝python運(yùn)行環(huán)境
- 使用cond安裝虛擬環(huán)境娘锁,并安裝相關(guān)依賴
conda create -n ngp python=3.9
conda activate ngp
pip install -r requirements.txt
COLMAP稀疏重建生成transform.json
- 1.創(chuàng)建自己的數(shù)據(jù)集文件夾:toy_truck
- 2.把拍攝好的圖片放入數(shù)據(jù)集文件夾中
- 3.上傳自己的數(shù)據(jù)集到 instant-ngp/data/ 目錄下
目錄結(jié)構(gòu)如下:
??instant-ngp/ # this is root
├── ??data/
│ ├── ??toy_truck/
│ │ ├── ??toy_truck_001.jpg
│ │ ├── ??toy_truck_002.jpg
│ │ │...
│ │...
│...
- 4.在instant-ngp目錄中執(zhí)行以下命令生成transform.json
# --images <image/path> 替換為自己的數(shù)據(jù)集目錄
python scripts/colmap2nerf.py --colmap_matcher exhaustive --run_colmap --aabb_scale 16 --images data/toy_truck
- 5.以上命令執(zhí)行完成后會(huì)在instant-ngp目錄中生成transform.json文件
- 6.將transform.json 和 數(shù)據(jù)集 toy_truck 文件夾按照以下目錄結(jié)構(gòu)存放
??instant-ngp/ # this is root
├── ??data/
│ ├── ??toy_truck/
│ │ ├── ??transforms.json/
│ │ ├── ??data/
│ │ │ ├── ??toy_truck/
│ │ │ │ ├── ??toy_truck_001.jpg
│ │ │ │ ├── ??toy_truck_002.jpg
│ │ │ │ │...
│ │ │ │...
│ │ │...
│ │...
│...
導(dǎo)出模型文件(obj牙寞、ply)
- 1.在 instant-ngp 目錄下創(chuàng)建用于保存導(dǎo)出文件的目錄 saved
mkdir saved
- 2.執(zhí)行以下命令,生成導(dǎo)出文件
python ./scripts/run.py --mode nerf --scene ./data/toy_truck --save_snapshot saved/toy_truck.msgpack --save_mesh saved/toy_truck.ply --gui --train
腳本 scripts/run.py 中有一個(gè) save_mesh 參數(shù)莫秆,它支持 OBJ 和 PLY 格式间雀。
注意:非GUI模式需要?jiǎng)h除 --gui 參數(shù)
- 3.執(zhí)行成功后會(huì)在 saved 目錄中生成 toy_truck.msgpack 和 toy_truck.ply
toy_truck.msgpack 文件可用戶導(dǎo)出圖片和視頻
導(dǎo)出圖片
–scene 場(chǎng)景的路徑
–mode 模式,選nerf即可
–load_snapshot 保存的訓(xùn)練好的模型
–screenshot_transforms 需要渲染的角度镊屎,數(shù)據(jù)結(jié)構(gòu)和nerf的json格式一樣
–screenshot_frames 渲染哪一幀惹挟,如果想全部渲染就不要這個(gè)參數(shù),會(huì)默認(rèn)渲染全部
–screenshot_dir 渲染好的圖片存儲(chǔ)的位置
–width 圖片寬度
–height 圖片高度
python scripts/run.py --scene data/toy_truck/ --mode nerf --load_snapshot saved/toy_truck.msgpack --screenshot_transforms data/toy_truck/transforms.json --screenshot_dir data/toy_truck/screenshot --width 2048 --height 2048 --n_steps 0
導(dǎo)出視頻
- 下載rendervideo.py到項(xiàng)目scripts目錄
鏈接: https://pan.baidu.com/s/1uxw5GL5TpU-FuHcH0RCYEg 密碼: opfl
python scripts/rendervideo.py --scene data/toy_truck/ --n_seconds 10 --fps 60 --render_name toy_truck_video --width 1920 --height 1080 --msgpack_path /root/code/instant-ngp/saved/toy_truck.msgpack --transform_path /root/code/instant-ngp/data/toy_truck/transforms.json
視頻數(shù)據(jù)集訓(xùn)練方式(一)
- 安裝ffmpeg(數(shù)據(jù)集為視頻時(shí)需要安裝)
sudo apt update
sudo apt install ffmpeg
- 測(cè)試ffmpeg
ffmpeg -version
- 使用ffmpeg將視頻處理為圖片
####安裝ffmpeg(數(shù)據(jù)集為視頻時(shí)需要安裝)
- 安裝ffmpeg
sudo apt update
sudo apt install ffmpeg
- 測(cè)試ffmpeg
生成清晰無(wú)壓縮的圖片方式:
ffmpeg -i test.mp4 -r 10 -f image2 %05d.jpg
-i : 指定輸入文件
-r : 幀數(shù) 10
-f : 指定格式化的格式為image2
image2后面跟著的是文件名
%5d:以為5位數(shù)按正序編號(hào)
視頻數(shù)據(jù)集訓(xùn)練方式(二)框架腳本
- 上傳視頻到data目錄
- 執(zhí)行以下腳本生成transform.json
python scripts/colmap2nerf.py --video_in data/model1/model1.MOV --video_fps 2 --run_colmap --aabb_scale 16
colmap2nerf.py實(shí)現(xiàn)的效果是自動(dòng)將視頻分割成圖片缝驳,然后調(diào)用colmap稀疏重建生成transform.json文件连锯,最后執(zhí)行即可
文獻(xiàn)參考
https://github.com/NVlabs/instant-ngp/blob/master/docs/nerf_dataset_tips.md
https://github.com/bycloudai/instant-ngp-Windows
https://github.com/NVlabs/instant-ngp/discussions/412
https://blog.csdn.net/YuhsiHu/article/details/124891710
https://asea.fun/articles/74