创建虚拟环境安装依赖
conda create -n DSNeRF python=3.7
pip install -r requirements.txt``
下载LLFF数据放在创建的data文件下
https://drive.google.com/file/d/1RjhfcbsywOvw0ts1AFSri91mKANvEVOa/view?usp=sharing
下载预先训练好的模型
bash download_models.sh
渲染视频
python run_nerf.py --config configs/fern_dsnerf.txt --render_only
报错显示没有这个文件
run_nerf.py: error: Unable to open config file: configs/fern_dsnerf.txt. Error: No such file or directory
## 修改文件为python run_nerf.py --config configs/fern_2v.txt --render_only
又报错
FileNotFoundError: [Errno 2] No such file or directory: ‘data/split_allview_npy/fern_2view/train_images.npy’
此时将文件名split_allview_new改为split_allview_npy
继续渲染
python run_nerf.py --config configs/fern_2v.txt --render_only
又报错
Loaded colmap llff (5, 756, 1008, 3) (120, 3, 5) [ 756. 1008.
829.89215] ./data/split_allview_npy/fern_2view DEFINING BOUNDS NEAR FAR 1.200000035762787 5.672883987426758 Found ckpts
[‘./logs/release/fern_2v/50000.tar’] Reloading from
./logs/release/fern_2v/50000.tar Not ndc! RENDER ONLY test poses shape
torch.Size([120, 3, 5]) 0%|
| 0/120 [00:00<?, ?it/s]0 0.0010442733764648438
/home/uriky/anaconda3/envs/DSNeRF/lib/python3.7/site-packages/torch/functional.py:504:
UserWarning: torch.meshgrid: in an upcoming release, it will be
required to pass the indexing argument. (Triggered internally at
…/aten/src/ATen/native/TensorShape.cpp:3190.) return
_VF.meshgrid(tensors, **kwargs) # type: ignore[attr-defined] torch.Size([756, 1008, 3]) torch.Size([756, 1008]) max: 5.531892 0%|
| 0/120 [00:48<?, ?it/s] Traceback (most recent call last): File
“/home/uriky/anaconda3/envs/DSNeRF/lib/python3.7/site-packages/PIL/PngImagePlugin.py”,
line 1286, in _save
rawmode, mode = _OUTMODES[mode] KeyError: ‘F’The above exception was the direct cause of the following exception:
Traceback (most recent call last): File “run_nerf.py”, line 1134, in
train() File “run_nerf.py”, line 795, in train
rgbs, disps = render_path(render_poses, hwf, args.chunk, render_kwargs_test, gt_imgs=images, savedir=testsavedir,
render_factor=args.render_factor) File “run_nerf.py”, line 191, in
render_path
imageio.imwrite(os.path.join(savedir, ‘{:03d}_depth.png’.format(i)), depth) File
“/home/uriky/anaconda3/envs/DSNeRF/lib/python3.7/site-packages/imageio/v2.py”,
line 397, in imwrite
return file.write(im, **kwargs) File “/home/uriky/anaconda3/envs/DSNeRF/lib/python3.7/site-packages/imageio/core/v3_plugin_api.py”,
line 367, in exit
self.close() File “/home/uriky/anaconda3/envs/DSNeRF/lib/python3.7/site-packages/imageio/plugins/pillow.py”,
line 123, in close
self._flush_writer() File “/home/uriky/anaconda3/envs/DSNeRF/lib/python3.7/site-packages/imageio/plugins/pillow.py”,
line 457, in _flush_writer
primary_image.save(self._request.get_file(), **self.save_args) File
“/home/uriky/anaconda3/envs/DSNeRF/lib/python3.7/site-packages/PIL/Image.py”,
line 2432, in save
save_handler(self, fp, filename) File “/home/uriky/anaconda3/envs/DSNeRF/lib/python3.7/site-packages/PIL/PngImagePlugin.py”,
line 1289, in _save
raise OSError(msg) from e OSError: cannot write mode F as PNG
Begin接下来一步步解决报错的问题:
1、这个警告表示在未来的PyTorch版本中,调用torch.meshgrid函数时,将需要显式地传递一个indexing参数。indexing参数用来指定网格输出的索引方式,可以是’ij’或’xy’。'ij’表示矩阵索引,而’xy’表示笛卡尔索引。当前,这个参数是可选的,但警告建议应该显式地传递这个参数以避免未来的不兼容问题。
/home/uriky/anaconda3/envs/DSNeRF/lib/python3.7/site-packages/torch/functional.py:504: UserWarning: torch.meshgrid: in an upcoming release, it will be required to pass the indexing argument. (Triggered internally at …/aten/src/ATen/native/TensorShape.cpp:3190.)
return _VF.meshgrid(tensors, **kwargs) # type: ignore[attr-defined]
如图修改成这样子
return _VF.meshgrid(tensors, **kwargs, indexing=‘ij’)
2、现在不会再又警告,但是出现KeyError:F
很奇怪图像模式都没看见F,不知道从哪里冒出来的KeyError:F和cannot write mode F as PNG这个报错
这个KeyError:F,搜了一下原因:代码中可能没有看到直接设置图像模式为 ‘F’ 的地方,但是有可能 depth 变量是一个浮点类型的数组,而当尝试使用 imageio.imwrite 保存它时,imageio 或其底层的库(如 PIL/Pillow)可能试图将其解释为某种图像模式,并默认选择了 ‘F’。
要解决这个问题的话,需要确保 depth 变量在保存为 PNG 之前被转换为合适的图像模式。(通常,深度图会以灰度图像的形式保存,其模式为 ‘L’,并且像素值范围在 0 到 255 之间。如果 depth 数组是浮点数类型,并且范围不在这个区间内,需要先将其转换为合适的整数范围。)
插入一个冷知识:
深度图(Depth Map):是一种灰度图像,其中每个像素点代表传感器距离物体的实际距离。它是计算机视觉中常用的一种图像表示方式,用于描述场景的三维结构。在深度图中,像素的灰度值表示物体距离相机的远近,灰度值越大,表示物体距离相机越远;反之,灰度值越小,表示物体距离相机越近。
找了半天没见这个depth然后打开github,https://github.com/dunbar12138/DSNeRF/issues/107,这个佬说改一下这一行代码(我的救星呜呜呜)
把depth = depth.cpu().numpy()
改成depth = depth.cpu().numpy().astype(np.uint8)
插入冷知识:
.astype(np.uint8)是NumPy数组的一个方法,用于更改数组的数据类型。np.uint8是无符号8位整数类型,常用于表示图像的像素值(范围从0到255)。如果depth的原始数据类型不是np.uint8,这个操作会将其转换为np.uint8