DSNeRF复现流程

文章讲述了在创建虚拟环境并安装依赖后,作者遇到关于配置文件缺失、深度图格式问题和FFMPEG警告的解决过程,包括修改代码、处理警告以及最终成功渲染和训练的过程。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

创建虚拟环境安装依赖

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

全部错误已解决(1、2、两个错误)

在这里插入图片描述

现在开始渲染视频(Testing)

在这里插入图片描述

在这里插入图片描述

已经渲染好了现在有个警告

Done rendering ./logs/release/flower_2v/renderonly_path_050000
IMAGEIO FFMPEG_WRITER WARNING: input image is not divisible by macro_block_size=16, resizing from (1008, 756) to (1008, 768) to ensure video compatibility with most codecs and players. To prevent resizing, make your input image divisible by the macro_block_size or set the macro_block_size to 1 (risking incompatibility).
Depth stats 0.3445094 0.8333333 0.6793633699417114
IMAGEIO FFMPEG_WRITER WARNING: input image is not divisible by macro_block_size=16, resizing from (1008, 756) to (1008, 768) to ensure video compatibility with most codecs and players. To prevent resizing, make your input image divisible by the macro_block_size or set the macro_block_size to 1 (risking incompatibility).
在这里插入图片描述
实际上这不是报错,而是IMAGEIO库的FFMPEG_WRITER发出的警告。它指出正在尝试将一系列图像编码为视频,但输入图像的尺寸(1008x756)不是宏块大小(macro_block_size)的整数倍,这里宏块大小默认是16。为了保证视频与大多数编解码器和播放器的兼容性,IMAGEIO将自动调整图像大小至(1008, 768)。

chat了一下这个警告的大概影响

在这里插入图片描述

当前忽略这个警告查看一下渲染出来的结果

在这里插入图片描述

有两个视频一个是disp.mp4一个是rgb.mp4

在这里插入图片描述
disp.mp4在这里插入图片描述在这里插入图片描述

rgb.mp4
在这里插入图片描述

现在开始训练数据集(Training)

python run_nerf.py --config configs/flower_2v.txt

在这里插入图片描述

一下子就完了给我整蒙了,./data/split_allview_npy/flower_2view,进去目录发现应该是数据集里的数据少所以运行得快

在这里插入图片描述

总结

            print('Depth stats', np.mean(disps), np.max(disps), np.percentile(disps, 95))
            Depth stats 0.3445094 0.8333333 0.6793633699417114

在这里插入图片描述

复现结束了(目前没什么问题),但是感觉哪里有问题,有点太顺利了,有时间在看看

评论 18
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值