Skip to content

OSError: cannot write mode F as PNG #12

Description

@abdulkarimatrash

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.

Activity

  1. bianwenjing commented on Jun 5, 2023

    @bianwenjing
    Collaborator

    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 1a0f0bc. Thanks to the code from @yangjiheng in commit 5102e2a.

  2. abdulkarimatrash commented on Jun 6, 2023

    @abdulkarimatrash
    Author

    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.

  3. bianwenjing commented on Jun 9, 2023

    @bianwenjing
    Collaborator

    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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions