dunbar12138 / DSNeRF

Code release for DS-NeRF (Depth-supervised Neural Radiance Fields)
https://www.cs.cmu.edu/~dsnerf/
MIT License
746 stars 126 forks source link

OSError: cannot write mode F as PNG #107

Open NickWWWW1 opened 6 months ago

NickWWWW1 commented 6 months ago

Hi all,

I am trying to run python run_nerf.py --config configs/leaves_2v.txt --render_only --chunk=16384 --netchunk=32768 with the pre-trained model. However, I receive the following logs:

python run_nerf.py --config configs/leaves_2v.txt --render_only --chunk=16384 --netchunk=32768 Loaded colmap llff (6, 756, 1008, 3) (120, 3, 5) [ 756. 1008. 863.3505] ./data/split_allview_npy/leaves_2view DEFINING BOUNDS NEAR FAR 1.2630987882614135 15.368377685546875 Found ckpts ['./logs/release/leaves_2v/50000.tar'] Reloading from ./logs/release/leaves_2v/50000.tar Not ndc! RENDER ONLY test poses shape torch.Size([120, 3, 5]) 0%| | 0/120 [00:00<?, ?it/s]0 0.0007996559143066406 /home/won147/miniconda3/envs/dsnerf/lib/python3.8/site-packages/torch/functional.py:507: 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:3549.) return _VF.meshgrid(tensors, **kwargs) # type: ignore[attr-defined] torch.Size([756, 1008, 3]) torch.Size([756, 1008]) max: 15.368378 0%| | 0/120 [01:51<?, ?it/s] Traceback (most recent call last): File "/home/won147/miniconda3/envs/dsnerf/lib/python3.8/site-packages/PIL/PngImagePlugin.py", line 1279, 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/won147/miniconda3/envs/dsnerf/lib/python3.8/site-packages/imageio/v2.py", line 397, in imwrite return file.write(im, kwargs) File "/home/won147/miniconda3/envs/dsnerf/lib/python3.8/site-packages/imageio/core/v3_plugin_api.py", line 367, in exit self.close() File "/home/won147/miniconda3/envs/dsnerf/lib/python3.8/site-packages/imageio/plugins/pillow.py", line 144, in close self._flush_writer() File "/home/won147/miniconda3/envs/dsnerf/lib/python3.8/site-packages/imageio/plugins/pillow.py", line 485, in _flush_writer primary_image.save(self._request.get_file(), self.save_args) File "/home/won147/miniconda3/envs/dsnerf/lib/python3.8/site-packages/PIL/Image.py", line 2439, in save save_handler(self, fp, filename) File "/home/won147/miniconda3/envs/dsnerf/lib/python3.8/site-packages/PIL/PngImagePlugin.py", line 1282, in _save raise OSError(msg) from e OSError: cannot write mode F as PNG

I am using python 3.8, any suggestions are appreciated!

19991105 commented 5 months ago

I'm having the same issue, maybe changing the 186 lines of the run_nerf.py to depth=depth.cpu().numpy().astype(np.uint8)would solve the problem

dunbar12138 commented 5 months ago

Hi, I think this is due to the mismatch of data types which happens in newer versions of PIL, and the answer above solves the problem.