ActiveVisionLab / nope-nerf

(CVPR 2023) NoPe-NeRF: Optimising Neural Radiance Field with No Pose Prior
https://nope-nerf.active.vision/
MIT License
372 stars 30 forks source link

OSError: cannot write mode F as PNG #12

Open random-guest opened 1 year ago

random-guest commented 1 year ago

Dear Respected Authors,

Let me congrats you first on the great work and thank you for sharing your code.

I am on Linux-based OS, Ubuntu 18.04, with a single GPU Card, RTX 3090.

I am trying to train your model by following the provided steps, but since you used Cudatoolkit 10.1, and my GPU needs sm_86, I installed Cuda 11.3 using:

pip install torch==1.12.1+cu113 torchvision==0.13.1+cu113 torchaudio==0.12.1 --extra-index-url https://download.pytorch.org/whl/cu113

and continue building the environment as listed in the environment. yaml

I started training and got the following error:

Loaded image data (540, 960, 3, 120) [540. 960. 593.97969292] test set: ['000745.jpg', '000753.jpg', '000761.jpg', '000769.jpg', '000777.jpg', '000785.jpg', '000793.jpg', '000801.jpg', '000809.jpg', '000817.jpg', '000825.jpg', '000833.jpg', '000841.jpg', '000849.jpg', '000857.jpg'] train : 105 views Loaded image data (540, 960, 3, 120) [540. 960. 593.97969292] test set: ['000745.jpg', '000753.jpg', '000761.jpg', '000769.jpg', '000777.jpg', '000785.jpg', '000793.jpg', '000801.jpg', '000809.jpg', '000817.jpg', '000825.jpg', '000833.jpg', '000841.jpg', '000849.jpg', '000857.jpg'] train : 105 views /home/desk/anaconda3/envs/nope-nerf/lib/python3.9/site-packages/torch/functional.py:478: 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:2894.) return _VF.meshgrid(tensors, **kwargs) # type: ignore[attr-defined] [Epoch 00] it=000, loss=1.05058718, time=1.0190 Traceback (most recent call last): File "/home/desk/anaconda3/envs/nope-nerf/lib/python3.9/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 "/home/desk/my_WorkingDirectory/NeRF-Based/nope-nerf/train.py", line 362, in train(cfg=cfg) File "/home/desk/my_WorkingDirectory/NeRF-Based/nope-nerf/train.py", line 234, in train val_rgb = trainer.render_visdata( File "/home/desk/my_WorkingDirectory/NeRF-Based/nope-nerf/model/training.py", line 136, in render_visdata imageio.imwrite(os.path.join(out_render_path,'%04d_depth.png'% img_idx), depth_pred_out) File "/home/desk/anaconda3/envs/nope-nerf/lib/python3.9/site-packages/imageio/v2.py", line 397, in imwrite return file.write(im, kwargs) File "/home/desk/anaconda3/envs/nope-nerf/lib/python3.9/site-packages/imageio/core/v3_plugin_api.py", line 367, in exit self.close() File "/home/desk/anaconda3/envs/nope-nerf/lib/python3.9/site-packages/imageio/plugins/pillow.py", line 123, in close self._flush_writer() File "/home/desk/anaconda3/envs/nope-nerf/lib/python3.9/site-packages/imageio/plugins/pillow.py", line 457, in _flush_writer primary_image.save(self._request.get_file(), self.save_args) File "/home/desk/anaconda3/envs/nope-nerf/lib/python3.9/site-packages/PIL/Image.py", line 2432, in save save_handler(self, fp, filename) File "/home/desk/anaconda3/envs/nope-nerf/lib/python3.9/site-packages/PIL/PngImagePlugin.py", line 1289, in _save raise OSError(msg) from e OSError: cannot write mode F as PNG

I am searching for this problem, trying to solve it, but I find myself stuck for a few days already, if you could guide me through this, I would be highly appreciated it.

thank you in advance for your time.

bianwenjing commented 1 year ago

Hi, thanks for your interest in the work. This is caused by the data type used for depth. I have updated the code in commit 1a0f0bc52a50292294d3dbd7a6df3511fb72dcb3. Thanks to the code from @yangjiheng in commit 5102e2aa8c4f65f9c10a0ada940e502cce6eca29.

random-guest commented 1 year ago

Excuse me again please,

Sadly, after I tried the updated code, I got the following error:

Loaded image data (540, 960, 3, 120) [540. 960. 593.97969292] test set: ['000745.jpg', '000753.jpg', '000761.jpg', '000769.jpg', '000777.jpg', '000785.jpg', '000793.jpg', '000801.jpg', '000809.jpg', '000817.jpg', '000825.jpg', '000833.jpg', '000841.jpg', '000849.jpg', '000857.jpg'] train : 105 views Loaded image data (540, 960, 3, 120) [540. 960. 593.97969292] test set: ['000745.jpg', '000753.jpg', '000761.jpg', '000769.jpg', '000777.jpg', '000785.jpg', '000793.jpg', '000801.jpg', '000809.jpg', '000817.jpg', '000825.jpg', '000833.jpg', '000841.jpg', '000849.jpg', '000857.jpg'] train : 105 views /home/desk/anaconda3/envs/nope-nerf/lib/python3.9/site-packages/torch/functional.py:478: 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:2894.) return _VF.meshgrid(tensors, **kwargs) # type: ignore[attr-defined] Traceback (most recent call last): File "/home/desk/my_WorkingDirectory/NeRF-Based/nope-nerf/train.py", line 362, in train(cfg=cfg) File "/home/desk/my_WorkingDirectory/NeRF-Based/nope-nerf/train.py", line 208, in train loss_dict = trainer.train_step(batch, it, epoch_it, scheduling_start, render_path) File "/home/desk/my_WorkingDirectory/NeRF-Based/nope-nerf/model/training.py", line 87, in train_step loss_dict = self.compute_loss(data, it=it, epoch=epoch, scheduling_start=scheduling_start, out_render_path=render_path) File "/home/desk/my_WorkingDirectory/NeRF-Based/nope-nerf/model/training.py", line 345, in compute_loss Image.fromarray( File "/home/desk/anaconda3/envs/nope-nerf/lib/python3.9/site-packages/PIL/Image.py", line 2432, in save save_handler(self, fp, filename) File "/home/desk/anaconda3/envs/nope-nerf/lib/python3.9/site-packages/PIL/PngImagePlugin.py", line 1233, in _save im = im.astype(np.unit8) File "/home/desk/anaconda3/envs/nope-nerf/lib/python3.9/site-packages/PIL/Image.py", line 528, in getattr raise AttributeError(name) AttributeError: astype

did you test the updated version of the code or does it have to do with the fact that I am using different PyTorch and cuda version?

thank you very much for your patience.

bianwenjing commented 1 year ago

Hi, I tested the updated code on my machine and it works. Sorry I am unable to figure out the exact cause of this bug. Just to provide more information, I have tested it with both pillow 9.0.0 and pillow 9.5.0. If you encounter the issue with the same pillow version, you may consider rewriting the image saving code using imageio as an alternative solution.